From 750f33265d208df8218f85359e3f027900c58363 Mon Sep 17 00:00:00 2001 From: jestin Date: Fri, 22 Jul 2011 16:49:57 +0000 Subject: Passage en 1.2.14 --- src/Probe.java | 125 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 65 insertions(+), 60 deletions(-) (limited to 'src/Probe.java') diff --git a/src/Probe.java b/src/Probe.java index c3f05c2..4425dd4 100644 --- a/src/Probe.java +++ b/src/Probe.java @@ -7,8 +7,12 @@ * (c) CENA * * Changelog: + * 1.2.14 + * - uses the "new" for: loop construct of Java5 + * - throws RuntimeException instead of System.exit(), allows code reuse + * - switch from gnu regexp (deprecated) to the built in java regexp * 1.2.13 - * - adds support for RESyntaxException + * - adds support for RESyntaxException * 1.2.12 * - .ping is back * 1.2.9 @@ -59,7 +63,7 @@ import fr.dgac.ivy.* ; import java.io.*; import java.util.*; import gnu.getopt.Getopt; -import org.apache.regexp.*; +import java.util.regex.*; public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBindListener, Runnable { @@ -110,14 +114,15 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin 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()); + for (int i=0;classTok.hasMoreElements();) + messageClass[i++] = classTok.nextToken(); break; case 'n': name=opt.getOptarg(); break; case 'q': quiet=true; break; case 't': timestamp=true; break; case 's': sendsToSelf=true; break; case 'h': - default: System.out.println(helpmsg); System.exit(0); + default: System.out.println(helpmsg); return; } Probe p = new Probe(new BufferedReader(new InputStreamReader(System.in)),timestamp,quiet,System.getProperty("IVY_DEBUG")!=null); p.setExitOnDie(true); @@ -126,7 +131,7 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin bus.sendToSelf(sendsToSelf); if (messageClass!=null) { System.out.println("using a message class filter of "+messageClass.length+" elements"); - for (int i=0;i Sent to " +bus.sendMsg(s)+" peers"); } catch (IvyException ie) { println("-> not sent, the message contains incorrect characters"); } - } else if (directMsgRE.match(s)) { - String target = directMsgRE.getParen(1); - int id = Integer.parseInt(directMsgRE.getParen(2)); - String message = directMsgRE.getParen(3); - Vector v=bus.getIvyClientsByName(target); + } else if (m.matches()) { + String target = m.group(1); + int id = Integer.parseInt(m.group(2)); + String message = m.group(3); + Vectorv=bus.getIvyClientsByName(target); if (v.size()==0) println("no Ivy client with the name \""+target+"\""); try { - for (int i=0;i not sent, the message contains incorrect characters"); } - return; } else if (s.lastIndexOf(".dieall-yes-i-am-sure")>=0){ - Vector v=bus.getIvyClients(); - for (int i=0;iv=bus.getIvyClients(); + for (IvyClient ic: v) ic.sendDie("java probe wants you to leave the bus"); } else if (s.lastIndexOf(".die ")>=0){ String target=s.substring(5); - Vector v=bus.getIvyClientsByName(target); + Vectorv=bus.getIvyClientsByName(target); if (v.size()==0) println("no Ivy client with the name \""+target+"\""); - for (int i=0;i=0){ String regexp=s.substring(8); if (bus.unBindMsg(regexp)) { @@ -238,14 +243,13 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin println("you can't unsubscribe to " + regexp + ", your're not subscribed to it"); } } else if (s.lastIndexOf(".bound *")>=0){ - Vector v=bus.getIvyClients(); + Vectorv=bus.getIvyClients(); int total=0; int boundedtotal=0; - for (int i=0;i e = ic.getRegexps();e.hasMoreElements();) { total++; - String r = (String)e.nextElement(); + String r = e.nextElement(); if (r.startsWith("^")) boundedtotal++; println(ic.getApplicationName()+" has subscribed to: "+r); } @@ -255,13 +259,12 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin int total=0; int boundedtotal=0; String target=s.substring(7); - Vector v=bus.getIvyClientsByName(target); + Vectorv=bus.getIvyClientsByName(target); if (v.size()==0) println("no Ivy client with the name \""+target+"\""); - for (int i=0;i e = ic.getRegexps();e.hasMoreElements();) { total++; - String r = (String)e.nextElement(); + String r = e.nextElement(); if (r.startsWith("^")) boundedtotal++; println(target+" has subscribed to: "+(String)e.nextElement()); } @@ -269,8 +272,8 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin } } else if (s.lastIndexOf(".bound")>=0){ println("you have subscribed to:"); - for (Enumeration e = bus.getSelfIvyClient().getRegexps();e.hasMoreElements();) { - println("\t"+(String)e.nextElement()); + for (Enumeration e = bus.getSelfIvyClient().getRegexps();e.hasMoreElements();) { + println("\t"+e.nextElement()); } } else if (s.lastIndexOf(".bind ")>=0){ String regexp=s.substring(6); @@ -282,20 +285,18 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin } } else if ( (s.lastIndexOf(".quit")>=0)||(s.lastIndexOf(".bye")>=0)){ bus.stop(); - System.exit(0); + return false; } else if (s.lastIndexOf(".list")>=0) { - Vector v = bus.getIvyClients(); + Vector v = bus.getIvyClients(); println(v.size()+" clients on the bus"); - for (int i=0;i "+((IvyClient)v.elementAt(i)).getApplicationName()); - } + for (IvyClient ic: v) println("-> "+ic.getApplicationName()); } else if ( s.lastIndexOf(".ping ")>=0) { String target=s.substring(6); - Vector v=bus.getIvyClientsByName(target); + Vectorv=bus.getIvyClientsByName(target); if (v.size()==0) println("no Ivy client with the name \""+target+"\""); - for (int i=0;i=0) { String target=s.substring(7); - Vector v=bus.getIvyClientsByName(target); + Vectorv=bus.getIvyClientsByName(target); if (v.size()==0) println("no Ivy client with the name \""+target+"\""); - for (int i=0;i it took "+(after-before)+"ms to send "+times+" to " +n+" peers"); } catch (IvyException ie) { @@ -334,11 +333,12 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin println("-> not sent, the line contains incorrect characters"); } } + return true; } // parseCommand public void bindPerformed(IvyClient client,int id,String re) { String s=""; - if (!bus.CheckRegexp(re)) s=" WITH NO EFFECT"; + if (!bus.checkRegexp(re)) s=" WITH NO EFFECT, because of the filters"; println(client.getApplicationName() + " subscribes to " +re+s); } @@ -358,7 +358,7 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin public void die(IvyClient client, int id,String msgarg) { println("received die msg from " + client.getApplicationName() +" with the message: "+msgarg+", good bye"); - /* I cannot stop the readLine(), because it is native code */ + /* I cannot stop the readLine(), because it is native code ?! */ if (exitOnDie) System.exit(0); } @@ -367,9 +367,14 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin } public void receive(IvyClient client, String[] args) { - String s=client.getApplicationName() + " sent"; - for (int i=0;iProbe<-- "+s); } -- cgit v1.1