From 55f376e0acf3a6dea0da68f480c945afa7952abb Mon Sep 17 00:00:00 2001
From: jestin
Date: Fri, 27 Sep 2002 17:26:26 +0000
Subject: see TODO for details. Mostly bugfixes.
---
src/Probe.java | 57 ++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 44 insertions(+), 13 deletions(-)
(limited to 'src/Probe.java')
diff --git a/src/Probe.java b/src/Probe.java
index a0a2ed0..c72c2ad 100644
--- a/src/Probe.java
+++ b/src/Probe.java
@@ -5,14 +5,16 @@ import gnu.getopt.Getopt;
/**
* terminal implementation in java of the ivyprobe.
- * For a graphical version, see TestIvySwing
- * @see fr.dgac.ivy.TestIvySwing
* @author Yannick Jestin
* @author http://www.tls.cena.fr/products/ivy/
*
*
* Changelog:
- * 1.0.12
+ * 1.2.1
+ * - new -t switch to print the date for each ivy message
+ * - now displays the correct domain list
+ * - now has .bind and .unbind commands
+ * 1.2.0
* - Probe can now send empty strings on keyboard input
* - rewritten with a looping thread on stdin to allow a cleaner exit on die
* message : not very good
@@ -29,12 +31,13 @@ class Probe implements IvyApplicationListener, IvyMessageListener, Runnable {
/**
* help message for the standalone program
*/
- public static final String helpCommands = "Available commands:\n.die CLIENTNAME sends a die message\n.bye quits the application\n.quit idem\n.list lists the available clients\n.ping sends a ping request if IVY_PING is enabled";
- public static final String helpmsg = "usage: java fr.dgac.ivy.Probe [options] [regexp]\n\t-b BUS\tspecifies the Ivy bus domain\n\t-n ivyname (default JPROBE)\n\t-q\tquiet, no tty output\n\t-d\tdebug\n\t-h\thelp\n\n\t regexp is a Perl5 compatible regular expression";
+ public static final String helpCommands = "Available commands:\n.die CLIENTNAME sends a die message\n.bye quits the application\n.quit idem\n.list lists the available clients\n.ping sends a ping request if IVY_PING is enabled\n.bind REGEXP binds to a regexp at runtime\n.unbind REGEXP unbinds to a regexp at runtime";
+ public static final String helpmsg = "usage: java fr.dgac.ivy.Probe [options] [regexp]\n\t-b BUS\tspecifies the Ivy bus domain\n\t-n ivyname (default JPROBE)\n\t-q\tquiet, no tty output\n\t-d\tdebug\n\t-t\ttime stamp each message\n\t-h\thelp\n\n\t regexp is a Perl5 compatible regular expression";
public static void main(String[] args) throws IvyException {
- Getopt opt = new Getopt("Probe",args,"n:b:dh");
+ Getopt opt = new Getopt("Probe",args,"n:b:dht");
int c;
+ boolean timestamp=false;
String domain=Ivy.getDomain(null);
String name="JPROBE";
while ((c = opt.getopt()) != -1) switch (c) {
@@ -44,6 +47,9 @@ class Probe implements IvyApplicationListener, IvyMessageListener, Runnable {
case 'n':
name=opt.getOptarg();
break;
+ case 't':
+ timestamp=true;
+ break;
case 'd':
System.setProperty("IVY_DEBUG","yes");
break;
@@ -52,13 +58,18 @@ class Probe implements IvyApplicationListener, IvyMessageListener, Runnable {
System.out.println(helpmsg);
System.exit(0);
} // getopt
- Probe p = new Probe();
+ Probe p = new Probe(timestamp);
Ivy bus=new Ivy(name,name+" ready",p);
for (int i=opt.getOptind();i Sent to " +bus.sendMsg(s)+" peers");
+ System.out.println(date()+"-> Sent to " +bus.sendMsg(s)+" peers");
} else if (s.lastIndexOf(".die ")>=0){
String target=s.substring(5);
Vector v=bus.getIvyClientsByName(target);
@@ -115,6 +128,17 @@ class Probe implements IvyApplicationListener, IvyMessageListener, Runnable {
for (int i=0;i=0){
+ String regexp=s.substring(8);
+ if (bus.unBindMsg(regexp)) {
+ System.out.println("you want to unsubscribe to " + regexp);
+ } else {
+ System.out.println("you can't unsubscribe to " + regexp + ", your're not subscribed to it");
+ }
+ } else if (s.lastIndexOf(".bind ")>=0){
+ String regexp=s.substring(6);
+ System.out.println("you want to subscribe to " + regexp);
+ bus.bindMsg(regexp,this);
} else if (s.lastIndexOf(".ping ")>=0){
String target=s.substring(6);
Vector v=bus.getIvyClientsByName(target);
@@ -131,7 +155,7 @@ class Probe implements IvyApplicationListener, IvyMessageListener, Runnable {
Vector v = bus.getIvyClients();
System.out.println(v.size()+" clients on the bus");
for (int i=0;i "+((IvyClient)v.elementAt(i)).getApplicationName());
+ System.out.println("-> "+((IvyClient)v.elementAt(i)).getApplicationName());
}
} else if ( s.lastIndexOf(".help")>=0) {
System.out.println(helpCommands);
@@ -139,7 +163,7 @@ class Probe implements IvyApplicationListener, IvyMessageListener, Runnable {
System.out.println("this command is not recognized");
System.out.println(helpCommands);
} else {
- System.out.println("-> Sent to " +bus.sendMsg(s)+" peers");
+ System.out.println(date()+"-> Sent to " +bus.sendMsg(s)+" peers");
}
} // parseCommand
@@ -167,9 +191,16 @@ class Probe implements IvyApplicationListener, IvyMessageListener, Runnable {
}
public void receive(IvyClient client, String[] args) {
- String s=client.getApplicationName() + " sent";
+ String s=date()+client.getApplicationName() + " sent";
for (int i=0;i