diff options
author | jestin | 2000-08-16 18:08:19 +0000 |
---|---|---|
committer | jestin | 2000-08-16 18:08:19 +0000 |
commit | bba0d7da93db5a33f5a5e16b476d4ac5b5a88be3 (patch) | |
tree | 800e6aa5fb9aea7487259e19d6cbdb9626b42b07 /doc/html/guide/first.html | |
parent | 32dd3ad48a8e63618db4ea17316bcc57cb778a30 (diff) | |
download | ivy-java-bba0d7da93db5a33f5a5e16b476d4ac5b5a88be3.zip ivy-java-bba0d7da93db5a33f5a5e16b476d4ac5b5a88be3.tar.gz ivy-java-bba0d7da93db5a33f5a5e16b476d4ac5b5a88be3.tar.bz2 ivy-java-bba0d7da93db5a33f5a5e16b476d4ac5b5a88be3.tar.xz |
First version of java api guide.
Diffstat (limited to 'doc/html/guide/first.html')
-rw-r--r-- | doc/html/guide/first.html | 112 |
1 files changed, 112 insertions, 0 deletions
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 @@ +<html> +<head> + <title>your first Ivy java application </title> +</head> +<body> + <table width=100% border=0 cellpadding=0 cellspacing=0><tr><th colspan=3 align=center> + The Ivy java library guide</th></tr><tr> + <td width=10% align=left valign=bottom><a href="javalib.html">Prev</a></td> + <td width=80% align=center valign=bottom> + <td width=10% align=right valign=bottom><a href="basic.html">Next</a></td> + </tr></table><hr> + + <h1>Your first Ivy java application</h1> + + <p>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". + + <h2>The code</h2> + There is the code of <a href="ivyTranslater.java">ivyTranslater.java</a>: + +<TABLE cellpadding=0 cellspacing=0 width=100%> +<tr BGcolor=#e0e0e0 TEXT=#000000><td> +<PRE> +<FONT color=#c000c0>import</FONT> fr.dgac.ivy.* ; + +<FONT color=#008000>class</FONT> ivyTranslater <FONT color=#008000>implements</FONT> IvyMessageListener { + + <FONT color=#008000>private</FONT> Ivy bus; + + ivyTranslater() { + <FONT color=#0000c0>// initialization</FONT> + bus = <FONT color=#804000>new</FONT> Ivy(<FONT color=#c00000>"IvyTranslater"</FONT>,<FONT color=#c00000>"Hello le monde"</FONT>,<FONT color=#c00000>null</FONT>); + bus.bindMsg(<FONT color=#c00000>"^Hello(.*)"</FONT>,<FONT color=#008000>this</FONT>); + bus.bindMsg(<FONT color=#c00000>"^Bye$"</FONT>,<FONT color=#804000>new</FONT> IvyMessageListener() { + <FONT color=#0000c0>// callback for </FONT><FONT color=#c00000>"Bye"</FONT><FONT color=#0000c0> message</FONT> + <FONT color=#008000>public</FONT> <FONT color=#008000>void</FONT> receive(IvyClient client, String[] args) {System.exit(<FONT color=#c00000>0</FONT>);} + }); + <FONT color=#804000>try</FONT> { + <FONT color=#0000c0>// starts the bus on the default domain or IVY_DOMAIN property</FONT> + bus.start(<FONT color=#c00000>null</FONT>); + } <FONT color=#804000>catch</FONT> (IvyException ie) { + System.err.println(<FONT color=#c00000>"can't run the Ivy bus"</FONT> + ie.getMessage()); + } + } + + <FONT color=#0000c0>// callback associated to the </FONT><FONT color=#c00000>"Hello"</FONT><FONT color=#0000c0> messages</FONT><FONT color=#c00000>"</FONT> + <FONT color=#008000>public</FONT> <FONT color=#008000>void</FONT> receive(IvyClient client, String[] args) { + bus.sendMsg(<FONT color=#c00000>"Bonjour"</FONT>+((args.length><FONT color=#c00000>0</FONT>)?args[<FONT color=#c00000>0</FONT>]:<FONT color=#c00000>""</FONT>)); + } + + <FONT color=#008000>public</FONT> <FONT color=#008000>static</FONT> <FONT color=#008000>void</FONT> main(String args[]) { <FONT color=#804000>new</FONT> ivyTranslater(); } +} +</PRE> +</td></tr></table> + + <h2>Compiling</h2> + <p>On a Unix computer, you should be able to compile the application with the + following command : + +<table cellpadding=0 cellspacing=0 width=100%> +<tr bgcolor=#e0e0e0 text=#000000><td> +$ javac ivyTranslater.java +<br>$ +</td></tr></table> + + <h2>Testing</h2> + <p>We are going to test our application with Probe. In a terminal window, + launch ivyTranslater: + +<table cellpadding=0 cellspacing=0 width=100%> +<tr bgcolor=#e0e0e0 text=#000000><td> +$ java ivyTranslater +<br> +</td></tr></table> + + <p>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 : + +<table cellpadding=0 cellspacing=0 width=100%> +<tr bgcolor=#e0e0e0 text=#000000><td> +$ java fr.dgac.ivy.Probe '(.*)' +<br>you want to subscribe to (.*) +<br>broadcasting on 127.255.255.255:2010 +<br>IvyTranslater connected +<br>IvyTranslater subscribes to ^Bye$ +<br>IvyTranslater subscribes to ^Hello(.*) +<br>IvyTranslater sent 'Hello le monde' +<br><b>Hello Paul</b> +<br>-> Sent to 1 peers +<br>IvyTranslater sent 'Bonjour Paul' +<br><b>Bye</b> +<br>-> Sent to 1 peers +<br>IvyTranslater disconnected +<br><Ctrl-D> +<br>$ +</td></tr></table> + + <p><hr><table width=100% border=0 cellpadding=0 cellspacing=0><tr> + <td width=33% align=left valign=top><a href="javalib.html">Prev</a></td> + <td width=34% align=center valign=top><a href="index.html">Home</a></td> + <td width=33% align=right valign=top><a href="basic.html">Next</a></td> + </tr><tr> + <td width=33% align=left valign=top>The Ivy java library</td> + <td width=34% align=center valign=top> </td> + <td width=33% align=right valign=top>Basic functions</a></td> + </tr></table> +</body> +</html> |