Olá pessoal!
Gente preciso de uma ajuda. Procurei rapidamento no forum sobre algo relativo, mas não achei…
Bom, é o seguinte:
Preciso desenvolver um código com a idéia de um WatchDog(WD), mas não tão robusto.
O WD tem que pegar um endereço de um site qqr exemplo: http://site.com.br
Daí tenta fazer uma conexão ao site.
Se o tempo de conexão ultrapassar um timeout, ele desiste da conexão e restarta o tomcat.
Contudo eu não conheço mto da parte de conexões. ^^
Eu preparei a seguinte classe:
package br.org.reconcavo.site.utils;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
public class WatchDog {
/** Default interval of time between checks, in milliseconds. */
public static long DEFAULT_INTERVAL = 60000;
private String site = new String("http://www.reconcavotecnologia.org.br/");
/** The url to watch. */
protected URL watchedURL;
/** The interval of time between checks. */
protected long interval = DEFAULT_INTERVAL;
/**
* Returns the URL that will be watched.
*
* @return The URL being watched.
*/
public URL getURL() {
return watchedURL;
}
/**
* Returns the interval of time, in milliseconds, between checks on the URL.
*
* @return An interval of time, in milliseconds.
*/
public long getInterval() {
return interval;
}
public boolean execute(){
try{
Proxy proxy = new Proxy( Proxy.Type.HTTP, new InetSocketAddress("192.168.0.13", 3128));
this.watchedURL = new URL(this.site);
URLConnection con = this.watchedURL.openConnection(proxy);
con.setConnectTimeout((int)this.interval);
con.connect();
con.get
}catch (Exception e){
return false;
}
}
}
Mas não sei se estou no caminho certo.
Alguém já passou por algo parecido e pode me dá um help nesse task?
Obrigado desde já.