diff options
author | jestin | 2002-03-06 12:56:54 +0000 |
---|---|---|
committer | jestin | 2002-03-06 12:56:54 +0000 |
commit | cb0e14bbd6882bed96642628ddc5e6d9c6c8baa4 (patch) | |
tree | fc48c04882b586400610f832d759279f8cad007d /src/Counter.java | |
parent | bdc113909fc711ce7c411d04a1f63c86d1b6c0d0 (diff) | |
download | ivy-java-cb0e14bbd6882bed96642628ddc5e6d9c6c8baa4.zip ivy-java-cb0e14bbd6882bed96642628ddc5e6d9c6c8baa4.tar.gz ivy-java-cb0e14bbd6882bed96642628ddc5e6d9c6c8baa4.tar.bz2 ivy-java-cb0e14bbd6882bed96642628ddc5e6d9c6c8baa4.tar.xz |
Counter counts an approximative number of messages going on the bus,
think xload, but for ivy messages. 1 second, 10 seconds, 1 minute
Diffstat (limited to 'src/Counter.java')
-rw-r--r-- | src/Counter.java | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/Counter.java b/src/Counter.java new file mode 100644 index 0000000..7e355db --- /dev/null +++ b/src/Counter.java @@ -0,0 +1,98 @@ +/** + * a software bus package geiger counter + * + * @author Yannick Jestin + * @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a> + * + */ +package fr.dgac.ivy ; + +import fr.dgac.ivy.* ; +import gnu.getopt.Getopt ; + + +/** + * A program to count to the Ivy software bus messages. + * The class itself can be used to collect data and send them on the terminal + * or on the bus. + */ +public class Counter implements IvyMessageListener, Runnable { + + private Ivy bus ; + private int[] secCount = new int[60]; + private int totalminute=0; + private int totaldix=0; + private int counter=0; + private int moindix=secCount.length-10; + private int moinune=1; + private Thread thread; + boolean isRunning=false; + boolean quiet=false; + + public static final String helpmsg = "usage: java Counter -[options]\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"; + + public Counter(String domain,boolean quiet) { + this.quiet=quiet; + for (int j=0;j<secCount.length;j++) {secCount[j]=0;} + bus = new Ivy("Counter","Counter ready",null); + bus.bindMsg(".*",this); + bus.bindMsg("^EXHAUSTED$",new IvyMessageListener(){ + public void receive(IvyClient client,String[] args) { + isRunning=false; + } + }); + thread = new Thread(this); + isRunning=true; + thread.start(); + try { + bus.start(domain); + } catch (IvyException ie) { + ie.printStackTrace(); + } + } + + // implements the Runnable interface + public void run() { + while (isRunning) { + try { + thread.sleep(1000); + } catch (InterruptedException ie) { + } + totalminute+=secCount[counter]-secCount[moinune]; + totaldix+=secCount[counter]-secCount[moindix]; + String s = "MessageCount "+ secCount[counter]+" "+totaldix+" "+totalminute; + if (!quiet) { System.out.println(s); } + bus.sendMsg(s); + moinune=(moinune+1)%secCount.length; + moindix=(moindix+1)%secCount.length; + counter=(counter+1)%secCount.length; + secCount[counter]=0; + } + } + + public void receive(IvyClient client,String[] args) { secCount[counter]++; } + + public static void main(String[] args) { + String domain="127.255.255.255:2010"; + Getopt opt = new Getopt("Counter",args,"b:dhq"); + int c; + boolean quiet=false; + while ((c=opt.getopt()) != -1 ) switch(c) { + case 'q': + quiet=true; + break; + case 'b': + domain=opt.getOptarg(); + break; + case 'd': + System.setProperty("IVY_DEBUG","yesla!"); + break; + case 'h': + default: + System.out.println(helpmsg); + System.exit(0); + } + new Counter(domain,quiet); + } // main + +} // class Counter |