diff options
author | jestin | 2011-07-22 16:49:57 +0000 |
---|---|---|
committer | jestin | 2011-07-22 16:49:57 +0000 |
commit | 750f33265d208df8218f85359e3f027900c58363 (patch) | |
tree | 105db356fc9b87fc04f1c09a4c2a567e93b37eed /src/IvyDaemon.java | |
parent | 90ac7a3566995cc244f9fdaff41e6c5122c7ca2e (diff) | |
download | ivy-java-750f33265d208df8218f85359e3f027900c58363.zip ivy-java-750f33265d208df8218f85359e3f027900c58363.tar.gz ivy-java-750f33265d208df8218f85359e3f027900c58363.tar.bz2 ivy-java-750f33265d208df8218f85359e3f027900c58363.tar.xz |
Passage en 1.2.14
Diffstat (limited to 'src/IvyDaemon.java')
-rw-r--r-- | src/IvyDaemon.java | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/IvyDaemon.java b/src/IvyDaemon.java index 71a2b93..3ec54e6 100644 --- a/src/IvyDaemon.java +++ b/src/IvyDaemon.java @@ -11,6 +11,11 @@ * (c) CENA * * changelog: + * 1.2.14 + * - remove the Thread.start() from the constructor, to avoid mulithread issues + * see * http://findbugs.sourceforge.net/bugDescriptions.html#SC_START_IN_CTOR + * now ,we have to call IvyClient.start() after it has been created + * - gracefully quits when message is received, by quitting the Ivy * 1.2.8 * - goes into tools subpackage * 1.2.3 @@ -35,12 +40,11 @@ public class IvyDaemon implements Runnable { private ServerSocket serviceSocket; - private boolean isRunning=false; private static boolean debug = (System.getProperty("IVY_DEBUG")!=null) ; private volatile Thread clientThread;// volatile to ensure the quick communication private Ivy bus; - public static int DEFAULT_SERVICE_PORT = 3456 ; + public static final int DEFAULT_SERVICE_PORT = 3456 ; public static final String DEFAULTNAME = "IvyDaemon"; public static final String helpmsg = "usage: java fr.dgac.ivy.tools.IvyDaemon [options]\n\t-b BUS\tspecifies the Ivy bus domain\n\t-p\tport number, default "+DEFAULT_SERVICE_PORT+"\n\t-n ivyname (default "+DEFAULTNAME+")\n\t-q\tquiet, no tty output\n\t-d\tdebug\n\t-h\thelp\nListens on the TCP port, and sends each line read on the Ivy bus. It is useful to launch one Ivy Daemon and let scripts send their message on the bus.\n"; @@ -72,25 +76,28 @@ public class IvyDaemon implements Runnable { servicePort = Integer.parseInt(s=opt.getOptarg()); } catch (NumberFormatException nfe) { System.out.println("Invalid port number: " + s ); - System.exit(0); + return; } break; case 'h': default: System.out.println(helpmsg); - System.exit(0); + return; } bus=new Ivy(name,name+" ready",null); if (!quiet) System.out.println("broadcasting on "+bus.domains(domain)); bus.start(domain); if (!quiet) System.out.println("listening on "+servicePort); - IvyDaemon d = new IvyDaemon(bus,servicePort); + new IvyDaemon(bus,servicePort).doStart(); } public IvyDaemon(Ivy bus,int servicePort) throws IOException { this.bus=bus; serviceSocket = new ServerSocket(servicePort) ; clientThread=new Thread(this); + } + + protected void doStart() { clientThread.start(); } @@ -113,10 +120,12 @@ public class IvyDaemon implements Runnable { class SubReader extends Thread { BufferedReader in; + SubReader(Socket socket) throws IOException { in=new BufferedReader(new InputStreamReader(socket.getInputStream())); - start(); + SubReader.this.start(); } + public void run() { traceDebug("Subreader Thread started"); String msg = null; @@ -133,7 +142,7 @@ public class IvyDaemon implements Runnable { } catch (IOException ioe) { traceDebug("Subreader exception ..."); ioe.printStackTrace(); - System.exit(0); + throw new RuntimeException(); } traceDebug("Subreader Thread stopped"); } |