diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/After.java | 8 | ||||
-rwxr-xr-x | src/IvyClient.java | 32 | ||||
-rw-r--r-- | src/Makefile | 8 |
3 files changed, 31 insertions, 17 deletions
diff --git a/src/After.java b/src/After.java index fa43cf9..b36d5de 100644 --- a/src/After.java +++ b/src/After.java @@ -26,10 +26,10 @@ public class After extends IvyApplicationAdapter implements IvyMessageListener { String name="AFTER"; int timeout = DEFAULTTIMEOUT; while ((c = opt.getopt()) != -1) switch (c) { - case 'b': domain=opt.getOptarg(); break; - case 't': timeout=Integer.parseInt(opt.getOptarg()); break; - case 'h': - default: System.out.println(helpmsg); System.exit(0); + case 'b': domain=opt.getOptarg(); break; + case 't': timeout=Integer.parseInt(opt.getOptarg()); break; + case 'h': + default: System.out.println(helpmsg); System.exit(0); } if (opt.getOptind()!=args.length-1) { System.out.println(helpmsg); System.exit(0); } String regexp=args[opt.getOptind()]; diff --git a/src/IvyClient.java b/src/IvyClient.java index b0c1200..af42342 100755 --- a/src/IvyClient.java +++ b/src/IvyClient.java @@ -103,10 +103,11 @@ public class IvyClient implements Runnable { final static char newLineChar = '\n'; // private variables + private final static int MAXPONGCALLBACKS = 10; private static int pingSerial = 0; private static Integer csMutex=new Integer(0); private static int clientSerial=0; /* an unique ID for each IvyClient */ - private Stack PCHStack = new Stack(); + private Hashtable PingCallbacksTable = new Hashtable(); private String messages_classes[] = null; private Ivy bus; @@ -246,7 +247,7 @@ public class IvyClient implements Runnable { * received */ public void ping(PingCallback pc) throws IvyException { - PCHStack.push(new PingCallbackHolder(pc)); + PCHadd(pingSerial,pc); sendString(Ping,pingSerial++,""); } @@ -488,7 +489,7 @@ public class IvyClient implements Runnable { } break; case Pong: - ((PingCallbackHolder)PCHStack.pop()).run(); + PCHget(msgId); break; case Ping: sendString(Pong,msgId.intValue(),""); @@ -591,16 +592,37 @@ public class IvyClient implements Runnable { traceDebug(s); } + void PCHadd(int serial,PingCallback pc) { + PingCallbacksTable.put(new Integer(serial),new PingCallbackHolder(pc)); + if (PingCallbacksTable.size()>MAXPONGCALLBACKS) { + // more than MAXPONGCALLBACKS callbacks, we ought to limit to prevent a + // memory leak + // TODO remove the first + Integer smallest=(Integer)new TreeSet(PingCallbacksTable.keySet()).first(); + PingCallbackHolder pch = (PingCallbackHolder)PingCallbacksTable.remove(smallest); + System.err.println("no response from "+getApplicationName()+" to ping "+smallest+" after "+pch.age()+" ms, discarding"); + } + } + + void PCHget(Integer serial) { + PingCallbackHolder pc = (PingCallbackHolder)PingCallbacksTable.remove(serial); + if (pc==null) { + System.err.println("warning: pong received for a long lost callback"); + return; + } + pc.run(); + } + private class PingCallbackHolder { PingCallback pc; long epoch; + int age() { return (int)(System.currentTimeMillis()-epoch); } PingCallbackHolder(PingCallback pc) { this.pc=pc; epoch=System.currentTimeMillis(); - PCHStack.push(this); } void run() { - pc.pongReceived(IvyClient.this,(int)(System.currentTimeMillis()-epoch)); + pc.pongReceived(IvyClient.this,age()); } } diff --git a/src/Makefile b/src/Makefile index 1d89856..2d33d08 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,14 +8,6 @@ include ../java.mk OBJS = $(SRCS:.java=.class) DOCS = ../doc/html/api - GNUPATH = /usr/share/java/gnu-getopt.jar:/usr/share/java/regexp.jar # debian SID - #GNUPATH = ../bundle # on my MAC -#GNUPATH = /usr/lib/jdk1.1/lib/classes.zip:/usr/share/java/gnu.getopt.jar:/usr/share/java/regexp.jar # debian woody -#GNUPATH = ${HOME}/java/Jars/gnu.getopt.jar:${HOME}/java/Jars/regexp.jar # Others -#RTPATH = /usr/local/jdk1.5.0/jre/lib/rt.jar # for jikes on my box -#RTPATH = /usr/local/jdk118_v3/lib/classes.zip:/home/jestin/java/Jars/swingall.jar # for 1.1.8 on my box - -CLASSPATH = -classpath .:$(GNUPATH) #ivy-java: # $(JAVAC) $(JAVACOPTS) $(CLASSPATH) $(SRCS) |