From 138cce7b62033d9b81f71943bda85ac9775b4fbc Mon Sep 17 00:00:00 2001 From: Vincent Spiewak Date: Thu, 12 Sep 2013 17:43:27 +0200 Subject: [PATCH] Initial commit --- pom.xml | 234 ++++++++++ .../com/github/vspiewak/loggenerator/App.java | 36 ++ .../vspiewak/loggenerator/LogExecutor.java | 37 ++ .../vspiewak/loggenerator/SearchTask.java | 23 + .../vspiewak/loggenerator/SellTask.java | 23 + .../github/vspiewak/loggenerator/Utils.java | 35 ++ src/main/resources/ips.txt | 436 ++++++++++++++++++ src/main/resources/logback.xml | 18 + 8 files changed, 842 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/com/github/vspiewak/loggenerator/App.java create mode 100644 src/main/java/com/github/vspiewak/loggenerator/LogExecutor.java create mode 100644 src/main/java/com/github/vspiewak/loggenerator/SearchTask.java create mode 100644 src/main/java/com/github/vspiewak/loggenerator/SellTask.java create mode 100644 src/main/java/com/github/vspiewak/loggenerator/Utils.java create mode 100644 src/main/resources/ips.txt create mode 100644 src/main/resources/logback.xml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..0970170 --- /dev/null +++ b/pom.xml @@ -0,0 +1,234 @@ + + + 4.0.0 + + + com.github.vspiewak + log-generator + 0.0.1-SNAPSHOT + jar + + + log-generator + + A simple log generator + + http://github.com/vspiewak/log-generator + + 2013 + + + Vincent Spiewak + http://www.github.com/vspiewak + + + + + + com.github.vspiewak.loggenerator.App + + + UTF-8 + UTF-8 + + + 1.7.5 + 1.0.13 + + [2.2.1, 3.1.0) + 1.6 + 2.1 + 2.4 + + + + + + + + + vspiewak + Vincent Spiewak + vspiewak+github@gmail.com + + Admin + Developer + + http://github.com/vspiewak + + + + + + + + org.slf4j + slf4j-api + ${slf4j.version} + compile + + + + ch.qos.logback + logback-classic + ${logback.version} + runtime + + + + + junit + junit + 4.10 + test + + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + + + ${java.version} + ${java.version} + + + true + true + + + + + + + org.apache.maven.plugins + maven-jar-plugin + ${maven.jar.plugin} + + + + + ${java.main.class} + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven.shade.plugin} + + true + + + + package + + shade + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 1.0 + + + enforce + + enforce + + + + + true + + + true + + + + + + + ${maven.versions} + + + + + ${java.version} + + + + + snapshots dependency found + + + + + + + + ... defined in pom.xml]]> + + + + + + + + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + [1.0.0,) + + enforce + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/github/vspiewak/loggenerator/App.java b/src/main/java/com/github/vspiewak/loggenerator/App.java new file mode 100644 index 0000000..1c4da77 --- /dev/null +++ b/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"); + + } + +} diff --git a/src/main/java/com/github/vspiewak/loggenerator/LogExecutor.java b/src/main/java/com/github/vspiewak/loggenerator/LogExecutor.java new file mode 100644 index 0000000..3b6d27c --- /dev/null +++ b/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 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()) { + } + + } +} diff --git a/src/main/java/com/github/vspiewak/loggenerator/SearchTask.java b/src/main/java/com/github/vspiewak/loggenerator/SearchTask.java new file mode 100644 index 0000000..d21b226 --- /dev/null +++ b/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 { + + 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; + } + +} diff --git a/src/main/java/com/github/vspiewak/loggenerator/SellTask.java b/src/main/java/com/github/vspiewak/loggenerator/SellTask.java new file mode 100644 index 0000000..ab6c66d --- /dev/null +++ b/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 { + + 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; + } + +} diff --git a/src/main/java/com/github/vspiewak/loggenerator/Utils.java b/src/main/java/com/github/vspiewak/loggenerator/Utils.java new file mode 100644 index 0000000..0f81120 --- /dev/null +++ b/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 ips = new ArrayList(); + + 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); + } +} diff --git a/src/main/resources/ips.txt b/src/main/resources/ips.txt new file mode 100644 index 0000000..7f710c6 --- /dev/null +++ b/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 diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..d634f4a --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,18 @@ + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + +