From 87080bdc05c1f3c28e40af674f6b24f280924ee4 Mon Sep 17 00:00:00 2001 From: elroy Date: Wed, 5 Jul 2017 23:05:56 +0200 Subject: [PATCH] cleanup always show ticker update on screen rolling log to file. --- GunbotProxyCommunity.iml | 3 +-- pom.xml | 6 ----- .../komtek/gpi/application/Application.java | 10 ++----- .../gpi/services/GunbotProxyService.java | 24 +++++++++++------ .../gpi/utils/ProxyHandledException.java | 11 ++++++++ .../nl/komtek/gpi/utils/ScheduledTasks.java | 2 +- src/main/resources/log4j2.xml | 27 +++++++++++++------ 7 files changed, 50 insertions(+), 33 deletions(-) create mode 100644 src/main/java/nl/komtek/gpi/utils/ProxyHandledException.java diff --git a/GunbotProxyCommunity.iml b/GunbotProxyCommunity.iml index 6569c99..bb2bc37 100644 --- a/GunbotProxyCommunity.iml +++ b/GunbotProxyCommunity.iml @@ -32,8 +32,7 @@ - - + diff --git a/pom.xml b/pom.xml index cf37925..e514ea6 100644 --- a/pom.xml +++ b/pom.xml @@ -46,16 +46,10 @@ slf4j-api 1.7.25 - - org.slf4j - slf4j-simple - 1.6.4 - org.apache.logging.log4j log4j-slf4j-impl 2.8.2 - test org.apache.logging.log4j diff --git a/src/main/java/nl/komtek/gpi/application/Application.java b/src/main/java/nl/komtek/gpi/application/Application.java index e3aeaba..9302999 100644 --- a/src/main/java/nl/komtek/gpi/application/Application.java +++ b/src/main/java/nl/komtek/gpi/application/Application.java @@ -14,13 +14,12 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; -import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; -import java.util.concurrent.Executor; +import java.util.concurrent.Executors; /** * Created by Elroy on 29-6-2017. @@ -55,14 +54,9 @@ public class Application { return factory; } - @Bean - public Executor taskExecutor() { - return new SimpleAsyncTaskExecutor(); - } - @Bean public TaskScheduler taskScheduler() { - return new ConcurrentTaskScheduler(); + return new ConcurrentTaskScheduler(Executors.newScheduledThreadPool(5)); } @Bean diff --git a/src/main/java/nl/komtek/gpi/services/GunbotProxyService.java b/src/main/java/nl/komtek/gpi/services/GunbotProxyService.java index 9e19b48..4a50d91 100644 --- a/src/main/java/nl/komtek/gpi/services/GunbotProxyService.java +++ b/src/main/java/nl/komtek/gpi/services/GunbotProxyService.java @@ -8,6 +8,8 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import net.jodah.failsafe.Failsafe; import net.jodah.failsafe.RetryPolicy; +import nl.komtek.gpi.utils.ProxyHandledException; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -155,7 +157,6 @@ public class GunbotProxyService { @Cacheable(value = "chartData", key = "#currencyPair") public String getChartData(String currencyPair, String start, long period) { - logger.debug("chartData: " + currencyPair + " -- start:" + start + " -- period:" + period); long startLong = 0; if (start.indexOf(".") > 0) { startLong = Long.valueOf(start.substring(0, start.indexOf("."))); @@ -166,7 +167,9 @@ public class GunbotProxyService { while (true) { try { String result = publicClient.getChartData(currencyPair, period, startLong); - return analyzeResult(result); + result = analyzeResult(result); + logger.debug("chartData: " + currencyPair + " -- start:" + start + " -- period:" + period + " -- " + result); + return result; } catch (Exception e) { handleException(e); } @@ -183,7 +186,12 @@ public class GunbotProxyService { String result = Failsafe.with(retryPolicy) .onFailedAttempt(this::handleException) .get(() -> analyzeResult(publicClient.returnTicker())); - logger.debug("ticker: " + result); + + if (logger.getLevel().isLessSpecificThan(Level.DEBUG)) { + logger.info("ticker updated"); + } else { + logger.info("ticker: " + result); + } return result; } @@ -346,20 +354,20 @@ public class GunbotProxyService { private String analyzeResult(String result) { if (result != null && result.contains("Nonce")) { - throw new RuntimeException("nonce error: " + result); + throw new ProxyHandledException("nonce error: " + result); } else if (result == null) { - throw new RuntimeException("No value was returned"); + throw new ProxyHandledException("No value was returned"); } return result; } private void handleException(Throwable e) { - if (!(e instanceof RuntimeException)) { - logger.error(e.toString()); + if (e instanceof ProxyHandledException) { + logger.debug(e.toString()); } else if (e instanceof NullPointerException) { logger.error("Something is really wrong", e); } else { - logger.debug(e.toString()); + logger.error(e.toString()); } } diff --git a/src/main/java/nl/komtek/gpi/utils/ProxyHandledException.java b/src/main/java/nl/komtek/gpi/utils/ProxyHandledException.java new file mode 100644 index 0000000..909c2fa --- /dev/null +++ b/src/main/java/nl/komtek/gpi/utils/ProxyHandledException.java @@ -0,0 +1,11 @@ +package nl.komtek.gpi.utils; + +/** + * Created by Elroy on 05-7-2017. + */ +public class ProxyHandledException extends RuntimeException { + + public ProxyHandledException(String message) { + super(message); + } +} diff --git a/src/main/java/nl/komtek/gpi/utils/ScheduledTasks.java b/src/main/java/nl/komtek/gpi/utils/ScheduledTasks.java index a3d3288..de7def2 100644 --- a/src/main/java/nl/komtek/gpi/utils/ScheduledTasks.java +++ b/src/main/java/nl/komtek/gpi/utils/ScheduledTasks.java @@ -18,7 +18,7 @@ public class ScheduledTasks { @Autowired private GunbotProxyService gunbotProxyService; - @Scheduled(fixedDelay = Long.MAX_VALUE) + @Scheduled(fixedRate = Long.MAX_VALUE) public void itWorks() { if (gunbotProxyService.isUsingMultipleMarkets()) { logger.info("Running in multimarket MODE!"); diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index 1a13629..ef2958b 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -1,25 +1,36 @@ + + logs + - - - + + + + + + + + + + - - - + + + - + - + \ No newline at end of file