aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/TestReady.java97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/TestReady.java b/tests/TestReady.java
new file mode 100644
index 0000000..fc3bd91
--- /dev/null
+++ b/tests/TestReady.java
@@ -0,0 +1,97 @@
+import fr.dgac.ivy.*;
+
+/**
+ * Ivy java ReadyMessage tester.
+ *
+ * @author Francois-Regis Colin <mailto:fcolin@cena.fr>
+ *
+ * (c) CENA
+ *
+ * usage: java TestReady & java TestReady 2
+ *
+ */
+
+class TestReady implements IvyApplicationListener {
+
+ static String me = "A";
+ static String other = "B";
+ static String ready_message = "A ready";
+ static String ready_bind = "^B ready";
+
+ private Ivy bus;
+ private class Ready implements IvyMessageListener {
+ public void receive (IvyClient app, String[] args)
+ {
+ int count = 0;
+ try {
+ count = bus.sendMsg ("are you there "+app.getApplicationName());
+ }
+ catch (IvyException ie) {
+ System.err.println("can't sendMsg" + ie.getMessage());
+ }
+ System.out.println("Application "+me+" received '"+ready_bind+"' from "+app.getApplicationName()+
+ " sent question 'are you there "+app.getApplicationName()+"'= "+ count );
+ }
+ }
+ private class Question implements IvyMessageListener {
+ public void receive (IvyClient app, String[] args)
+ {
+ int count = 0;
+ try {
+ count = bus.sendMsg ("yes i am "+me);
+ }
+ catch (IvyException ie) {
+ System.err.println("can't sendMsg" + ie.getMessage());
+ }
+ System.out.println("Application "+me+" Reply to "+app.getApplicationName()+" are you there = "+count );
+
+ }
+ }
+ private class Reply implements IvyMessageListener {
+ public void receive (IvyClient app, String[] args)
+ {
+ System.out.println("Application "+app.getApplicationName()+" Reply to our question! "+args[0]);
+
+ }
+ }
+ TestReady() {
+ try {
+
+ bus = new Ivy(me, ready_message, this);
+ bus.bindMsg (ready_bind, new Ready());
+ bus.bindMsg ("^are you there "+me, new Question());
+ bus.bindMsg ("^(yes i am "+other+")", new Reply());
+
+ bus.start(null);
+ } catch (IvyException ie) {
+ System.err.println("can't run the Ivy bus" + ie.getMessage());
+ }
+ }
+
+
+ public void disconnect(IvyClient client) {
+ }
+
+ public void directMessage(IvyClient client, int id, String msgarg) {
+ }
+
+ public void connect(IvyClient client) {
+
+ }
+
+ public void die(IvyClient client, int id, String msg) {
+ System.out.println("argh. cya " + msg);
+ }
+
+ public static void main(String args[]) {
+
+ if (args.length >= 1) {
+ me = "B";
+ other = "A";
+ ready_message = "B ready";
+ ready_bind = "^A ready";
+ }
+ System.out.println("I am "+me);
+ new TestReady();
+ }
+}