aboutsummaryrefslogtreecommitdiff
path: root/tests/TestReady.java
diff options
context:
space:
mode:
authorfcolin2011-02-17 13:31:11 +0000
committerfcolin2011-02-17 13:31:11 +0000
commit4d486c099ed1cdd05dd6990a0f407459c3f502d5 (patch)
tree570a7a11d9d64bd0345fe59fbca8cb0114e1f982 /tests/TestReady.java
parentd93623316e15f774688bd7523c9c7431bffa689e (diff)
downloadivy-java-4d486c099ed1cdd05dd6990a0f407459c3f502d5.zip
ivy-java-4d486c099ed1cdd05dd6990a0f407459c3f502d5.tar.gz
ivy-java-4d486c099ed1cdd05dd6990a0f407459c3f502d5.tar.bz2
ivy-java-4d486c099ed1cdd05dd6990a0f407459c3f502d5.tar.xz
test envoi de message a partir d'un callback Ready Message
Diffstat (limited to 'tests/TestReady.java')
-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();
+ }
+}