diff options
author | jestin | 2006-07-24 13:33:15 +0000 |
---|---|---|
committer | jestin | 2006-07-24 13:33:15 +0000 |
commit | f0ca4915ee9eec18d05c60e3cf0248b50fab7310 (patch) | |
tree | 94697724e5fffa4aef5eefc3a98db5276f7e5d95 /src/IvyClient.java | |
parent | 0f83d1bab49eb913cc8be048ec7884a9a2e3402e (diff) | |
download | ivy-java-f0ca4915ee9eec18d05c60e3cf0248b50fab7310.zip ivy-java-f0ca4915ee9eec18d05c60e3cf0248b50fab7310.tar.gz ivy-java-f0ca4915ee9eec18d05c60e3cf0248b50fab7310.tar.bz2 ivy-java-f0ca4915ee9eec18d05c60e3cf0248b50fab7310.tar.xz |
adding ping and pong
Diffstat (limited to 'src/IvyClient.java')
-rwxr-xr-x | src/IvyClient.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/IvyClient.java b/src/IvyClient.java index 85edfc8..5e71ccb 100755 --- a/src/IvyClient.java +++ b/src/IvyClient.java @@ -10,6 +10,8 @@ * created for each remote client. * * CHANGELOG: + * 1.2.12 + * - Ping and Pong are back ... * 1.2.8 * - no CheckRegexp anymore * - synchronized(regexps) pour le match et le getParen(): @@ -90,6 +92,8 @@ public class IvyClient implements Runnable { final static int SchizoToken = 6; /* avoid race condition in concurrent connexions, aka BeginRegexp in other implementations */ final static int DirectMsg = 7;/* the peer sends a direct message */ final static int Die = 8; /* the peer wants us to quit */ + final static int Ping = 9; // from outer space + final static int Pong = 10; final static String MESSAGE_TERMINATOR = "\n"; /* the next protocol will use \r */ final static String StartArg = "\u0002";/* begin of arguments */ final static String EndArg = "\u0003"; /* end of arguments */ @@ -101,6 +105,7 @@ public class IvyClient implements Runnable { // private variables private static Integer csMutex=new Integer(0); private static int clientSerial=0; /* an unique ID for each IvyClient */ + private Stack PCHStack = new Stack(); private String messages_classes[] = null; private Ivy bus; @@ -234,6 +239,16 @@ public class IvyClient implements Runnable { sendString(Die,0,message); } + /** + * triggers a Ping, and executes the callback + * @param pc the callback that will be triggerred (once) when the ponc is + * received + */ + public void ping(PingCallback pc) throws IvyException { + PCHStack.push(new PingCallbackHolder(pc)); + sendString(Ping,0,""); + } + /////////////////////////////////////////////////// // // PROTECTED METHODS @@ -471,6 +486,12 @@ public class IvyClient implements Runnable { throw new IvyException(ioe.getMessage()); } break; + case Pong: + ((PingCallbackHolder)PCHStack.pop()).run(); + break; + case Ping: + sendString(Pong,0,""); + break; case AddRegexp: String regexp=s.substring(from,b.length); if ( bus.CheckRegexp(regexp) ) { @@ -569,4 +590,17 @@ public class IvyClient implements Runnable { traceDebug(s); } + private class PingCallbackHolder { + PingCallback pc; + long epoch; + PingCallbackHolder(PingCallback pc) { + this.pc=pc; + epoch=System.currentTimeMillis(); + PCHStack.push(this); + } + void run() { + pc.pongReceived(IvyClient.this,(int)(System.currentTimeMillis()-epoch)); + } + } + } |