diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/Ivy.java | 3 | ||||
-rwxr-xr-x | src/IvyClient.java | 3 | ||||
-rwxr-xr-x | src/IvyWatcher.java | 64 | ||||
-rw-r--r-- | src/Makefile | 48 |
4 files changed, 85 insertions, 33 deletions
diff --git a/src/Ivy.java b/src/Ivy.java index fbc9161..b11d546 100755 --- a/src/Ivy.java +++ b/src/Ivy.java @@ -447,7 +447,8 @@ public class Ivy implements Runnable { if (serverThread==thisThread) { traceDebug("Error IvyServer exception: " + e.getMessage()); System.out.println("Ivy server socket reader caught an exception " + e.getMessage()); - e.printStackTrace(); + System.out.println("this is probably a bug in your JVM !"); + // e.printStackTrace(); } else { traceDebug("my server socket has been closed"); } } } diff --git a/src/IvyClient.java b/src/IvyClient.java index 8cd330e..8aad199 100755 --- a/src/IvyClient.java +++ b/src/IvyClient.java @@ -11,6 +11,7 @@ * * CHANGELOG: * 1.2.3: + * - silently stops on InterruptedIOException. * - direct Messages * - deals with early stops during readline * 1.2.2: @@ -216,7 +217,7 @@ public class IvyClient implements Runnable { } catch (IvyException ie) { ie.printStackTrace(); } catch (InterruptedIOException ioe) { - System.out.println("I have been interrupted. I'm about to leave my thread loop"); + traceDebug("I have been interrupted. I'm about to leave my thread loop"); if (thisThread!=clientThread) break; } catch (IOException e) { traceDebug("abnormally Disconnected from "+ socket.getInetAddress().getHostName()+":"+socket.getPort()); diff --git a/src/IvyWatcher.java b/src/IvyWatcher.java index b54a08f..98956ea 100755 --- a/src/IvyWatcher.java +++ b/src/IvyWatcher.java @@ -1,20 +1,12 @@ -package fr.dgac.ivy ; - -import java.lang.Thread; -import java.net.*; -import java.io.*; -import java.util.StringTokenizer; -import gnu.regexp.*; -import java.util.Vector; -import java.util.Enumeration; - /** - * A private Class for the Ivy rendezvous + * IvyWatcher, A private Class for the Ivy rendezvous * - * @author François-Régis Colin * @author Yannick Jestin + * @author François-Régis Colin * @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a> * + * (C) CENA + * * right now, the rendez vous is either an UDP socket or a TCP multicast. * The watcher will answer to * each peer advertising its arrival on the bus. The intrinsics of Unix are so @@ -23,9 +15,13 @@ import java.util.Enumeration; * * CHANGELOG: * 1.2.3: + * - the packet sending is done in its own thread from now on (PacketSender) + * I don't care stopping it, since it can't be blocked. * - checks whether I have been interrupted just after the receive (start() * then stop() immediately). * 1.2.1: + * - can be Interrupted during the broadcast Send. I catch the + * and do nothing with it. InterruptedIOException * - changed the fill character from 0 to 10, in order to prevent a nasty bug * on Windows XP machines * - fixed a NullPointerException while trying to stop a Thread before having @@ -41,6 +37,14 @@ import java.util.Enumeration; * - removed the timeout bug eating all the CPU resources * - now handles a Vector of broadcast listeners */ +package fr.dgac.ivy ; +import java.lang.Thread; +import java.net.*; +import java.io.*; +import java.util.StringTokenizer; +import gnu.regexp.*; +import java.util.Vector; +import java.util.Enumeration; class IvyWatcher implements Runnable { private static boolean debug = (System.getProperty("IVY_DEBUG")!=null); @@ -143,7 +147,7 @@ class IvyWatcher implements Runnable { /** * stops the thread waiting on the broadcast socket */ - void stop() { + synchronized void stop() { traceDebug("begining stopping an IvyWatcher"); Thread t = listenThread; listenThread=null; @@ -152,19 +156,37 @@ class IvyWatcher implements Runnable { traceDebug("ending stopping an IvyWatcher"); } - private void sendBroadcast(String data, String domain, int port) throws IvyException { - try { - DatagramPacket packet = new DatagramPacket( data.getBytes(), data.length(), group, port ); - broadcast.send(packet); - } catch ( IOException e ) { - throw new IvyException("Broadcast error " + e.getMessage() ); + private class PacketSender implements Runnable { + DatagramPacket packet; + String data; + public PacketSender(String data) { + this.data=data; + packet=new DatagramPacket(data.getBytes(),data.length(),group,port); + new Thread((PacketSender.this)).start(); + } + public void run() { + traceDebug("PacketSender thread started"); // THREADDEBUG + try { + broadcast.send(packet); + } catch (InterruptedIOException e) { + // somebody interrupts my IO. Thread, do nothing. + System.out.println(e.bytesTransferred+" bytes transferred anyway, out of " + data.length()); + e.printStackTrace(); + traceDebug("IO interrupted during the broadcast. Do nothing"); + } catch ( IOException e ) { + System.out.println("Broadcast Error" + e.getMessage()); + e.printStackTrace(); + // throw new IvyException("Broadcast error " + e.getMessage() ); + System.exit(0); + } + traceDebug("PacketSender thread stopped"); // THREADDEBUG } } - void start() throws IvyException { + synchronized void start() throws IvyException { String hello = bus.PROCOCOLVERSION + " " + bus.applicationPort + "\n"; listenThread.start(); - sendBroadcast(hello,domainaddr,port); // notifies our arrival on each domain: protocol version + port + new PacketSender(hello); // notifies our arrival on each domain: protocol version + port } /* diff --git a/src/Makefile b/src/Makefile index caaeb90..b53ba51 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,26 +1,54 @@ -# Be sure to set this before compiling ... - RTPATH = /usr/lib/j2re1.3/lib/rt.jar -RTPATH = /usr/local/j2sdk1.4.1/jre/lib/rt.jar -JIKESPATH = ${RTPATH}:/usr/share/java/gnu.getopt.jar:/usr/share/java/repository +####################################### +# jikes setup on my box +####################################### +# RTPATH = /usr/local/j2sdk1.4.1/jre/lib/rt.jar +#JAVACOPTS = -d . -deprecation +# JAVAC = jikes +#CLASSPATH = -classpath .:$(RTPATH) + +####################################### +# generic setup +####################################### + JAVAC = javac JAVACOPTS = -d . -deprecation +CLASSPATH = -classpath . + +####################################### +# blackdown jdk118 setup +####################################### +# JAVAC = /usr/local/jdk118_v3/bin/javac +#CLASSPATH = -classpath .:/usr/local/jdk118_v3/lib/classes.zip:/home/jestin/java/Jars/swingall.jar +#JAVACOPTS = -d . + +###################################### +# local Blackdown linux 1.2.2 +###################################### +#CLASSPATH = -classpath . +#JAVACOPTS = -deprecation -d . +# JAVAC = /usr/local/jdk1.2.2/bin/javac + +###################################### +# local Blackdown linux 1.3.1 +###################################### +#CLASSPATH = -classpath . +#JAVACOPTS = -deprecation -d . +# JAVAC = /usr/local/j2sdk1.3.1/bin/javac + .SUFFIXES: .java .class SRCS = *.java OBJS = $(SRCS:.java=.class) - #JAVAC = gcj-3.2 -classpath $(JIKESPATH) - JAVAC = jikes -classpath $(JIKESPATH) - #JAVAC = javac DOCS = ../doc/html/api .java.class: - $(JAVAC) $< + $(JAVAC) $(JAVACOPTS) $(CLASSPATH) $< ivy-java: - $(JAVAC) $(JAVACOPTS) $(SRCS) + $(JAVAC) $(JAVACOPTS) $(CLASSPATH) $(SRCS) all: $(OBJS) clean: - /bin/rm -f -- $(OBJS) *~ *.bak $(JAR) + /bin/rm -f -- $(OBJS) *~ *.bak $(JAR) fr/dgac/ivy/*.class docs: rm -fR $(DOCS)/*html |