diff --git a/java/com.sap.sailing.monitoring/.classpath b/java/com.sap.sailing.monitoring/.classpath index 098194ca4b7..d1b53753fc8 100644 --- a/java/com.sap.sailing.monitoring/.classpath +++ b/java/com.sap.sailing.monitoring/.classpath @@ -1,5 +1,6 @@ + diff --git a/java/com.sap.sailing.monitoring/META-INF/MANIFEST.MF b/java/com.sap.sailing.monitoring/META-INF/MANIFEST.MF index 98014a1d466..55841ee8adc 100644 --- a/java/com.sap.sailing.monitoring/META-INF/MANIFEST.MF +++ b/java/com.sap.sailing.monitoring/META-INF/MANIFEST.MF @@ -15,3 +15,5 @@ Require-Bundle: javax.servlet;bundle-version="2.5.0", org.eclipse.jetty.util;bundle-version="7.5.4", org.eclipse.jetty.io;bundle-version="7.5.4", org.eclipse.jetty.servlet;bundle-version="7.5.4" +Bundle-ClassPath: lib/mail.jar, + . diff --git a/java/com.sap.sailing.monitoring/build.properties b/java/com.sap.sailing.monitoring/build.properties index 34d2e4d2dad..b08bfeddeb6 100644 --- a/java/com.sap.sailing.monitoring/build.properties +++ b/java/com.sap.sailing.monitoring/build.properties @@ -1,4 +1,5 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - . + .,\ + lib/mail.jar diff --git a/java/com.sap.sailing.monitoring/lib/mail.jar b/java/com.sap.sailing.monitoring/lib/mail.jar new file mode 100644 index 00000000000..300f436ad2a Binary files /dev/null and b/java/com.sap.sailing.monitoring/lib/mail.jar differ diff --git a/java/com.sap.sailing.monitoring/src/com/sap/sailing/monitoring/AbstractPortMonitor.java b/java/com.sap.sailing.monitoring/src/com/sap/sailing/monitoring/AbstractPortMonitor.java index 2bad8a5ab95..d5430dddbff 100644 --- a/java/com.sap.sailing.monitoring/src/com/sap/sailing/monitoring/AbstractPortMonitor.java +++ b/java/com.sap.sailing.monitoring/src/com/sap/sailing/monitoring/AbstractPortMonitor.java @@ -1,9 +1,11 @@ package com.sap.sailing.monitoring; import java.io.IOException; +import java.net.ConnectException; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketTimeoutException; +import java.util.logging.Logger; /** * Simple post monitoring application. Checks given ports in an regular interval. @@ -14,14 +16,18 @@ import java.net.SocketTimeoutException; */ public abstract class AbstractPortMonitor extends Thread { + Logger log = Logger.getLogger(AbstractPortMonitor.class.getName()); + private final int TIMEOUT = 1000; private final int GRACEFUL = 5000; private final int PAUSE = 1000; - private InetSocketAddress[] endpoints = null; - private int interval; + protected InetSocketAddress[] endpoints = null; + protected int interval; boolean started = false; + boolean paused = false; + private long lastmillis; private InetSocketAddress currentendpoint; @@ -34,6 +40,8 @@ public abstract class AbstractPortMonitor extends Thread { this.interval = interval; this.started = true; + + log.info("Initialized monitoring!"); } public void startMonitoring() { @@ -48,32 +56,39 @@ public abstract class AbstractPortMonitor extends Thread { Thread.sleep(GRACEFUL); while (started) { - long currentmillis = System.currentTimeMillis(); - try { - if (currentmillis >= (lastmillis + interval + (100*endpoints.length))) { - for (int i = 0; i < endpoints.length; i++) { - currentendpoint = endpoints[i]; - - Socket sn = new Socket(); - sn.connect(currentendpoint, TIMEOUT); - - handleConnection(currentendpoint); - lastmillis = System.currentTimeMillis(); + if (!paused) { + long currentmillis = System.currentTimeMillis(); + try { + if (currentmillis >= (lastmillis + interval + (100*endpoints.length))) { + for (int i = 0; i < endpoints.length; i++) { + currentendpoint = endpoints[i]; + + Socket sn = new Socket(); + sn.connect(currentendpoint, TIMEOUT); + + log.info("Connection succeeded to " + currentendpoint.toString()); + handleConnection(currentendpoint); + lastmillis = System.currentTimeMillis(); + } } + + } catch (SocketTimeoutException|ConnectException ex) { + log.info("Connection FAILED to " + currentendpoint.toString()); + handleFailure(currentendpoint); + lastmillis = System.currentTimeMillis(); + + } catch (IOException ex) { + ex.printStackTrace(); } - - Thread.sleep(PAUSE); - - } catch (SocketTimeoutException ex) { - handleFailure(currentendpoint); - - } catch (IOException ex) { - ex.printStackTrace(); + } else { + log.info("Pausing..."); } + + Thread.sleep(PAUSE); } } catch (InterruptedException ex) { - System.out.println("Interrupted"); + System.err.println("Interrupted"); } } @@ -82,6 +97,17 @@ public abstract class AbstractPortMonitor extends Thread { this.started = false; } + protected void removeEndpoint(InetSocketAddress endpoint) { + InetSocketAddress[] new_endpoints = new InetSocketAddress[endpoints.length-1]; + + for (int i=0;i endpointservices = new HashMap(); + HashMap bundles = new HashMap(); + + public OSGiRestartingPortMonitor(InetSocketAddress[] endpoints, String[] services, int interval) { + super(endpoints, interval); + + /* store bundles so that we can reference them later */ + for (Bundle bundle : Activator.getContext().getBundles()) { + bundles.put(bundle.getSymbolicName(), bundle); + } + + for (int i=0; i