aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjestin2006-07-24 13:33:15 +0000
committerjestin2006-07-24 13:33:15 +0000
commitf0ca4915ee9eec18d05c60e3cf0248b50fab7310 (patch)
tree94697724e5fffa4aef5eefc3a98db5276f7e5d95
parent0f83d1bab49eb913cc8be048ec7884a9a2e3402e (diff)
downloadivy-java-f0ca4915ee9eec18d05c60e3cf0248b50fab7310.zip
ivy-java-f0ca4915ee9eec18d05c60e3cf0248b50fab7310.tar.gz
ivy-java-f0ca4915ee9eec18d05c60e3cf0248b50fab7310.tar.bz2
ivy-java-f0ca4915ee9eec18d05c60e3cf0248b50fab7310.tar.xz
adding ping and pong
-rw-r--r--Makefile4
-rw-r--r--debian/changelog6
-rw-r--r--doc/ivy-java.sgml21
-rw-r--r--doc/jprobe.12
-rwxr-xr-xsrc/Ivy.java2
-rwxr-xr-xsrc/IvyClient.java34
-rw-r--r--src/Makefile2
-rw-r--r--src/PingCallback.java20
-rw-r--r--src/Probe.java20
9 files changed, 105 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 59e416c..09f5ee4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
include java.mk
# Be sure to set this before compiling ...
- VERSION = 1.2.11
+ VERSION = 1.2.12
DIST = ivy-$(VERSION).jar
DOCS = doc/html/api
#dist = woody/
@@ -27,7 +27,7 @@ tests:
dist: class
(cd src && $(JAR) cvfm ../$(DIST) ../manifest fr/dgac/ivy/*.class fr/dgac/ivy/tools/*.class )
-jar: class
+#jar: class
#ln -sf src/fr .
#ln -sf bundle/${dist}gnu .
#ln -sf bundle/${dist}org .
diff --git a/debian/changelog b/debian/changelog
index 2c6533a..47f1108 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+libivy-java (1.2.12) unstable; urgency=low
+
+ * (re)introducing Ping and Pong in the protocol and in IvyClient api
+
+ -- Yannick Jestin <yannick.jestin@enac.fr> Mon, 24 Jul 2006 15:32:34 +0200
+
libivy-java (1.2.11) unstable; urgency=low
* major documentation update ( programmers's guide )
diff --git a/doc/ivy-java.sgml b/doc/ivy-java.sgml
index 92fe115..0e4d233 100644
--- a/doc/ivy-java.sgml
+++ b/doc/ivy-java.sgml
@@ -38,7 +38,7 @@
<para>
This document is a programmer's guide that describes how to use the Ivy
Java library to connect applications to an Ivy bus. This guide describes
-version 1.2.10 of the library. This document itself is part of the Java
+version 1.2.12 of the library. This document itself is part of the Java
package, available on the <ulink
url="http://www.tls.cena.fr/products/ivy/">Ivy web site</ulink>.
</para>
@@ -558,6 +558,23 @@ chance to match the message you're sending, use the
</para>
</sect2>
+<sect2><title>Monitoring the bus</title>
+<para>
+When in doubt, to check if the remote client is still responding, instead of
+relying on a callback, you can test the response of the protocol parsing
+thread. Use following method:
+<programlisting>
+Ivyclient.ping(PingCallback pc);
+</programlisting>
+It will send a ping token that will (hopefully) be parsed by the remote agent,
+and will trigger the following message with the elapsed time in milliseconds:
+<programlisting>
+void PingCallback.pongReceived(IvyClient ic,int elapsedTime);
+</programlisting>
+An example is provided in fr.dgac.ivy.tools.Probe.
+</para>
+</sect2>
+
<sect2><title>Message classes</title>
<para>
When your Ivy bus is populated with many agents, the cost of pattern matching
@@ -683,6 +700,8 @@ the numeric id
<listitem><para>
.time COUNT MSG sends the MSG COUNT times and displays the elapsed time
</para></listitem>
+<listitem><para>
+.ping CLIENT measures the time it takes to reach a client
</itemizedlist>
</para>
</sect2>
diff --git a/doc/jprobe.1 b/doc/jprobe.1
index e4d8da0..e5a3d2d 100644
--- a/doc/jprobe.1
+++ b/doc/jprobe.1
@@ -69,6 +69,8 @@ issue a command to jprobe, use one of the following commands:
\.where CLIENT displays the host where a client runs
.nf
\.time COUNT MESSAGE measures the time it takes to send COUNT messages
+.nf
+ \.ping CLIENT measures the roundrip time in milliseconds to a client
.SH "EXAMPLES"
.nf
diff --git a/src/Ivy.java b/src/Ivy.java
index 7e14619..7d26dff 100755
--- a/src/Ivy.java
+++ b/src/Ivy.java
@@ -112,7 +112,7 @@ public class Ivy implements Runnable {
* the library version, useful for development purposes only, when java is
* invoked with -DIVY_DEBUG
*/
- public static final String libVersion ="1.2.11";
+ public static final String libVersion ="1.2.12";
private boolean debug;
private ServerSocket app;
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));
+ }
+ }
+
}
diff --git a/src/Makefile b/src/Makefile
index ecf9e33..1d89856 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,7 +2,7 @@ include ../java.mk
#.SUFFIXES: .java .class
#SRCS = *.java
- SRCS = IvyApplicationAdapter.java IvyApplicationListener.java IvyBindListener.java IvyClient.java IvyException.java Ivy.java IvyMessageListener.java IvyWatcher.java SelfIvyClient.java WaiterClient.java Waiter.java
+ SRCS = IvyApplicationAdapter.java IvyApplicationListener.java IvyBindListener.java IvyClient.java IvyException.java Ivy.java IvyMessageListener.java IvyWatcher.java SelfIvyClient.java WaiterClient.java Waiter.java PingCallback.java
TOOLS= IvyDaemon.java Probe.java After.java
OBJS = $(SRCS:.java=.class)
diff --git a/src/PingCallback.java b/src/PingCallback.java
new file mode 100644
index 0000000..ff3233b
--- /dev/null
+++ b/src/PingCallback.java
@@ -0,0 +1,20 @@
+package fr.dgac.ivy;
+
+/**
+ * this interface specifies the methods of an PingCallback
+ *
+ * @author Yannick Jestin
+ * @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
+ *
+ * Changelog:
+ * 1.2.12
+ */
+
+public interface PingCallback {
+ /**
+ * invoked when a Pong is received
+ * @param elapsedTime the elapsed time in milliseconds between the ping and
+ * the pong
+ */
+ void pongReceived(IvyClient ic,int elapsedTime);
+}
diff --git a/src/Probe.java b/src/Probe.java
index 0d3eed7..8ced8e5 100644
--- a/src/Probe.java
+++ b/src/Probe.java
@@ -7,6 +7,8 @@
* (c) CENA
*
* Changelog:
+ * 1.2.12
+ * - .ping is back
* 1.2.9
* - added the .time command
* - added the .bound *
@@ -71,7 +73,8 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
".bound CLIENT\t\t\t* lists the subscriptions of a client, .bound * to get all\n"+
".bound\t\t\t\t* lists the probe's subscriptions\n"+
".where CLIENT\t\t\t* displays the host where a client runs\n"+
- ".time COUNT MESSAGE\t\t\t* measures the time it takes to send COUNT messages\n"
+ ".time COUNT MESSAGE\t\t\t* measures the time it takes to send COUNT messages\n"+
+ ".ping CLIENT\t\t\t* measures the roundtrip time in millisecond to reach a client\n"
;
public static final String helpmsg =
@@ -274,6 +277,21 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
for (int i=0;i<v.size();i++) {
println("-> "+((IvyClient)v.elementAt(i)).getApplicationName());
}
+ } else if ( s.lastIndexOf(".ping ")>=0) {
+ String target=s.substring(6);
+ Vector v=bus.getIvyClientsByName(target);
+ if (v.size()==0) println("no Ivy client with the name \""+target+"\"");
+ for (int i=0;i<v.size();i++) {
+ try {
+ ((IvyClient)v.elementAt(i)).ping(new PingCallback() {
+ public void pongReceived(IvyClient ic,int elapsedTime){
+ System.out.println("round trip to"+ic.getApplicationName()+" "+elapsedTime+" ms");
+ }
+ });
+ } catch (IvyException ie) {
+ println("-> ping not sent, the remote client must have disconnected");
+ }
+ }
} else if ( s.lastIndexOf(".where ")>=0) {
String target=s.substring(7);
Vector v=bus.getIvyClientsByName(target);