aboutsummaryrefslogtreecommitdiff
path: root/examples/ivyTranslater.java
diff options
context:
space:
mode:
authorjestin2004-07-27 16:21:24 +0000
committerjestin2004-07-27 16:21:24 +0000
commit9ab98e8b79688821f85649fa3a04137f83467b73 (patch)
treeec55f2feb85355cadaf901bd561cd37444ae83ba /examples/ivyTranslater.java
parent9eff9570e518daccec02dd62593294341f4c36b6 (diff)
downloadivy-java-9ab98e8b79688821f85649fa3a04137f83467b73.zip
ivy-java-9ab98e8b79688821f85649fa3a04137f83467b73.tar.gz
ivy-java-9ab98e8b79688821f85649fa3a04137f83467b73.tar.bz2
ivy-java-9ab98e8b79688821f85649fa3a04137f83467b73.tar.xz
clean up the examples to abide to the new API
Diffstat (limited to 'examples/ivyTranslater.java')
-rw-r--r--examples/ivyTranslater.java49
1 files changed, 24 insertions, 25 deletions
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();
+ }
}