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 | |
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')
-rw-r--r-- | src/Counter.java | 98 | ||||
-rwxr-xr-x | src/Ivy.java | 34 | ||||
-rwxr-xr-x | src/IvyClient.java | 271 | ||||
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/Probe.java | 17 | ||||
-rw-r--r-- | src/TestIvySwing.java | 85 |
6 files changed, 345 insertions, 162 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 diff --git a/src/Ivy.java b/src/Ivy.java index ad8a4e6..b23125a 100755 --- a/src/Ivy.java +++ b/src/Ivy.java @@ -40,9 +40,13 @@ public class Ivy implements Runnable, IvyApplicationListener { * the domain for the UDP rendez vous */ public static final String DEFAULT_DOMAIN = "127.255.255.255:"+DEFAULT_PORT; + /** + * the library version + */ + public static String libVersion ="1.0.8"; - private static boolean debug = (System.getProperty("IVY_DEBUG")!=null) ; - private static int serial=0; /* an unique ID for each regexps */ + private boolean debug; + private static int serial=0; /* an unique ID for each regexp */ private ServerSocket app; private IvyWatcher watch; private Thread server; @@ -69,6 +73,7 @@ public class Ivy implements Runnable, IvyApplicationListener { public Ivy( String name, String message, IvyApplicationListener appcb) { appName = name; ready_message = message; + debug = (System.getProperty("IVY_DEBUG")!=null); if ( appcb != null ) ivyApplicationListenerList.addElement( appcb ); } @@ -88,7 +93,7 @@ public class Ivy implements Runnable, IvyApplicationListener { } catch (IOException e) { throw new IvyException("can't open TCP service socket " + e ); } - traceDebug("TCP service open on port "+applicationPort); + traceDebug("lib: "+libVersion+" protocol: "+PROCOCOLVERSION+" TCP service open on port "+applicationPort); watch = new IvyWatcher(this); ivyRunning = true; server = new Thread(this); @@ -98,19 +103,19 @@ public class Ivy implements Runnable, IvyApplicationListener { /** * disconnects from the Ivy bus. - * TODO is there a bug here ? There is still a thread running and a - * standalone application won't quit here. + * + * TODO: it's buggy, the watcher is still there, the ivyclients are waiting + * for one last message . Everything needs to be redesigned from scratch */ public void stop() { + traceDebug("I want to leave"); try { + app.close(); ivyRunning = false; watch.stop(); - app.close(); - for ( int i = 0 ; i < clients.size(); i++ ) { + for (int i=0;i<clients.size();i++) { IvyClient client = (IvyClient)clients.elementAt(i); client.close("normal Ivy Stopping..."); - // advertise that this is a normal - //close for debugging purposes } } catch (IOException e) { traceDebug("IOexception Stop "); @@ -228,6 +233,7 @@ public class Ivy implements Runnable, IvyApplicationListener { for ( int i = 0 ; i < ivyApplicationListenerList.size(); i++ ) { ((IvyApplicationListener)ivyApplicationListenerList.elementAt(i)).die(client, id); } + this.stop(); } /* invokes the direct message callbacks @@ -254,13 +260,11 @@ public class Ivy implements Runnable, IvyApplicationListener { clients.removeElement( client ); } - void callCallback(IvyClient client, Integer key, String msgarg) throws IvyException { + void callCallback(IvyClient client, Integer key, String[] tab) throws IvyException { IvyMessageListener callback=(IvyMessageListener)callbacks.get(key); if (callback==null){ throw new IvyException("(callCallback) Not regexp matching id "+key.intValue()); } - String[] tab= myTokenize(msgarg,IvyClient.EndArg); - System.out.println("received " + tab.length + " args"); callback.receive( client, tab); } @@ -334,7 +338,7 @@ public class Ivy implements Runnable, IvyApplicationListener { traceDebug("Error IvyServer exception: " + e.getMessage()); System.out.println("DEBUG TCP socket reader caught an exception " + e.getMessage()); } - } + } // while traceDebug("IvyServer end of trans"); } @@ -353,4 +357,6 @@ public class Ivy implements Runnable, IvyApplicationListener { messages_classes = msg_classes; } -} +} // class Ivy + +/* EOF */ diff --git a/src/IvyClient.java b/src/IvyClient.java index 4faeb00..cfbc320 100755 --- a/src/IvyClient.java +++ b/src/IvyClient.java @@ -31,7 +31,7 @@ public class IvyClient extends Thread { final static int SchizoToken = 6; /* avoid race condition in concurrent connexions */ final static int DirectMsg = 7;/* the peer sends a direct message */ final static int Die = 8; /* the peer wants us to quit */ - /* test pour jdk1.3 */ + final static String MESSAGE_TERMINATOR = "\n"; /* the next protocol will use \r */ final static String StartArg = "\u0002";/* begin of arguments */ final static String EndArg = "\u0003"; /* end of arguments */ @@ -48,7 +48,7 @@ public class IvyClient extends Thread { private boolean peerCalling; IvyClient(Ivy bus, Socket socket,boolean peerCalling) throws IOException { - appName = "Unkown"; + appName = "Unknown"; appPort = 0; this.bus = bus; this.socket = socket; @@ -72,8 +72,10 @@ public class IvyClient extends Thread { start(); } - - String getApplicationName() { return appName ; } + /** + * returns the name of the remote agent. + */ + public String getApplicationName() { return appName ; } /** * allow an Ivy package class to access the list of regexps at a @@ -100,10 +102,6 @@ public class IvyClient extends Thread { RE regexp = (RE)regexp_in.get(key); REMatch result = regexp.getMatch(message); if ( result != null ) { - // it's just to check if matching went right.... It is right. - //String tmp=""; - //for (int i=1;i<=regexp.getNumSubs();i++) { tmp+="'"+result.toString(i)+"' "; } - //System.out.println(">> matching "+regexp.getNumSubs()+" blocks "+tmp); send(Msg,key,regexp.getNumSubs(),result); count++; } @@ -118,8 +116,6 @@ public class IvyClient extends Thread { */ void close(String msg) throws IOException { traceDebug( msg ); - socket.close(); // TODO it seems it doesnt stop the thread - out.close(); in.close(); gardefou=false; } @@ -143,108 +139,23 @@ public class IvyClient extends Thread { public void run() { String msg = null; try { - traceDebug("Connected from "+ socket.getInetAddress().getHostName()+ - ":"+socket.getPort()); + traceDebug("Connected from "+ socket.getInetAddress().getHostName()+ ":"+socket.getPort()); + /* + * TODO bug ?! + * sometime we're stuck in readline while gardefou is false + * we need non blocking IO, found in the next 1.4 jdk ... + */ while ( gardefou && ((msg=in.readLine()) != null )) { - int msgtype; // type of the last message received - Integer msgid; // ID of the last message received - RE regexp = null; // compiled regexp - String token = null; - /* - * First stage: extract the message - */ - StringTokenizer st = new StringTokenizer(msg); - if(!st.hasMoreTokens()){close("Bad format no type '"+msg+"'");break;} - token=st.nextToken().trim(); - if (token.length()==0){close("Bad format no type '"+msg+"'");break;} - try { - msgtype = Integer.parseInt(token); - } catch ( NumberFormatException e ) { - close("Bad format error parsing type'"+msg+"'"); - break; - } - if(!st.hasMoreTokens()){close("Bad format no id '"+msg+"'");break;} - - token=st.nextToken(StartArg).trim(); - try { - msgid=Integer.valueOf(token); - } catch ( NumberFormatException e ) { - close("Bad format error parsing id '"+token+"'"); - break; - } - String msgarg=""; - // if (st.hasMoreTokens()) msgarg=st.nextToken("\n").trim(); - if (st.hasMoreTokens()) msgarg=st.nextToken("\n"); - // TODO: here is a bug ! - // quick and dirty fix: I do the trimming by hand later on. - // (cf ref: This method may be used to trim whitespace from the - // beginning and end of a string; in fact, it trims all ASCII control characters as well. - - /* - * second stage: process the message - */ - switch (msgtype) { - case Bye: break; - case AddRegexp: - msgarg.trim(); - if ( bus.CheckRegexp(msgarg) ) { - try { - regexp_in.put(msgid,new RE(msgarg)); - regexp_text.put(msgid,msgarg); - } catch (REException e) { - System.err.println("Bad pattern: "+e.getMessage()); - } - } else { - System.err.println( - "Warning exp='"+msgarg+"' can't match removing from "+appName); - } - break; - case DelRegexp: - regexp_in.remove(msgid); - regexp_text.remove(msgid); - break; - case EndRegexp: - bus.connect(this); - /* TODO - * BUG ? the peer is perhaps not ready to handle this message - * an assymetric processing should be written - */ - if (bus.ready_message!=null) sendMsg(bus.ready_message); - break; - case Msg: - try { - bus.callCallback(this,msgid,msgarg.substring(1,msgarg.length()-1)); - } catch (IvyException ie) { - // calling an inexistant callback - System.err.println("calling an inexistant callback, the caller must be wrong !"); - } - break; - case Error: - traceDebug("Error msg "+msgid+" "+msgarg); - break; - case SchizoToken: - appName=msgarg; - appPort=msgid.intValue(); - if ( bus.checkConnected(this) ) { - close("Quitting Application already connected"); - System.err.println("Rare ! A concurrent connect occured"); - } - break; - case DirectMsg: - msgarg.trim(); - bus.directMessage( this, msgid.intValue(), msgarg ); - break; - case Die: - bus.die( this,msgid.intValue()); - break; - default: - System.err.println("*** IvyClient *** unhandled msg type "+ - msgtype+" "+msgid+msgarg); - break; - } // switch - } // while gardefou - traceDebug("normally Disconnected from "+ - socket.getInetAddress().getHostName()+":"+socket.getPort()); + try { + newParseMsg(msg); + } catch (IvyException ie) { + ie.printStackTrace(); + } + } + traceDebug("normally Disconnected from "+ socket.getInetAddress().getHostName()+":"+socket.getPort()); + socket.close(); + out.close(); + in.close(); } catch (IOException e) { traceDebug("abnormally Disconnected from "+ socket.getInetAddress().getHostName()+":"+socket.getPort()); @@ -253,22 +164,24 @@ public class IvyClient extends Thread { bus.removeClient( this ); } - private void sendBuffer( String buffer ) { + private void sendBuffer( String buffer ) throws IvyException { buffer += "\n"; try { out.write(buffer.getBytes() ); out.flush(); } catch ( IOException e ) { - /* - * TODO - * we should throw an exception here - */ - System.err.println("IvyClient.sendBuffer.write failed. FIX ME"); + throw new IvyException("IvyClient.sendBuffer.write failed: "+e.getMessage()); } } private void send(int type, int id, String arg) { - sendBuffer(type+" "+id+StartArg+arg); + try { + sendBuffer(type+" "+id+StartArg+arg); + } catch (IvyException ie ) { + // TODO shoud fix the exception Handling here ... + System.err.println("received an exception: " + ie.getMessage()); + ie.printStackTrace(); + } } private void send(int type, Integer id, int nbsub, REMatch result) { @@ -279,7 +192,127 @@ public class IvyClient extends Thread { buffer += result.toString(sub)+EndArg; } } - sendBuffer(buffer); + try { + sendBuffer(buffer); + } catch (IvyException ie ) { + // TODO shoud fix the exception Handling here ... + System.err.println("received an exception: " + ie.getMessage()); + ie.printStackTrace(); + } + } + + private String dumpHex(String s) { + byte[] b = s.getBytes(); + String out = ""; + String zu = "\t"; + for (int i=0;i<b.length;i++) { + char c = s.charAt(i); + out+=((int)c) + " "; + zu+= ((c>15) ? c : 'X')+" "; + } + out += zu; + return out; + } + + private String dumpMsg(String s) { + String deb = " \""+s+"\" "+s.length()+" cars, "; + for (int i=0;i<s.length();i++) { + deb+= "["+s.charAt(i) + "]:" + (int)s.charAt(i) +", "; + } + return s; + } + + private void newParseMsg(String s) throws IvyException { + byte[] b = s.getBytes(); + int from=0,to=0,msgType; + Integer msgId; + while ((to<b.length)&&(b[to]!=' ')) to++; + if (to>=b.length) throw new IvyException("protocol error"); + try { + msgType = Integer.parseInt(s.substring(from,to)); + } catch (NumberFormatException nfe) { + throw new IvyException("protocol error on msgType"); + } + from=to+1; + while ((to<b.length)&&(b[to]!=2)) to++; + if (to>=b.length) throw new IvyException("protocol error"); + try { + msgId = new Integer(s.substring(from,to)); + } catch (NumberFormatException nfe) { + throw new IvyException("protocol error on identifier"); + } + from=to+1; + switch (msgType) { + case Bye: + bus.die(this,msgId.intValue()); + gardefou=false; + break; + case AddRegexp: + String regexp=s.substring(from,b.length); + if ( bus.CheckRegexp(regexp) ) { + try { + regexp_in.put(msgId,new RE(regexp)); + regexp_text.put(msgId,regexp); + } catch (REException e) { + throw new IvyException("regexp error " +e.getMessage()); + } + } else { + throw new IvyException("regexp Warning exp='"+regexp+"' can't match removing from "+appName); + } + break; + case DelRegexp: + regexp_in.remove(msgId); + regexp_text.remove(msgId); + break; + case EndRegexp: + bus.connect(this); + /* TODO + * BUG ? the peer is perhaps not ready to handle this message + * an assymetric processing should be written + */ + if (bus.ready_message!=null) sendMsg(bus.ready_message); + break; + case Msg: + Vector v = new Vector(); + while (to<b.length) { + while ( (to<b.length) && (b[to]!=3) ) to++; + if (to<b.length) { + v.add(s.substring(from,to)); + from=to; + to++; + } + } + String[] tab = new String[v.size()]; + for (int i=0;i<v.size();i++) tab[i]=(String)v.elementAt(i); + bus.callCallback(this,msgId,tab); + break; + case Error: + String error=s.substring(from,b.length); + traceDebug("Error msg "+msgId+" "+error); + break; + case SchizoToken: + appName=s.substring(from,b.length); + appPort=msgId.intValue(); + if ( bus.checkConnected(this) ) { + try { + close("Quitting Application already connected"); + } catch (IOException ioe) { + throw new IvyException("io " + ioe.getMessage()); + } + throw new IvyException("Rare ! A concurrent connect occured"); + } + break; + case DirectMsg: + String direct=s.substring(from,b.length); + bus.directMessage( this, msgId.intValue(), direct ); + break; + case Die: + gardefou=false; + bus.die(this,msgId.intValue()); + break; + default: + throw new IvyException("protocol error, unknown message type "+msgType); + } } private void sendDie() {send(Die,0,"");} diff --git a/src/Makefile b/src/Makefile index 18beb1c..611049a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,7 @@ JAVACOPTS = -d . -deprecation $(CLASSPATH) SRCS = *.java JAR = ../lib/Ivy.jar - VER = 1.0.7 + VER = 1.0.8 DIST = ../lib/ivy-java-$(VER).jar JAVAC = jikes # JAVAC = javac diff --git a/src/Probe.java b/src/Probe.java index 6e4543b..a5238c1 100644 --- a/src/Probe.java +++ b/src/Probe.java @@ -1,6 +1,6 @@ package fr.dgac.ivy ; -import gnu.getopt.Getopt; import java.io.*; +import gnu.getopt.Getopt; /** * terminal implementation in java of the ivyprobe. @@ -12,9 +12,14 @@ import java.io.*; */ 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 { Probe p = new Probe(); - Getopt opt = new Getopt("Probe",args,"b:d"); + Getopt opt = new Getopt("Probe",args,"b:dh"); int c; String domain=Ivy.getDomain(null); while ((c = opt.getopt()) != -1) switch (c) { @@ -24,12 +29,14 @@ class Probe implements IvyApplicationListener, IvyMessageListener { case 'd': System.setProperty("IVY_DEBUG","yes"); break; + case 'h': default: + System.out.println(helpmsg); + System.exit(0); } // connexion to the Bus - Ivy bus; try { - bus=new Ivy("JPROBE","JPROBE ready",p); + Ivy bus=new Ivy("JPROBE","JPROBE ready",p); for (int i=opt.getOptind();i<args.length;i++) { System.out.println("you want to subscribe to " + args[i]); bus.bindMsg(args[i],p); @@ -69,7 +76,7 @@ class Probe implements IvyApplicationListener, IvyMessageListener { public void die(IvyClient client, int id) { looping=false; - System.out.println(client.getApplicationName() + " received die msg from "+ id ); + System.out.println("received die msg from " + client.getApplicationName() ); } public void directMessage(IvyClient client, int id, String arg) { 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 |