Commit 4afc44ac by Dave Syer

Catch exception and log instead of failing

Some singleton clashes are inevitable if running multiple apps i nteh same JVM, but we can at least try and not fall off a cliff when they happen.
parent 4f39b64f
...@@ -22,6 +22,7 @@ import java.util.List; ...@@ -22,6 +22,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import lombok.extern.apachecommons.CommonsLog; import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.boot.actuate.metrics.reader.MetricReader; import org.springframework.boot.actuate.metrics.reader.MetricReader;
...@@ -52,8 +53,16 @@ public class ServoMetricCollector implements DisposableBean { ...@@ -52,8 +53,16 @@ public class ServoMetricCollector implements DisposableBean {
BasicMetricFilter.MATCH_ALL, true, observers); BasicMetricFilter.MATCH_ALL, true, observers);
if (!PollScheduler.getInstance().isStarted()) { if (!PollScheduler.getInstance().isStarted()) {
try {
PollScheduler.getInstance().start(); PollScheduler.getInstance().start();
} }
catch (Exception e) {
// Can fail due to race condition with evil singletons (if more than one
// app in same JVM)
log.error("Could not start servo metrics poller", e);
return;
}
}
// TODO Make poll interval configurable // TODO Make poll interval configurable
PollScheduler.getInstance().addPoller(task, 5, TimeUnit.SECONDS); PollScheduler.getInstance().addPoller(task, 5, TimeUnit.SECONDS);
} }
...@@ -62,8 +71,13 @@ public class ServoMetricCollector implements DisposableBean { ...@@ -62,8 +71,13 @@ public class ServoMetricCollector implements DisposableBean {
public void destroy() throws Exception { public void destroy() throws Exception {
log.info("Stopping Servo PollScheduler"); log.info("Stopping Servo PollScheduler");
if (PollScheduler.getInstance().isStarted()) { if (PollScheduler.getInstance().isStarted()) {
try {
PollScheduler.getInstance().stop(); PollScheduler.getInstance().stop();
} }
catch (Exception e) {
log.error("Could not stop servo metrics poller", e);
}
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment