From bba0d7da93db5a33f5a5e16b476d4ac5b5a88be3 Mon Sep 17 00:00:00 2001 From: jestin Date: Wed, 16 Aug 2000 18:08:19 +0000 Subject: First version of java api guide. --- doc/html/guide/first.html | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 doc/html/guide/first.html (limited to 'doc/html/guide/first.html') diff --git a/doc/html/guide/first.html b/doc/html/guide/first.html new file mode 100644 index 0000000..97ab74c --- /dev/null +++ b/doc/html/guide/first.html @@ -0,0 +1,112 @@ + + + your first Ivy java application + + + + + +
+ The Ivy java library guide
Prev + Next

+ +

Your first Ivy java application

+ +

We are going to write a "Hello world translater" for an Ivy bus. The + application will subscribe to all messages starting + with "Hello", and re-emit them after translating "Hello" into "Bonjour". In + addition, the application will quit when it receives any message containing + exactly "Bye". + +

The code

+ There is the code of ivyTranslater.java: + + +
+
+import fr.dgac.ivy.* ;
+
+class ivyTranslater implements IvyMessageListener {
+
+  private Ivy bus;
+
+  ivyTranslater() {
+    // initialization
+    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());
+    }
+  }
+
+  // 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 ivyTranslater(); }
+}
+
+
+ +

Compiling

+

On a Unix computer, you should be able to compile the application with the + following command : + + +
+$ javac ivyTranslater.java +
$ +
+ +

Testing

+

We are going to test our application with Probe. In a terminal window, + launch ivyTranslater: + + +
+$ java ivyTranslater +
  +
+ +

Then in another terminal window, launch Probe. You are then ready to + start, Type "Hello Paul", and you should get "Bonjour Paul". Then Type "Bye", + and your application should quit : + + +
+$ java fr.dgac.ivy.Probe '(.*)' +
you want to subscribe to (.*) +
broadcasting on 127.255.255.255:2010 +
IvyTranslater connected +
IvyTranslater subscribes to ^Bye$ +
IvyTranslater subscribes to ^Hello(.*) +
IvyTranslater sent 'Hello le monde' +
Hello Paul +
-> Sent to 1 peers +
IvyTranslater sent 'Bonjour Paul' +
Bye +
-> Sent to 1 peers +
IvyTranslater disconnected +
<Ctrl-D> +
$ +
+ +


+ + + + + + + +
PrevHomeNext
The Ivy java library Basic functions
+ + -- cgit v1.1