|
From: Robert E. <sky...@us...> - 2009-12-15 20:01:38
|
Update of /cvsroot/jcommander/plugins/org.jcommander.ui.app/src/org/jcommander/ui/app/singleton In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv14659/src/org/jcommander/ui/app/singleton Modified Files: SingletonAppLauncher.java Log Message: Improved logging Index: SingletonAppLauncher.java =================================================================== RCS file: /cvsroot/jcommander/plugins/org.jcommander.ui.app/src/org/jcommander/ui/app/singleton/SingletonAppLauncher.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SingletonAppLauncher.java 6 Aug 2006 10:32:17 -0000 1.2 --- SingletonAppLauncher.java 15 Dec 2009 20:01:28 -0000 1.3 *************** *** 6,9 **** --- 6,11 ---- import java.net.Socket; + import org.apache.log4j.Logger; + /** *************** *** 15,22 **** public class SingletonAppLauncher { ! private final ApplicationEntryPoint entryPoint; private final int fromPort; private final int toPort; ! public SingletonAppLauncher(ApplicationEntryPoint entryPoint, int fromPort, int toPort){ if(null == entryPoint){ --- 17,26 ---- public class SingletonAppLauncher { ! protected static final Logger LOG = Logger.getLogger(SingletonAppLauncher.class); ! ! private final ApplicationEntryPoint entryPoint; private final int fromPort; private final int toPort; ! public SingletonAppLauncher(ApplicationEntryPoint entryPoint, int fromPort, int toPort){ if(null == entryPoint){ *************** *** 34,40 **** this.entryPoint = entryPoint; this.fromPort = fromPort; ! this.toPort = toPort; } ! public boolean startingFirstInstance(String[] params){ ServerSocket server = null; --- 38,44 ---- this.entryPoint = entryPoint; this.fromPort = fromPort; ! this.toPort = toPort; } ! public boolean startingFirstInstance(String[] params){ ServerSocket server = null; *************** *** 47,51 **** } else{ ! try{ loopSocket.close(); }catch(Exception ex){} --- 51,55 ---- } else{ ! try{ loopSocket.close(); }catch(Exception ex){} *************** *** 82,86 **** } } ! private boolean startSameApp(Socket sameApplication, String[] parameters){ try{ --- 86,90 ---- } } ! private boolean startSameApp(Socket sameApplication, String[] parameters){ try{ *************** *** 110,114 **** } } ! private ServerSocket tryToOccupy(int port){ try { --- 114,118 ---- } } ! private ServerSocket tryToOccupy(int port){ try { *************** *** 121,125 **** } } ! private Socket contactSameApplication(int port){ Socket client = null; --- 125,129 ---- } } ! private Socket contactSameApplication(int port){ Socket client = null; *************** *** 127,131 **** try { client = new Socket(InetAddress.getLocalHost(), port); ! client.setSoTimeout(250); PrintWriter writer = new PrintWriter(client.getOutputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream())); --- 131,135 ---- try { client = new Socket(InetAddress.getLocalHost(), port); ! client.setSoTimeout(250); PrintWriter writer = new PrintWriter(client.getOutputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream())); *************** *** 139,146 **** return null; } catch (IOException e) { ! System.err.println("Error communicating:" + e); return null; } catch (Throwable t){ ! t.printStackTrace(); return null; } finally{ --- 143,150 ---- return null; } catch (IOException e) { ! LOG.warn("Error communicating:" + e, e); return null; } catch (Throwable t){ ! LOG.warn(t, t); return null; } finally{ *************** *** 152,168 **** } } ! private static class HandshakeServer { protected final ServerSocket socket; protected final ApplicationEntryPoint entryPoint; ! public HandshakeServer(ServerSocket socket, ApplicationEntryPoint entryPoint){ if(null == socket){ throw new NullPointerException("socket"); ! } if(null == entryPoint){ throw new NullPointerException("entryPoint"); ! } ! this.socket = socket; this.entryPoint = entryPoint; while(true){ --- 156,172 ---- } } ! private static class HandshakeServer { protected final ServerSocket socket; protected final ApplicationEntryPoint entryPoint; ! public HandshakeServer(ServerSocket socket, ApplicationEntryPoint entryPoint){ if(null == socket){ throw new NullPointerException("socket"); ! } if(null == entryPoint){ throw new NullPointerException("entryPoint"); ! } ! this.socket = socket; this.entryPoint = entryPoint; while(true){ *************** *** 176,180 **** } } ! private class ClientHandler implements Runnable{ private final Socket socket; --- 180,184 ---- } } ! private class ClientHandler implements Runnable{ private final Socket socket; *************** *** 185,189 **** this.socket = socket; } ! public void run(){ try{ --- 189,193 ---- this.socket = socket; } ! public void run(){ try{ *************** *** 205,213 **** } catch(IOException ex){ ! ex.printStackTrace(); ! System.out.println(ex); } } ! private String handleLine(String line){ if(Requests.RETRIEVE_ID_REQUEST.equalsIgnoreCase(line)){ --- 209,216 ---- } catch(IOException ex){ ! LOG.warn(ex, ex); } } ! private String handleLine(String line){ if(Requests.RETRIEVE_ID_REQUEST.equalsIgnoreCase(line)){ *************** *** 227,231 **** return "UNKNOWN:" + line; } ! private void startup(String line){ String[] params = null; --- 230,234 ---- return "UNKNOWN:" + line; } ! private void startup(String line){ String[] params = null; *************** *** 240,251 **** }, "STARTUP").start(); } ! } ! } ! private static class Requests{ public static final String STARTUP_REQUEST = "STARTUP_"; public static final String DISCONNECT_REQUEST = "HANDSHAKE_DISCONNECT"; public static final String RETRIEVE_ID_REQUEST = "WHO_ARE_YOU"; ! private Requests(){} } --- 243,254 ---- }, "STARTUP").start(); } ! } ! } ! private static class Requests{ public static final String STARTUP_REQUEST = "STARTUP_"; public static final String DISCONNECT_REQUEST = "HANDSHAKE_DISCONNECT"; public static final String RETRIEVE_ID_REQUEST = "WHO_ARE_YOU"; ! private Requests(){} } |