Browse Source

Initial commit

Vincent Spiewak 12 years ago
commit
138cce7b62

+ 234 - 0
pom.xml

@@ -0,0 +1,234 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" 
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+	                         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+   <modelVersion>4.0.0</modelVersion>
+
+   <!-- Maven Metadatas -->
+   <groupId>com.github.vspiewak</groupId>
+   <artifactId>log-generator</artifactId>
+   <version>0.0.1-SNAPSHOT</version>
+   <packaging>jar</packaging>
+
+   <!-- Project Metadatas -->
+   <name>log-generator</name>
+   <description>
+      A simple log generator
+   </description>
+   <url>http://github.com/vspiewak/log-generator</url>
+
+   <inceptionYear>2013</inceptionYear>
+
+   <organization>
+      <name>Vincent Spiewak</name>
+      <url>http://www.github.com/vspiewak</url>
+   </organization>
+
+   <!-- Project Properties -->
+   <properties>
+
+      <java.main.class>com.github.vspiewak.loggenerator.App</java.main.class>
+
+      <!-- UTF-8 Encoding for all -->
+      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+
+      <!-- Dependencies versions -->
+      <slf4j.version>1.7.5</slf4j.version>
+      <logback.version>1.0.13</logback.version>
+      
+      <maven.versions>[2.2.1, 3.1.0)</maven.versions>
+      <java.version>1.6</java.version>
+      <maven.shade.plugin>2.1</maven.shade.plugin>
+      <maven.jar.plugin>2.4</maven.jar.plugin>
+
+   </properties>
+
+   <!-- Team Metadatas -->
+   <developers>
+
+      <!-- A Developer - You can skip some fields... -->
+      <developer>
+         <id>vspiewak</id>
+         <name>Vincent Spiewak</name>
+         <email>vspiewak+github@gmail.com</email>
+         <roles>
+            <role>Admin</role>
+            <role>Developer</role>
+         </roles>
+         <organization>http://github.com/vspiewak</organization>
+      </developer>
+
+   </developers>
+
+   <dependencies>
+
+      <dependency>
+         <groupId>org.slf4j</groupId>
+         <artifactId>slf4j-api</artifactId>
+         <version>${slf4j.version}</version>
+         <scope>compile</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>ch.qos.logback</groupId>
+         <artifactId>logback-classic</artifactId>
+         <version>${logback.version}</version>
+         <scope>runtime</scope>
+      </dependency>
+
+      <!-- Junit -->
+      <dependency>
+         <groupId>junit</groupId>
+         <artifactId>junit</artifactId>
+         <version>4.10</version>
+         <scope>test</scope>
+      </dependency>
+
+   </dependencies>
+
+
+   <build>
+
+      <!-- Build plugins -->
+      <plugins>
+
+         <!-- Maven Compiler -->
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-compiler-plugin</artifactId>
+            <version>2.3.2</version>
+            <configuration>
+
+               <!-- Ensures we are compiling at java.version level -->
+               <source>${java.version}</source>
+               <target>${java.version}</target>
+
+               <!-- Show Warnings & Deprecations -->
+               <showWarnings>true</showWarnings>
+               <showDeprecation>true</showDeprecation>
+
+            </configuration>
+         </plugin>
+
+         <!-- Maven Jar -->
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-jar-plugin</artifactId>
+            <version>${maven.jar.plugin}</version>
+            <configuration>
+               <archive>
+                  <!-- Add manifest Main-Class entry -->
+                  <manifest>
+                     <mainClass>${java.main.class}</mainClass>
+                  </manifest>
+               </archive>
+            </configuration>
+         </plugin>
+
+         <!-- Maven Shade -->
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-shade-plugin</artifactId>
+            <version>${maven.shade.plugin}</version>
+            <configuration>
+               <minimizeJar>true</minimizeJar>
+            </configuration>
+            <executions>
+               <execution>
+                  <phase>package</phase>
+                  <goals>
+                     <goal>shade</goal>
+                  </goals>
+               </execution>
+            </executions>
+         </plugin>
+
+         <!-- Maven Enforcer -->
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-enforcer-plugin</artifactId>
+            <version>1.0</version>
+            <executions>
+               <execution>
+                  <id>enforce</id>
+                  <goals>
+                     <goal>enforce</goal>
+                  </goals>
+                  <configuration>
+
+                     <!-- Fail the build if a check fail -->
+                     <fail>true</fail>
+
+                     <!-- Stop on the first check fail -->
+                     <failFast>true</failFast>
+
+                     <!-- Rules: -->
+                     <rules>
+
+                        <!-- Check Maven version -->
+                        <requireMavenVersion>
+                           <version>${maven.versions}</version>
+                        </requireMavenVersion>
+
+                        <!-- Check Java version -->
+                        <requireJavaVersion>
+                           <version>${java.version}</version>
+                        </requireJavaVersion>
+
+                        <!-- No snapshots Dependencies -->
+                        <requireReleaseDeps>
+                           <message>snapshots dependency found</message>
+                        </requireReleaseDeps>
+
+                        <!-- Only one version per dependency -->
+                        <dependencyConvergence />
+
+                        <!-- No Repositories in pom.xml -->
+                        <requireNoRepositories>
+                           <message><![CDATA[<repositories>...</repositories> defined in pom.xml]]></message>
+                        </requireNoRepositories>
+
+                     </rules>
+                  </configuration>
+               </execution>
+            </executions>
+         </plugin>
+
+      </plugins>
+
+      <!-- m2e (Maven integration for Eclipse) requires the following configuration -->
+      <!-- this avoid m2e warning about enforce goal -->
+      <pluginManagement>
+         <plugins>
+            <plugin>
+               <groupId>org.eclipse.m2e</groupId>
+               <artifactId>lifecycle-mapping</artifactId>
+               <version>1.0.0</version>
+               <configuration>
+                  <lifecycleMappingMetadata>
+                     <pluginExecutions>
+                        <pluginExecution>
+                           <pluginExecutionFilter>
+                              <groupId>org.apache.maven.plugins</groupId>
+                              <artifactId>maven-enforcer-plugin</artifactId>
+                              <versionRange>[1.0.0,)</versionRange>
+                              <goals>
+                                 <goal>enforce</goal>
+                              </goals>
+                           </pluginExecutionFilter>
+                           <action>
+                              <ignore />
+                           </action>
+                        </pluginExecution>
+                     </pluginExecutions>
+                  </lifecycleMappingMetadata>
+               </configuration>
+            </plugin>
+         </plugins>
+      </pluginManagement>
+
+   </build>
+
+</project>

+ 36 - 0
src/main/java/com/github/vspiewak/loggenerator/App.java

@@ -0,0 +1,36 @@
+package com.github.vspiewak.loggenerator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public class App {
+
+    private static final Logger log = LoggerFactory.getLogger(App.class);
+    private static AtomicLong counter = new AtomicLong(0);
+
+    public static final long NB_LOGS = 10;
+
+    public static void main(String... args) {
+
+        log.debug("starting");
+
+        LogExecutor executor = new LogExecutor(5);
+
+        while (counter.get() < NB_LOGS) {
+            long number = counter.incrementAndGet();
+            SellTask task1 = new SellTask(number);
+            SearchTask task2 = new SearchTask(number);
+
+            executor.add(task1)
+                    .add(task2);
+        }
+
+        executor.execute();
+
+        log.debug("shutdown");
+
+    }
+
+}

+ 37 - 0
src/main/java/com/github/vspiewak/loggenerator/LogExecutor.java

@@ -0,0 +1,37 @@
+package com.github.vspiewak.loggenerator;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class LogExecutor {
+
+    public static final int DEFAULT_NB_THREADS = 4;
+    private final int nbThreads;
+    private ExecutorService executor;
+
+    public LogExecutor() {
+        this(DEFAULT_NB_THREADS);
+    }
+
+    public LogExecutor(int nbThreads) {
+        this.nbThreads = nbThreads;
+        executor = Executors.newFixedThreadPool(this.nbThreads);
+    }
+
+    public LogExecutor add(Callable<Long> task) {
+        executor.submit(task);
+        return this;
+    }
+
+    public void execute() {
+
+        // This will make the executor accept no new threads
+        // and finish all existing threads in the queue
+        executor.shutdown();
+        // Wait until all threads are finish
+        while (!executor.isTerminated()) {
+        }
+
+    }
+}

+ 23 - 0
src/main/java/com/github/vspiewak/loggenerator/SearchTask.java

@@ -0,0 +1,23 @@
+package com.github.vspiewak.loggenerator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.Callable;
+
+public class SearchTask implements Callable<Long> {
+
+    private static final Logger log = LoggerFactory.getLogger(SearchTask.class);
+    private final long id;
+
+        public SearchTask(final long id) {
+            this.id = id;
+        }
+
+        @Override
+        public Long call() throws Exception {
+            log.info("{} - {}", id, Utils.getRandomIP());
+            return id;
+        }
+
+}

+ 23 - 0
src/main/java/com/github/vspiewak/loggenerator/SellTask.java

@@ -0,0 +1,23 @@
+package com.github.vspiewak.loggenerator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.Callable;
+
+public class SellTask implements Callable<Long> {
+
+    private static final Logger log = LoggerFactory.getLogger(SellTask.class);
+    private final long id;
+
+        public SellTask(final long id) {
+            this.id = id;
+        }
+
+        @Override
+        public Long call() throws Exception {
+            log.info("{} - {}", id, Utils.getRandomIP());
+            return id;
+        }
+
+}

+ 35 - 0
src/main/java/com/github/vspiewak/loggenerator/Utils.java

@@ -0,0 +1,35 @@
+package com.github.vspiewak.loggenerator;
+
+import com.sun.org.apache.xml.internal.security.algorithms.implementations.SignatureDSA;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+public class Utils {
+
+    private static final Logger log = LoggerFactory.getLogger(Utils.class);
+    private static final List<String> ips = new ArrayList<String>();
+
+    static {
+        try {
+            URI uri = Thread.currentThread().getContextClassLoader().getResource("ips.txt").toURI();
+            ips.addAll(Files.readAllLines(Paths.get(uri), StandardCharsets.UTF_8));
+        } catch (Exception e) {
+            log.error("Error during ip read/parsing", e);
+        }
+    }
+
+    public static String getRandomIP() {
+        int rndInt = new Random().nextInt(ips.size());
+        return ips.get(rndInt);
+    }
+}

+ 436 - 0
src/main/resources/ips.txt

@@ -0,0 +1,436 @@
+2.0.240.217
+2.14.46.207
+2.1.85.39
+2.2.241.173
+2.231.129.129
+2.3.203.195
+2.8.199.62
+5.48.191.103
+10.36.173.122
+24.230.212.23
+31.164.176.25
+31.37.64.129
+37.160.146.222
+37.161.127.153
+37.25.78.100
+41.223.180.98
+41.97.220.180
+46.18.96.158
+46.19.216.170
+46.218.200.2
+46.218.250.142
+50.23.94.74
+54.226.24.77
+54.227.147.193
+62.160.254.156
+62.160.254.157
+62.160.254.158
+62.160.254.247
+62.160.254.248
+62.160.254.249
+62.161.39.6
+62.212.113.166
+62.212.96.45
+62.23.215.100
+62.39.99.97
+65.55.213.72
+65.55.24.219
+66.130.99.148
+66.249.81.158
+70.80.120.74
+72.46.130.42
+74.59.71.177
+76.164.194.74
+76.245.46.23
+77.192.114.164
+77.196.115.82
+77.196.133.159
+77.196.33.68
+77.204.241.75
+77.205.144.28
+77.242.202.237
+78.114.128.154
+78.121.224.250
+78.122.53.38
+78.125.88.233
+78.152.144.124
+78.193.10.137
+78.198.164.4
+78.212.96.87
+78.213.84.38
+78.223.176.115
+78.226.206.168
+78.226.37.248
+78.234.4.139
+78.235.129.40
+78.245.15.9
+78.245.218.69
+78.247.117.100
+78.249.72.117
+78.250.209.114
+78.250.238.89
+78.250.32.170
+78.251.137.177
+78.251.230.48
+78.251.84.243
+79.161.20.58
+79.80.172.38
+79.81.194.5
+79.85.46.149
+79.86.215.47
+79.86.250.59
+79.88.145.68
+79.92.164.25
+79.93.55.204
+79.94.201.94
+80.10.159.198
+80.10.159.226
+80.10.159.231
+80.11.193.31
+80.11.232.211
+80.11.39.22
+80.118.118.247
+80.118.33.228
+80.12.100.19
+80.12.100.44
+80.12.110.207
+80.13.231.58
+80.13.235.125
+80.14.37.69
+80.15.220.251
+80.215.1.51
+80.215.28.94
+80.215.32.142
+80.215.33.111
+80.215.33.94
+80.215.40.231
+80.215.64.179
+80.78.9.34
+80.82.234.134
+80.82.239.10
+81.20.211.186
+81.220.48.195
+81.251.86.65
+81.252.187.83
+81.253.62.103
+81.255.116.40
+81.255.131.233
+81.56.203.53
+81.57.51.55
+81.57.51.61
+81.64.13.213
+81.64.80.230
+81.65.69.77
+81.80.87.120
+82.103.128.63
+82.120.73.69
+82.121.185.168
+82.122.193.129
+82.123.40.97
+82.126.60.84
+82.126.99.201
+82.127.201.244
+82.150.19.227
+82.216.46.191
+82.216.76.85
+82.224.136.79
+82.224.185.146
+82.224.65.247
+82.225.2.247
+82.225.62.69
+82.226.108.31
+82.226.140.39
+82.227.181.9
+82.228.28.66
+82.230.23.188
+82.233.82.117
+82.235.37.8
+82.237.231.110
+82.238.94.195
+82.239.107.163
+82.240.203.178
+82.243.25.222
+82.244.14.82
+82.245.88.66
+82.66.10.102
+82.66.138.27
+82.66.250.41
+82.67.143.192
+82.67.176.144
+82.67.212.205
+82.67.41.46
+83.112.70.237
+83.114.120.241
+83.137.242.22
+83.145.100.34
+83.152.90.13
+83.155.181.158
+83.155.50.121
+83.193.110.199
+83.197.137.33
+83.202.200.159
+83.203.204.79
+83.205.46.145
+83.206.39.45
+84.102.131.99
+84.102.53.31
+84.102.8.156
+84.14.169.30
+84.5.189.224
+84.97.38.228
+84.99.204.32
+84.99.57.151
+85.117.148.125
+85.171.197.218
+85.17.156.11
+85.17.156.99
+85.31.218.186
+86.192.72.48
+86.196.22.221
+86.204.108.183
+86.207.66.45
+86.207.84.175
+86.209.157.23
+86.209.180.150
+86.210.13.128
+86.211.84.48
+86.213.251.48
+86.221.177.233
+86.63.245.182
+86.66.129.144
+86.66.37.46
+86.67.10.158
+86.68.113.90
+86.69.65.90
+86.72.65.200
+86.73.160.167
+86.73.24.74
+87.231.182.44
+87.231.59.143
+87.88.71.215
+88.137.142.185
+88.138.194.157
+88.139.111.219
+88.161.114.67
+88.162.178.163
+88.163.208.90
+88.166.255.31
+88.167.157.202
+88.168.100.69
+88.169.77.151
+88.170.176.54
+88.172.36.189
+88.172.66.25
+88.175.196.162
+88.175.89.162
+88.179.12.229
+88.180.247.164
+88.184.44.95
+88.186.70.26
+88.190.210.243
+89.156.70.232
+89.157.14.143
+89.159.232.120
+89.17.121.220
+89.202.137.8
+89.84.25.141
+89.87.249.88
+89.93.253.227
+90.0.109.27
+90.0.126.162
+90.11.118.150
+90.15.77.193
+90.25.76.9
+90.29.9.104
+90.32.9.203
+90.33.93.13
+90.34.42.196
+90.37.80.119
+90.39.71.123
+90.41.105.231
+90.48.149.40
+90.48.221.228
+90.50.54.145
+90.52.64.247
+90.53.191.23
+90.54.159.178
+90.60.20.83
+90.60.78.202
+90.61.148.18
+90.61.89.94
+90.6.44.105
+90.7.26.116
+90.80.234.26
+90.8.169.94
+90.83.51.21
+90.84.144.220
+90.84.144.237
+90.84.144.93
+90.84.145.24
+90.84.146.222
+90.84.146.227
+90.84.146.235
+90.9.130.28
+91.91.16.164
+92.103.22.254
+92.130.110.144
+92.132.175.218
+92.134.177.156
+92.135.181.173
+92.135.204.108
+92.137.100.193
+92.137.187.68
+92.143.197.219
+92.144.155.169
+92.144.181.182
+92.145.205.156
+92.153.23.28
+92.158.156.185
+92.161.105.19
+92.162.35.163
+92.231.211.198
+92.42.223.3
+92.90.16.135
+92.90.16.190
+92.90.16.222
+92.90.16.32
+92.90.16.94
+92.90.17.5
+92.90.20.211
+92.90.26.108
+93.1.160.26
+93.13.108.144
+93.174.145.106
+93.17.56.247
+93.27.189.125
+93.31.186.100
+93.31.36.162
+94.127.14.157
+94.185.159.252
+94.228.34.210
+94.247.174.83
+94.46.240.121
+94.46.4.1
+95.170.44.138
+98.223.228.215
+108.161.112.220
+108.59.8.70
+108.62.115.226
+109.106.78.192
+109.11.237.163
+109.12.183.196
+109.13.100.162
+109.14.100.130
+109.15.214.57
+109.16.6.224
+109.190.26.87
+109.209.160.135
+109.211.12.248
+109.213.102.149
+109.213.24.192
+109.213.25.2
+109.217.113.252
+109.218.39.112
+109.2.197.218
+109.222.238.42
+109.23.131.167
+109.28.195.174
+109.2.96.202
+109.30.82.110
+109.7.15.36
+109.7.26.228
+109.7.33.126
+109.7.67.126
+109.8.110.250
+111.161.50.28
+111.240.70.197
+119.63.193.132
+123.125.71.13
+123.125.71.15
+123.125.71.48
+123.125.71.56
+128.93.62.145
+128.93.62.51
+143.126.201.151
+145.226.30.43
+145.226.30.45
+145.226.94.44
+150.70.172.208
+150.70.173.48
+150.70.64.209
+150.70.64.215
+150.70.75.28
+150.70.75.34
+150.70.97.113
+150.70.97.117
+150.70.97.120
+150.70.97.122
+150.70.97.123
+150.70.97.127
+157.55.34.94
+157.99.64.13
+159.50.249.150
+163.116.6.10
+163.116.6.11
+163.116.6.14
+164.131.224.225
+171.16.208.2
+173.252.73.112
+173.252.73.115
+176.31.228.137
+178.19.141.88
+178.211.100.252
+178.213.64.2
+178.255.155.2
+178.255.215.67
+184.75.209.18
+184.75.210.186
+188.138.118.184
+188.138.124.110
+188.142.64.189
+188.165.245.107
+188.219.135.214
+192.196.142.21
+192.35.17.15
+192.54.145.146
+192.54.145.66
+193.134.254.25
+193.248.159.223
+193.248.203.28
+193.48.226.82
+193.49.225.10
+193.57.67.241
+194.126.21.1
+194.149.94.118
+194.3.206.100
+194.8.148.24
+195.101.177.200
+195.101.177.3
+195.132.242.17
+195.132.255.82
+195.189.143.56
+195.221.106.161
+195.76.98.135
+195.83.97.32
+198.102.219.141
+199.192.76.58
+199.87.228.66
+202.46.52.35
+202.46.56.49
+212.23.175.167
+212.23.175.185
+212.234.159.203
+212.234.93.154
+212.51.175.66
+212.99.94.100
+213.189.150.66
+213.41.248.250
+217.109.123.82
+217.109.49.180
+217.69.16.122
+217.77.225.129
+217.77.225.130
+217.77.77.226
+220.181.108.105
+220.181.108.86
+220.181.108.96

+ 18 - 0
src/main/resources/logback.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+  <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
+      <encoder>
+            <pattern>
+                    %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+            </pattern>
+      </encoder>
+  </appender>
+
+  <logger name="com.github" level="all" />
+        
+  <root level="INFO">
+      <appender-ref ref="stdout"/>
+  </root>
+
+</configuration>