mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-27 16:06:39 +00:00
renamed Endpoint/IEndpoint to EndpointImpl and Endpoint, respectively
This commit is contained in:
+7
-6
@@ -9,6 +9,7 @@ import java.net.SocketTimeoutException;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* Simple post monitoring application. Checks given ports in an regular interval.
|
||||
* If there is a problem it calls the registered handler.
|
||||
@@ -24,26 +25,26 @@ public abstract class AbstractPortMonitor extends Thread {
|
||||
private int graceful = 5000;
|
||||
private int pause = 1000;
|
||||
|
||||
protected IEndpoint[] endpoints = null;
|
||||
protected Endpoint[] endpoints = null;
|
||||
protected int interval;
|
||||
|
||||
boolean started = false;
|
||||
boolean paused = false;
|
||||
|
||||
private long lastmillis;
|
||||
private IEndpoint currentendpoint;
|
||||
private Endpoint currentendpoint;
|
||||
|
||||
protected Properties properties;
|
||||
|
||||
public AbstractPortMonitor(Properties properties) {
|
||||
String[] prop_endpoints = properties.getProperty("monitor.endpoints").split(",");
|
||||
|
||||
this.endpoints = new IEndpoint[prop_endpoints.length];
|
||||
this.endpoints = new Endpoint[prop_endpoints.length];
|
||||
for (int i=0; i<prop_endpoints.length;i++) {
|
||||
String[] data = prop_endpoints[i].split(":");
|
||||
|
||||
try {
|
||||
Endpoint e = new Endpoint(new InetSocketAddress(InetAddress.getByName(data[0].trim()), Integer.parseInt(data[1].trim())));
|
||||
EndpointImpl e = new EndpointImpl(new InetSocketAddress(InetAddress.getByName(data[0].trim()), Integer.parseInt(data[1].trim())));
|
||||
this.endpoints[i] = e;
|
||||
} catch (Exception ex) {
|
||||
log.severe("Could not parse endpoint definition " + prop_endpoints[i]);
|
||||
@@ -121,8 +122,8 @@ public abstract class AbstractPortMonitor extends Thread {
|
||||
this.started = false;
|
||||
}
|
||||
|
||||
public abstract void handleFailure(IEndpoint endpoint);
|
||||
public abstract void handleFailure(Endpoint endpoint);
|
||||
|
||||
public abstract void handleConnection(IEndpoint endpoint);
|
||||
public abstract void handleConnection(Endpoint endpoint);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,69 +3,33 @@ package com.sap.sailing.monitoring;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* @see IEndpoint
|
||||
* Definition of an endpoint that submits to checks by
|
||||
* the monitoring service. It consists of an address, a port
|
||||
* and additional status information.
|
||||
*
|
||||
* @author Simon Pamies (info@pamies.de)
|
||||
* @since Nov 28, 2012
|
||||
*/
|
||||
public class Endpoint implements IEndpoint {
|
||||
|
||||
private InetSocketAddress address;
|
||||
private String name = "";
|
||||
private long last_success = 0;
|
||||
private long last_fail = 0;
|
||||
private boolean already_checked = false;
|
||||
public interface Endpoint {
|
||||
|
||||
public Endpoint(InetSocketAddress address) {
|
||||
this.address = address;
|
||||
}
|
||||
InetSocketAddress getAddress();
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long lastSucceeded() {
|
||||
return last_success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long lastFailed() {
|
||||
return last_fail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alreadyChecked() {
|
||||
return already_checked;
|
||||
}
|
||||
String getName();
|
||||
|
||||
@Override
|
||||
public boolean hasFailed() {
|
||||
return (last_fail > last_success);
|
||||
}
|
||||
long lastSucceeded();
|
||||
|
||||
public void setSuccess(long millis) {
|
||||
last_success = millis;
|
||||
already_checked = true;
|
||||
}
|
||||
long lastFailed();
|
||||
|
||||
public void setFailure(long millis) {
|
||||
last_fail = millis;
|
||||
}
|
||||
boolean alreadyChecked();
|
||||
|
||||
public String toString() {
|
||||
return getAddress().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
boolean hasFailed();
|
||||
|
||||
void setSuccess(long millis);
|
||||
|
||||
void setFailure(long millis);
|
||||
|
||||
void setName(String name);
|
||||
|
||||
String toString();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.sap.sailing.monitoring;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
|
||||
/**
|
||||
* @see Endpoint
|
||||
*
|
||||
* @author Simon Pamies (info@pamies.de)
|
||||
* @since Nov 28, 2012
|
||||
*/
|
||||
public class EndpointImpl implements Endpoint {
|
||||
|
||||
private InetSocketAddress address;
|
||||
private String name = "";
|
||||
private long last_success = 0;
|
||||
private long last_fail = 0;
|
||||
private boolean already_checked = false;
|
||||
|
||||
public EndpointImpl(InetSocketAddress address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long lastSucceeded() {
|
||||
return last_success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long lastFailed() {
|
||||
return last_fail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alreadyChecked() {
|
||||
return already_checked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFailed() {
|
||||
return (last_fail > last_success);
|
||||
}
|
||||
|
||||
public void setSuccess(long millis) {
|
||||
last_success = millis;
|
||||
already_checked = true;
|
||||
}
|
||||
|
||||
public void setFailure(long millis) {
|
||||
last_fail = millis;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getAddress().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.sap.sailing.monitoring;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* Definition of an endpoint that submits to checks by
|
||||
* the monitoring service. It consists of an address, a port
|
||||
* and additional status information.
|
||||
*
|
||||
* @author Simon Pamies (info@pamies.de)
|
||||
* @since Nov 28, 2012
|
||||
*/
|
||||
public interface IEndpoint {
|
||||
|
||||
public InetSocketAddress getAddress();
|
||||
|
||||
public String getName();
|
||||
|
||||
public long lastSucceeded();
|
||||
|
||||
public long lastFailed();
|
||||
|
||||
public boolean alreadyChecked();
|
||||
|
||||
public boolean hasFailed();
|
||||
|
||||
public void setSuccess(long millis);
|
||||
|
||||
public void setFailure(long millis);
|
||||
|
||||
public void setName(String name);
|
||||
|
||||
public String toString();
|
||||
|
||||
}
|
||||
+4
-3
@@ -43,7 +43,7 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFailure(IEndpoint endpoint) {
|
||||
public void handleFailure(Endpoint endpoint) {
|
||||
Bundle bundle = bundles.get(endpoint.getName());
|
||||
|
||||
if (bundle.getState() == BundleEvent.STARTED || bundle.getState() == BundleEvent.STOPPED) {
|
||||
@@ -63,7 +63,7 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
log.info("Bundle " + endpoint.getName() + " restarted");
|
||||
|
||||
/* only send mail if service has not failed before */
|
||||
if (!endpoint.hasFailed())
|
||||
if (!endpoint.hasFailed()) {
|
||||
try {
|
||||
Session session = Session.getDefaultInstance(this.properties, new SMTPAuthenticator());
|
||||
MimeMessage msg = new MimeMessage(session);
|
||||
@@ -80,6 +80,7 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
} catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SMTPAuthenticator extends javax.mail.Authenticator {
|
||||
@@ -91,7 +92,7 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleConnection(IEndpoint endpoint) {
|
||||
public void handleConnection(Endpoint endpoint) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,12 +16,12 @@ public class SystemPrinterPortMonitor extends AbstractPortMonitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFailure(IEndpoint endpoint) {
|
||||
public void handleFailure(Endpoint endpoint) {
|
||||
System.out.println("ERROR: Could not connect to endpoint " + endpoint.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleConnection(IEndpoint endpoint) {
|
||||
public void handleConnection(Endpoint endpoint) {
|
||||
System.out.println("INFO: Connection to " + endpoint.toString() + " succeeded.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user