private SSLSocketFactory sslSocketFactory;
public char monitor(Host host) {
SocketBasedHost socketBasedHost = (SocketBasedHost) host;
BlockingClient client = new BlockingClient();
try {
client.setSecure(socketBasedHost.isSecure());
client.setUseDummyTrustManager(isUseDummyTrustManager());
if(getSslSocketFactory()!=null) {
client.setSslSocketFactory(getSslSocketFactory());
}
client.connect(socketBasedHost.getInetAddress().getHostAddress(),
socketBasedHost.getInetSocketAddress().getPort());
if(socketBasedHost.getTextToExpect()!=null) {
String textGot = client.readBytes();
if(textGot.indexOf(socketBasedHost.getTextToExpect())!=-1) {
return Host.ACTIVE;
} else {
logger.fine(socketBasedHost+" Error: Text ["+socketBasedHost.getTextToExpect()
+"]Not found! Got: "+textGot);
return Host.DOWN;
}
} else {
return Host.ACTIVE;
}
} catch (IOException e) {
logger.fine(socketBasedHost+" IOError: "+e);
return Host.DOWN;
} catch (Exception e) {
logger.warning(socketBasedHost+" Error: "+e);
return Host.ERROR;
} finally {
if(client!=null) {
try {
client.close();
} catch (IOException ex) {
Logger.getLogger(SocketMonitor.class.getName()).log(Level.FINE, "Error", ex);
}
}
host.setLastCheckedOn(new Date());