1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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();
}
}
|