aboutsummaryrefslogtreecommitdiff
path: root/src/Probe.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Probe.java')
-rw-r--r--src/Probe.java96
1 files changed, 80 insertions, 16 deletions
diff --git a/src/Probe.java b/src/Probe.java
index 7f5e7b5..ab40a11 100644
--- a/src/Probe.java
+++ b/src/Probe.java
@@ -7,6 +7,9 @@
* (c) CENA
*
* Changelog:
+ * 1.2.9
+ * - added the .time command
+ * - added the .bound *
* 1.2.8
* - added a fr.dgac.ivy.tools subsection
* 1.2.7
@@ -56,24 +59,54 @@ import org.apache.regexp.*;
public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBindListener, Runnable {
- public static final String helpCommands = "Available commands:\n.die CLIENT\t\t\t* sends a die message\n.dieall-yes-i-am-sure\t\t* sends a die to all clients\n.direct CLIENT ID MSG\t\t* sends the direct message to the client\n.bye\t\t\t\t* quits the probe\n.quit\t\t\t\t* quites the probe\n.list\t\t\t\t* lists the clients on the bus\n.bind REGEXP\t\t\t* subscribes to a regexp\n.unbind REGEXP\t\t\t* unsubscribes to a regexp\n.bound CLIENT\t\t\t* lists the subscriptions of a client\n.bound\t\t\t\t* lists the probe's subscriptions\n.where CLIENT\t\t\t* displays the host where a client runs";
+ public static final String helpCommands = "Available commands:\n"+
+ ".die CLIENT\t\t\t* sends a die message\n"+
+ ".dieall-yes-i-am-sure\t\t* sends a die to all clients\n"+
+ ".direct CLIENT ID MSG\t\t* sends the direct message to the client\n"+
+ ".bye\t\t\t\t* quits the probe\n"+
+ ".quit\t\t\t\t* quites the probe\n"+
+ ".list\t\t\t\t* lists the clients on the bus\n"+
+ ".bind REGEXP\t\t\t* subscribes to a regexp\n"+
+ ".unbind REGEXP\t\t\t* unsubscribes to a regexp\n"+
+ ".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"
+ ;
- 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-s\tsends to self\n\t-h\thelp\n\n\t regexp is a Perl5 compatible regular expression";
+ public static final String helpmsg =
+ "usage: java fr.dgac.ivy.Probe [options] [regexp]\n"+
+ "\t-b BUS\tspecifies the Ivy bus domain\n"+
+ "\t-c CLASS\tuses a message class CLASS=Word1,Word2,Word3...\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-s\tsends to self\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:dqsht");
+ Getopt opt = new Getopt("Probe",args,"n:b:c:dqsht");
int c;
boolean timestamp=false;
boolean quiet=false;
boolean sendsToSelf=false;
String domain=Ivy.getDomain(null);
String name="JPROBE";
+ String[] messageClass=null;
while ((c = opt.getopt()) != -1) switch (c) {
case 'd':
Properties sysProp = System.getProperties();
sysProp.put("IVY_DEBUG","yes");
break;
case 'b': domain=opt.getOptarg(); break;
+ case 'c':
+ java.util.StringTokenizer classTok = new java.util.StringTokenizer(opt.getOptarg(),",");
+ messageClass=new String[classTok.countTokens()];
+ System.out.println("YANNNN "+messageClass.length);
+ for (int i=0;classTok.hasMoreElements();) messageClass[i++]=new String((String)classTok.nextElement());
+ break;
case 'n': name=opt.getOptarg(); break;
case 'q': quiet=true; break;
case 't': timestamp=true; break;
@@ -86,6 +119,11 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
Ivy bus=new Ivy(name,name+" ready",null);
bus.addBindListener(p);
bus.sendToSelf(sendsToSelf);
+ if (messageClass!=null) {
+ System.out.println("using a message class filter of "+messageClass.length+" elements");
+ for (int i=0;i<messageClass.length;i++) System.out.println(messageClass[i]);
+ bus.setFilter(messageClass);
+ }
for (int i=opt.getOptind();i<args.length;i++) {
try {
bus.bindMsg(args[i],p);
@@ -103,21 +141,15 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
private volatile Thread looperThread;
private Ivy bus;
private boolean timestamp,quiet,debug,exitOnDie=false;
- private RE directMsgRE;
+ private static RE directMsgRE = new RE("^\\.direct ([^ ]*) ([0-9]+) (.*)");
+ private static RE timeCountRE = new RE("^\\.time (\\d+) (.*)");
public Probe(BufferedReader in, boolean timestamp,boolean quiet,boolean debug) {
this.in=in;
this.timestamp=timestamp;
this.quiet=quiet;
this.debug = debug;
- try {
- directMsgRE = new RE("^\\.direct ([^ ]*) ([0-9]+) (.*)");
- } catch (RESyntaxException ree) {
- System.err.println("Regexp fatal error in the Probe program.");
- ree.printStackTrace();
- System.exit(0);
- }
}
public void start(Ivy bus) throws IvyException {
@@ -131,10 +163,10 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
public void setExitOnDie(boolean b) { exitOnDie=b; }
public void run() {
- traceDebug("Thread started");
+ traceDebug("Probe Thread started");
Thread thisThread=Thread.currentThread();
String s;
- println("probe ready, type .help and return to get help");
+ println(bus.getSelfIvyClient().getApplicationName()+ " ready, type .help and return to get help");
// "infinite" loop on keyboard input
while (looperThread==thisThread) {
try {
@@ -190,16 +222,35 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
} else {
println("you can't unsubscribe to " + regexp + ", your're not subscribed to it");
}
+ } else if (s.lastIndexOf(".bound *")>=0){
+ Vector v=bus.getIvyClients();
+ int total=0;
+ int boundedtotal=0;
+ for (int i=0;i<v.size();i++) {
+ IvyClient ic=(IvyClient)v.elementAt(i);
+ for (Enumeration e = ic.getRegexps();e.hasMoreElements();) {
+ total++;
+ String r = (String)e.nextElement();
+ if (r.startsWith("^")) boundedtotal++;
+ println(ic.getApplicationName()+" has subscribed to: "+r);
+ }
+ System.out.println("total: "+total+", unbounded:"+(total-boundedtotal));
+ }
} else if (s.lastIndexOf(".bound ")>=0){
+ int total=0;
+ int boundedtotal=0;
String target=s.substring(7);
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++) {
IvyClient ic=(IvyClient)v.elementAt(i);
- println(target+" has subscribed to:");
for (Enumeration e = ic.getRegexps();e.hasMoreElements();) {
- println("\t"+(String)e.nextElement());
+ total++;
+ String r = (String)e.nextElement();
+ if (r.startsWith("^")) boundedtotal++;
+ println(target+" has subscribed to: "+(String)e.nextElement());
}
+ System.out.println("total: "+total+", unbounded:"+(total-boundedtotal));
}
} else if (s.lastIndexOf(".bound")>=0){
println("you have subscribed to:");
@@ -230,6 +281,17 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
for (int i=0;i<v.size();i++) {
println(target+" runs on "+((IvyClient)v.elementAt(i)).getHostName());
}
+ } else if (timeCountRE.match(s)) {
+ long before = new java.util.Date().getTime();
+ int times=Integer.parseInt(timeCountRE.getParen(1));
+ try {
+ int n=0;
+ for (int i=0;i<times;i++) n=bus.sendMsg(timeCountRE.getParen(2));
+ long after = new java.util.Date().getTime();
+ println("-> it took "+(after-before)+"ms to send "+times+" to " +n+" peers");
+ } catch (IvyException ie) {
+ println("-> not sent, the line contains incorrect characters");
+ }
} else if ( s.lastIndexOf(".help")>=0) {
println(helpCommands);
} else if ( s.charAt(0)=='.') {
@@ -245,7 +307,9 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
} // parseCommand
public void bindPerformed(IvyClient client,int id,String re) {
- println(client.getApplicationName() + " subscribes to " +re );
+ String s="";
+ if (!bus.CheckRegexp(re)) s=" WITH NO EFFECT";
+ println(client.getApplicationName() + " subscribes to " +re+s);
}
public void unbindPerformed(IvyClient client,int id,String re) {