private static void initEclipseListener(final Configs configs){
//init eclipse hook
if(configs.getEclipseListenerPort() != -1 ){
Thread eclipseListener = new Thread(){
public void run() {
try {
while(true){
Thread.sleep(5000L);
Socket sock = new Socket("127.0.0.1", configs.getEclipseListenerPort());
byte[] response = new byte[4];
sock.getInputStream().read(response);
//@see runjettyrun.Plugin#enableListenter
if(response[0] ==1 && response[1] ==2){
//it's ok!
}else{
//Eclipse crashs
shutdownServer();
}
}
} catch (UnknownHostException e) {
System.err.println("lost connection with Eclipse , shutting down.");
shutdownServer();
} catch (IOException e) {
System.err.println("lost connection with Eclipse , shutting down.");
shutdownServer();
} catch (InterruptedException e) {
System.err.println("lost connection with Eclipse , shutting down.");
shutdownServer();
}
};
};
eclipseListener.start();
}
}
private static void shutdownServer(){
try {
server.stop();
System.exit(-1);
} catch (Exception e1) {
e1.printStackTrace();
}
}