package fr.dgac.ivy ; import java.io.*; 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.10 * Should exit on end of user input * Should handle multiple domains - it was a IvyWatcher problem - */ class Probe implements IvyApplicationListener, IvyMessageListener { /** * help message for the standalone program */ public static final String helpmsg = "usage: java fr.dgac.ivy.Probe [options] [regexp]\n\t-b BUS\tspecifies the Ivy bus domain\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 void main(String[] args) throws IvyException { Getopt opt = new Getopt("Probe",args,"b:dh"); int c; String domain=Ivy.getDomain(null); while ((c = opt.getopt()) != -1) switch (c) { case 'b': domain=opt.getOptarg(); break; case 'd': System.setProperty("IVY_DEBUG","yes"); break; case 'h': default: System.out.println(helpmsg); System.exit(0); } // getopt Probe p = new Probe(); Ivy bus=new Ivy("JPROBE","JPROBE ready",p); try { for (int i=opt.getOptind();i Sent to " +bus.sendMsg(s)+" peers"); } } } catch (NullPointerException e) { // EOF triggered by a ^D, for instance bus.stop(); } catch (IOException e) { System.out.println("ioe ?"); e.printStackTrace(); bus.stop(); } } catch (IvyException ie) { System.out.println("Caught an exception. quitting. "+ie.getMessage()); } System.exit(0); // quit ! } private boolean looping=true; public boolean looping() { return looping ; } // accessor public void connect(IvyClient client) { System.out.println(client.getApplicationName() + " connected " ); for (java.util.Enumeration e=client.getRegexps();e.hasMoreElements();) System.out.println(client.getApplicationName() + " subscribes to " +e.nextElement() ); } public void disconnect(IvyClient client) { System.out.println(client.getApplicationName() + " disconnected " ); } public void die(IvyClient client, int id) { looping=false; System.out.println("received die msg from " + client.getApplicationName() ); System.exit(0); } public void directMessage(IvyClient client, int id, String arg) { System.out.println(client.getApplicationName() + " direct Message "+ id + arg ); } public void receive(IvyClient client, String[] args) { String s=client.getApplicationName() + " sent"; for (int i=0;i