aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorjestin2002-12-30 13:06:40 +0000
committerjestin2002-12-30 13:06:40 +0000
commite126ac84a2d2415328989d0e084faeda42e303c8 (patch)
tree7724dfdd52714fcf2edec63c2c2e21d3600f51b1 /examples
parent4aa86fb6b7edab0406d4003eb2c5be378a87f982 (diff)
downloadivy-java-e126ac84a2d2415328989d0e084faeda42e303c8.zip
ivy-java-e126ac84a2d2415328989d0e084faeda42e303c8.tar.gz
ivy-java-e126ac84a2d2415328989d0e084faeda42e303c8.tar.bz2
ivy-java-e126ac84a2d2415328989d0e084faeda42e303c8.tar.xz
Cleanup.
Diffstat (limited to 'examples')
-rw-r--r--examples/Counter.java16
-rw-r--r--examples/Makefile2
-rw-r--r--examples/TestIvy.java142
-rw-r--r--examples/TestIvySwing.java25
-rw-r--r--examples/Translate.java13
-rw-r--r--examples/ivyTranslater.java15
6 files changed, 105 insertions, 108 deletions
diff --git a/examples/Counter.java b/examples/Counter.java
index 1275101..a1dffd1 100644
--- a/examples/Counter.java
+++ b/examples/Counter.java
@@ -1,10 +1,16 @@
/**
- * a software bus package geiger counter
+ * Yet another Ivy java program example
+ *
+ * a software bus message "geiger counter" displaying each and every second
+ * the number of messages sent on the bus during the past second, the past ten
+ * seconds and the past minute.
*
* @author Yannick Jestin
* @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
*
- * (c) CENA 1998-2002
+ * (c) CENA 1998-2003
+ * This program is provided as is, under the LGPL licence with the ivy-java
+ * package.
*
*/
import fr.dgac.ivy.* ;
@@ -34,6 +40,8 @@ public class Counter implements IvyMessageListener, Runnable {
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) {
@@ -59,7 +67,7 @@ public class Counter implements IvyMessageListener, Runnable {
}
totalminute+=secCount[counter]-secCount[moinune];
totaldix+=secCount[counter]-secCount[moindix];
- String s = "MessageCount "+ secCount[counter]+" "+totaldix+" "+totalminute;
+ String s = "stats:\t"+ secCount[counter]+"\t"+totaldix+"\t"+totalminute;
if (!quiet) { System.out.println(s); }
bus.sendMsg(s);
moinune=(moinune+1)%secCount.length;
@@ -72,7 +80,7 @@ public class Counter implements IvyMessageListener, Runnable {
public void receive(IvyClient client,String[] args) { secCount[counter]++; }
public static void main(String[] args) {
- String domain="127.255.255.255:2010";
+ String domain=Ivy.getDomain(null);
Getopt opt = new Getopt("Counter",args,"b:dhq");
int c;
boolean quiet=false;
diff --git a/examples/Makefile b/examples/Makefile
index 94aed89..844cab7 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,5 +1,5 @@
# Be sure to set this before compiling ...
-JIKESPATH = /usr/local/j2sdk1.4.1/jre/lib/rt.jar:/usr/share/java/repository:../lib/ivy-java.jar:nanoxml-2.2.1.jar:.
+JIKESPATH = /usr/local/j2sdk1.4.1/jre/lib/rt.jar:../lib/ivy-java.jar:/usr/share/java/repository:nanoxml-2.2.1.jar:.
JAVACOPTS = -deprecation
.SUFFIXES: .java .class
SRCS = TestIvy.java TestIvySwing.java Counter.java ivyTranslater.java Translate.java TranslateXML.java
diff --git a/examples/TestIvy.java b/examples/TestIvy.java
index 7bbc99c..3ab0cc0 100644
--- a/examples/TestIvy.java
+++ b/examples/TestIvy.java
@@ -1,126 +1,96 @@
-import java.awt.* ;
-import java.awt.event.* ;
-import fr.dgac.ivy.*;
-
/**
- * toy tool to probe the Ivy software bus.
- * it relies on the AWT, and is less useable than TestIvySwing, which should
- * be preferred.
+ * TestIvy, an AWT Ivy Java program example.
+ *
+ * toy tool to probe the Ivy software bus it relies on the AWT, and is less useable than
+ * TestIvySwing, which should be preferred if swing is on your JDK.
*
- * @see fr.dgac.ivy.TestIvySwing
- * @author François-Régis Colin
* @author Yannick Jestin
* @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
+ * @see fr.dgac.ivy.TestIvySwing
+ *
+ * (c) CENA
*
- * CHANGELOG
- * 1.0.10:
- * - System.exit on bus die
*/
+import java.awt.* ;
+import java.awt.event.* ;
+import fr.dgac.ivy.*;
-class TestIvy extends Panel implements IvyApplicationListener {
+class TestIvy extends Frame implements IvyApplicationListener,IvyMessageListener {
+ public static String DEFAULTREGEXP = "(.*)";
private Ivy bus ;
private String regexp="";
+ private Label tfBound;
private TextField tfRegex, tfSend ;
private TextArea ta ;
private Button buApply, buSend, buClear ;
- 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 int regexp_id;
public TestIvy() throws IvyException {
- super(new BorderLayout());
+ addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
+ setLayout(new BorderLayout());
ta = new TextArea();
ta.setEditable(false);
add(ta,BorderLayout.CENTER);
Panel p = new Panel(new BorderLayout());
- p.add(new Label("Regex:"),BorderLayout.WEST);
+ add(p,BorderLayout.NORTH);
+ p.add(tfBound=new Label("Boung to: "+DEFAULTREGEXP),BorderLayout.WEST);
tfRegex = new TextField(regexp);
- tfRegex.addActionListener(new REGCB());
+ tfRegex.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ try { bus.unBindMsg(regexp_id); } catch (IvyException ie) {
+ System.out.println("Big badaboum"); // this should not happen
+ System.exit(0);
+ }
+ regexp=tfRegex.getText();
+ tfBound.setText("Bound to: " +regexp);
+ regexp.trim();
+ regexp_id = bus.bindMsg(regexp,TestIvy.this);
+ tfRegex.setText("");
+ pack();
+ }
+ });
p.add(tfRegex,BorderLayout.CENTER);
- add(p,BorderLayout.NORTH);
p = new Panel(new BorderLayout());
p.add(new Label("Msg:"),BorderLayout.WEST);
tfSend = new TextField("");
- tfSend.addActionListener(new SENDCB());
+ tfSend.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ int count;
+ String tosend = tfSend.getText();
+ tfSend.setText("");
+ count = bus.sendMsg(tosend);
+ append("Sending '" + tosend + "' count " + count );
+ }
+ });
p.add(tfSend,BorderLayout.CENTER);
add(p,BorderLayout.SOUTH);
bus = new Ivy("JAVATESTBUS","Testbus is ready",this);
- bus.start(null);
+ regexp_id = bus.bindMsg(DEFAULTREGEXP,this);
+ bus.start(Ivy.getDomain(null));
append( "Ivy Domain: "+ bus.getDomain(null) );
}
- public static Frame f;
-
public static void main(String[] args) throws IvyException {
TestIvy tb = new TestIvy();
- f = new Frame("TestIvy");
- f.addWindowListener( tb.new WCCB(f,tb)) ;
- f.add(tb, BorderLayout.CENTER);
- f.pack();
- f.setVisible(true);
- }
-
- public void connect(IvyClient client) {
- append(client.getApplicationName() + " connected " );
+ tb.pack();
+ tb.setVisible(true);
}
- public void disconnect(IvyClient client) {
- append(client.getApplicationName() + " disconnected " );
- }
- public void die(IvyClient client, int id) {
- f.dispose();
- System.exit(0);
- }
+ 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 directMessage(IvyClient client, int id, String arg) {
- append(client.getApplicationName() + " direct Message "+ id + arg );
+ append(client.getApplicationName() + " direct Message "+ id + arg );
}
- class REGCB implements ActionListener, IvyMessageListener {
- public void actionPerformed(ActionEvent e) {
- try {
- bus.unBindMsg(regexp_id);
- } catch (IvyException ie) {
- System.out.println("Big badaboum"); // this should not happen
- }
- regexp=tfRegex.getText();
- regexp.trim();
- regexp_id = bus.bindMsg(regexp,this);
- tfRegex.setText("");
- }
- public void receive(IvyClient client, String[] args) {
- String out="client " + client.getApplicationName() + " envoie: [ ";
- for (int i=0;i<args.length;i++)
- out=out+args[i]+ ((i<args.length-1)?" , ":"");
- out = out + " ]";
- append(out);
- }
+ public void receive(IvyClient client, String[] args) {
+ String out="client " + client.getApplicationName() + " envoie: [ ";
+ for (int i=0;i<args.length;i++) out+=args[i]+ ((i<args.length-1)?" , ":"");
+ out+= " ]";
+ append(out);
}
- class SENDCB implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- int count;
- String tosend = tfSend.getText();
- tfSend.setText("");
- count = bus.sendMsg(tosend);
- append("Sending '" + tosend + "' count " + count );
- }
- }
-
- private void append(String s) {
- ta.append("[" + format.format(new java.util.Date()) + "] "+ s + "\n");
- }
-
- class WCCB extends WindowAdapter {
- private Frame f;
- public WCCB(Frame f, TestIvy b) { this.f=f; }
- public void windowClosing(WindowEvent e) {
- f.setVisible(false);
- bus.stop();
- bus = null;
- f.dispose();
- System.exit(0);
- }
- }
+ private void append(String s) { ta.append("[" + format.format(new java.util.Date()) + "] "+ s + "\n"); }
-} // class TestIvy
-// EOF
+}
diff --git a/examples/TestIvySwing.java b/examples/TestIvySwing.java
index 582e8a1..ee265a5 100644
--- a/examples/TestIvySwing.java
+++ b/examples/TestIvySwing.java
@@ -1,24 +1,23 @@
+/**
+ * TestIvySwing, a swing Ivy Java example to probe the Ivy software bus.
+ *
+ * it relies on the Swing toolkit, which is not standard on jdk1.1 platforms,
+ * if you don't have swing, your can use TestIvy.
+ *
+ * @author Yannick Jestin
+ * @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
+ *
+ * (c) CENA
+ *
+ */
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.* ;
import gnu.getopt.Getopt ;
import fr.dgac.ivy.*;
-/**
- * toy tool to probe the Ivy software bus.
- * it relies on the Swing toolkit, which is not standard on jdk1.1 platform.
- * if you don't have jdk1.2 or swing, consider downloading it. You can also
- * use TestIvy
- *
- * @see fr.dgac.ivy.TestIvy
- * @author Yannick Jestin
- * @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
- */
class TestIvySwing extends JPanel implements IvyApplicationListener {
- /**
- * help message for the standalone program
- */
public static final String helpmsg = "usage: java 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";
public static final int WIDTH=30;
public static final int HEIGHT=30;
diff --git a/examples/Translate.java b/examples/Translate.java
index dee8210..738443c 100644
--- a/examples/Translate.java
+++ b/examples/Translate.java
@@ -1,3 +1,11 @@
+/**
+ * Translate, an Ivy java program sample.
+ *
+ * @author Yannick Jestin <jestin@cena.fr>
+ *
+ * (c) CENA
+ *
+ */
import fr.dgac.ivy.* ;
import java.io.* ;
import gnu.regexp.* ;
@@ -52,12 +60,9 @@ class Translate {
}
}
- // callback associated to the "Hello" messages"
public void receive(IvyClient client, String[] args) {
bus.sendMsg("Bonjour"+((args.length>0)?args[0]:""));
}
- public static void main(String args[]) {
- new Translate("translation.txt");
- }
+ public static void main(String args[]) { new Translate("translation.txt"); }
}
diff --git a/examples/ivyTranslater.java b/examples/ivyTranslater.java
index f995270..497ac87 100644
--- a/examples/ivyTranslater.java
+++ b/examples/ivyTranslater.java
@@ -1,3 +1,18 @@
+/**
+ * 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".
+ *
+ * @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.
+ *
+ */
import fr.dgac.ivy.* ;
class ivyTranslater implements IvyMessageListener {