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/TestIvySwing.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/TestIvySwing.java')
-rw-r--r-- | src/TestIvySwing.java | 85 |
1 files changed, 62 insertions, 23 deletions
diff --git a/src/TestIvySwing.java b/src/TestIvySwing.java index 82afe43..e5138f6 100644 --- a/src/TestIvySwing.java +++ b/src/TestIvySwing.java @@ -3,6 +3,7 @@ package fr.dgac.ivy ; import java.awt.BorderLayout; import java.awt.event.*; import javax.swing.* ; +import gnu.getopt.Getopt ; /** * toy tool to probe the Ivy software bus. @@ -17,12 +18,16 @@ import javax.swing.* ; */ class TestIvySwing extends JPanel implements IvyApplicationListener { + /** + * help message for the standalone program + */ + public static final String helpmsg = "usage: java fr.dgac.ivy.TestIvySwing [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"; - private static String version ="1.0.2"; private static int index; private static int nbTIS=0; private String localname; private Ivy bus ; + private String domain; private String regexp = "(.*)"; private JLabel laRegex; private JTextArea ta ; @@ -31,14 +36,11 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { private JComboBox ports; private int regexp_id; private REGCB reg; - private java.text.SimpleDateFormat format = new - java.text.SimpleDateFormat("hh:mm:ss"); + private java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("hh:mm:ss"); private static String[] startDomainList = { "127.255.255.255:2010", - "10.192.36.255:2223", - "10.192.36.255:2333", - "10.192.36.255:2020", - "10.192.36.255:3110", + "10.192.36:3110", + "10.0.0:54321", }; private static java.util.Vector domainList; @@ -49,12 +51,34 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { domainList.add(startDomainList[i]); } - public static void main(String[] args) throws IvyException {newTestIvy();} + public static void main(String[] args) throws IvyException { + 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); + } + newTestIvy(domain); + } - private TestIvySwing() throws IvyException { + private TestIvySwing(String domain) throws IvyException { super(new BorderLayout()); + this.domain=domain; nbTIS++; - ta = new JTextArea(25,40); + ta = new JTextArea(25,30); ta.setEditable(false); add(new JScrollPane(ta),BorderLayout.CENTER); JPanel p = new JPanel(new BorderLayout()); @@ -72,12 +96,7 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { p.add(p2,BorderLayout.SOUTH); JButton tmpb ; (p = new JPanel()).add(tmpb=new JButton("spawn")); - tmpb.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - try { newTestIvy(); - } catch (IvyException ie) {} - } - }); + tmpb.addActionListener(new SPAWN(domain)); p.add(tmpb=new JButton("clear")); tmpb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -86,8 +105,11 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { }); ports=new JComboBox(); ports.setEditable(true); - for (java.util.Enumeration e=domainList.elements();e.hasMoreElements();) { - ports.addItem((String) e.nextElement()); + int index=0; + for (java.util.Enumeration e=domainList.elements();e.hasMoreElements();index++) { + String port = (String) e.nextElement(); + ports.addItem(port); + if (port == domain ) { ports.setSelectedIndex(index); } } ports.addActionListener(new ComboCB()); p.add(ports); @@ -95,12 +117,12 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { tfRegex.setNextFocusableComponent(tfSend); tfSend.setNextFocusableComponent(tfRegex); tfSend.setRequestFocusEnabled(true); - localname = "TestIvySwing "+version+" ("+index+")"; + localname = "TestIvySwing "+Ivy.libVersion+" ("+index+")"; index++; bus = new Ivy(localname,localname+" ready",this); regexp_id = bus.bindMsg(regexp,reg); - bus.start(null); - append( "Ivy Domain: "+ bus.getDomain(null) ); + bus.start(domain); + append( "Ivy Domain: "+ bus.getDomain(domain) ); } public void connect(IvyClient client) { @@ -122,6 +144,11 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { private class ComboCB implements ActionListener { public void actionPerformed(ActionEvent e) { String newDomain=(String)ports.getSelectedItem(); + if (newDomain == domain) { + // if it's the same domain, don't do anything + return; + } + domain=newDomain; try { append( "deconnexion from domain "+ bus.getDomain(null)); } catch ( IvyException ie ) { @@ -176,8 +203,8 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { ta.insert("[" + format.format(new java.util.Date()) + "] "+ s + "\n",0); } - private static void newTestIvy() throws IvyException { - TestIvySwing tb = new TestIvySwing(); + private static void newTestIvy(String domain) throws IvyException { + TestIvySwing tb = new TestIvySwing(domain); JFrame f = new JFrame(tb.localname); f.addWindowListener( tb.new WCCB(f,tb)) ; f.getContentPane().add(tb, BorderLayout.CENTER); @@ -197,5 +224,17 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { public void windowActivated(WindowEvent e) {tfSend.grabFocus();} } + private class SPAWN implements ActionListener { + private String domain; + public SPAWN(String domain) {this.domain=domain;} + public void actionPerformed(ActionEvent e) { + try { + newTestIvy(domain); + } catch (IvyException ie) { + ie.printStackTrace(); + } + } + } + } // class TestIvySwing // EOF |