diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Counter.java | 7 | ||||
-rw-r--r-- | examples/Makefile | 2 | ||||
-rw-r--r-- | examples/TestIvy.java | 11 | ||||
-rw-r--r-- | examples/TestIvySwing.java | 26 | ||||
-rw-r--r-- | examples/Translate.java | 37 | ||||
-rw-r--r-- | examples/ivyTranslater.java | 49 |
6 files changed, 77 insertions, 55 deletions
diff --git a/examples/Counter.java b/examples/Counter.java index 34ae576..3c4c93e 100644 --- a/examples/Counter.java +++ b/examples/Counter.java @@ -41,13 +41,12 @@ public class Counter implements IvyMessageListener, Runnable { 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) { + public Counter(String domain,boolean quiet) throws IvyException { this.quiet=quiet; for (int j=0;j<secCount.length;j++) {secCount[j]=0;} bus = new Ivy("Counter","Counter ready",null); System.out.println(bus.domains(domain)); System.out.println("stats:\t1s\t10s\t1m"); - bus.bindMsg(".*",this); bus.bindMsg("^EXHAUSTED$",new IvyMessageListener(){ public void receive(IvyClient client,String[] args) { isRunning=false; @@ -74,7 +73,7 @@ public class Counter implements IvyMessageListener, Runnable { totaldix+=secCount[counter]-secCount[moindix]; String s = "stats:\t"+ secCount[counter]+"\t"+totaldix+"\t"+totalminute; if (!quiet) { System.out.println(s); } - bus.sendMsg(s); + try { bus.sendMsg(s); } catch (IvyException ie) { } moinune=(moinune+1)%secCount.length; moindix=(moindix+1)%secCount.length; counter=(counter+1)%secCount.length; @@ -84,7 +83,7 @@ public class Counter implements IvyMessageListener, Runnable { public void receive(IvyClient client,String[] args) { secCount[counter]++; } - public static void main(String[] args) { + public static void main(String[] args) throws IvyException { String domain=Ivy.getDomain(null); Getopt opt = new Getopt("Counter",args,"b:dhq"); int c; diff --git a/examples/Makefile b/examples/Makefile index 84104a5..4918928 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -3,7 +3,7 @@ OBJS = $(SRCS:.java=.class) NANOXMLPATH=/export/home/jestin/java/Jars/nanoxml-2.2.1.jar -GNUPATH=/usr/share/java/repository:/usr/share/java/gnu.getopt.0.9.jar:/usr/share/java/gnu-regexp-1.1.3.jar +GNUPATH=/usr/share/java/regexp.jar:/usr/share/java/gnu.getopt.jar BUILDPATH=../lib/ivy-java.jar ADD=$(GNUPATH):$(BUILDPATH):$(NANOXMLPATH) diff --git a/examples/TestIvy.java b/examples/TestIvy.java index 3ab0cc0..7bc96d0 100644 --- a/examples/TestIvy.java +++ b/examples/TestIvy.java @@ -45,7 +45,7 @@ class TestIvy extends Frame implements IvyApplicationListener,IvyMessageListener regexp=tfRegex.getText(); tfBound.setText("Bound to: " +regexp); regexp.trim(); - regexp_id = bus.bindMsg(regexp,TestIvy.this); + try { regexp_id = bus.bindMsg(regexp,TestIvy.this); } catch (IvyException ie) { } tfRegex.setText(""); pack(); } @@ -59,8 +59,11 @@ class TestIvy extends Frame implements IvyApplicationListener,IvyMessageListener int count; String tosend = tfSend.getText(); tfSend.setText(""); - count = bus.sendMsg(tosend); - append("Sending '" + tosend + "' count " + count ); + try { count = bus.sendMsg(tosend); + append("Sending '" + tosend + "' count " + count ); + } catch (IvyException ie) { + append("*Error* cant't send " + tosend ); + } } }); p.add(tfSend,BorderLayout.CENTER); @@ -79,7 +82,7 @@ class TestIvy extends Frame implements IvyApplicationListener,IvyMessageListener public void connect(IvyClient client) { append(client.getApplicationName() + " connected " ); } public void disconnect(IvyClient client) { append(client.getApplicationName() + " disconnected " ); } - public void die(IvyClient client, int id) { System.exit(0); } + public void die(IvyClient client, int id,String msgarg) { System.exit(0); } public void directMessage(IvyClient client, int id, String arg) { append(client.getApplicationName() + " direct Message "+ id + arg ); } diff --git a/examples/TestIvySwing.java b/examples/TestIvySwing.java index e7a9315..cb3eca5 100644 --- a/examples/TestIvySwing.java +++ b/examples/TestIvySwing.java @@ -141,8 +141,8 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { append(client.getApplicationName() + " disconnected " ); } - public void die(IvyClient client, int id) { - append(client.getApplicationName() + " die "+ id ); + public void die(IvyClient client, int id,String msgarg) { + append(client.getApplicationName() + " die "+ id + " " + msgarg); } public void directMessage(IvyClient client, int id, String arg) { @@ -175,9 +175,13 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { } regexp=tfRegex.getText(); regexp.trim(); - regexp_id = bus.bindMsg(regexp,this); - tfRegex.setText(""); - laRegex.setText(regexp); + try { + regexp_id = bus.bindMsg(regexp,this); + tfRegex.setText(""); + laRegex.setText(regexp); + } catch (IvyException ie) { + System.out.println("RE error "+regexp); // this should not happen + } } public void receive(IvyClient client, String[] args) { String out="client " + client.getApplicationName() + " envoie: [ "; @@ -194,10 +198,14 @@ class TestIvySwing extends JPanel implements IvyApplicationListener { int count; String tosend = tfSend.getText(); tfSend.setText(""); - if ( (count = bus.sendMsg(tosend)) != 0 ) - append("Sending '" + tosend + "' count " + count ); - else - append("not Sending '" + tosend + "' nobody cares"); + try { + if ( (count = bus.sendMsg(tosend)) != 0 ) + append("Sending '" + tosend + "' count " + count ); + else + append("not Sending '" + tosend + "' nobody cares"); + } catch (IvyException ie ) { + append("problem Sending '" + tosend + "'"); + } } } diff --git a/examples/Translate.java b/examples/Translate.java index 738443c..43ed82f 100644 --- a/examples/Translate.java +++ b/examples/Translate.java @@ -5,16 +5,19 @@ * * (c) CENA * + * 1.2.6 + * - goes apache jakarta regexp + * */ import fr.dgac.ivy.* ; import java.io.* ; -import gnu.regexp.* ; +import org.apache.regexp.* ; class Translate { private Ivy bus; - Translate(String filename) { + Translate(String filename) throws IvyException { bus = new Ivy("Translater","Hello le monde",null); parseFile(filename); bus.bindMsg("^Bye$",new IvyMessageListener() { @@ -33,16 +36,18 @@ class Translate { try { BufferedReader in = new BufferedReader(new FileReader(new File(filename))); String s; - RE regexp; - regexp = new RE("\"([^\"]*)\" \"([^\"]*)\""); + RE re = new RE("\"([^\"]*)\" \"([^\"]*)\""); while ( (s=in.readLine()) != null ) { - REMatch result = regexp.getMatch(s); - bus.bindMsg(result.toString(1),new TALK(result.toString(2))); + if (re.match(s)) { + System.out.println("binding " +re.getParen(1)+" and translating to " + re.getParen(2)); + try { + bus.bindMsg(re.getParen(1),new TALK(re.getParen(2))); + } catch (IvyException ie) { + System.out.println(re.getParen(1)+" is not a valid PCRE regex"); + } + } } in.close(); - } catch (REException ree) { - System.out.println("regexp error"); - System.exit(-1); } catch (FileNotFoundException fnfe) { System.out.println("file "+filename+" not found. Good bye !"); System.exit(-1); @@ -56,13 +61,21 @@ class Translate { private String go; TALK(String s) {go=s;} public void receive(IvyClient client, String[] args) { - bus.sendMsg(go); + try { + bus.sendMsg(go); + } catch (IvyException ie) { + } } } public void receive(IvyClient client, String[] args) { - bus.sendMsg("Bonjour"+((args.length>0)?args[0]:"")); + try { + bus.sendMsg("Bonjour"+((args.length>0)?args[0]:"")); + } catch (IvyException ie) { + } } - public static void main(String args[]) { new Translate("translation.txt"); } + public static void main(String args[]) throws IvyException { + new Translate("translation.txt"); + } } diff --git a/examples/ivyTranslater.java b/examples/ivyTranslater.java index 497ac87..5299338 100644 --- a/examples/ivyTranslater.java +++ b/examples/ivyTranslater.java @@ -1,46 +1,45 @@ /** * Yet another Ivy java program example * - * This is the example from the documentations, it connects to the bus, and - * translate the messages beginning with "Hello" by the same message, where - * "Hello" is replaced by "Bonjour". + * This is the example from the documentation * * @author Yannick Jestin <jestin@cena.fr> * * (c) CENA * - * This program is distributed as is, under the LGPL licence, which should be - * present in the package. + * This program is distributed as is * */ import fr.dgac.ivy.* ; class ivyTranslater implements IvyMessageListener { - private Ivy bus; + private Ivy bus; - ivyTranslater() { - bus = new Ivy("IvyTranslater","Hello le monde",null); - bus.bindMsg("^Hello(.*)",this); - bus.bindMsg("^Bye$",new IvyMessageListener() { - // callback for "Bye" message - public void receive(IvyClient client, - String[] args) {System.exit(0);} - }); - try { - // starts the bus on the default domain or IVY_DOMAIN property - bus.start(null); - } catch (IvyException ie) { - System.err.println("can't run the Ivy bus" + ie.getMessage()); + ivyTranslater() throws IvyException { + // initialization, name and ready message + bus = new Ivy("IvyTranslater","IvyTranslater Ready",null); + bus.bindMsg("^Hello(.*)",this); + bus.bindMsg("^Bye$",new IvyMessageListener() { + // callback for "Bye" message + public void receive(IvyClient client, String[] args) { + bus.stop(); } - } + }); + // starts the bus on the default domain + bus.start(null); + } - // callback associated to the "Hello" messages" - public void receive(IvyClient client, String[] args) { + // callback associated to the "Hello" messages" + public void receive(IvyClient client, String[] args) { + try { bus.sendMsg("Bonjour"+((args.length>0)?args[0]:"")); + } catch (IvyException ie) { + System.out.println("can't send my message !"); } + } - public static void main(String args[]) { - new ivyTranslater(); - } + public static void main(String args[]) throws IvyException { + new ivyTranslater(); + } } |