aboutsummaryrefslogtreecommitdiff
path: root/tests/SendNowSelf.java
blob: ef3df0c295732af84c5020a38e3698985ebc50ef (plain)
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
/**
 * Ivy java library API tester.
 * TODO does not work if there is anotehr agent on the bus ...? FIXME 
 *
 * @author  Yannick Jestin <mailto:yannick.jestin@enac.fr>
 *
 * (c) ENAC
 *
 * usage: java Unitaire
 *
 */
import fr.dgac.ivy.*;

public class SendNowSelf {

  Ivy bus;

  public SendNowSelf(String domain) {
    bus = new Ivy("SendNowSelf" , null, null);
    try {
      System.out.println("starting sender");
      bus.sendToSelf(true);
      bus.bindMsg("^hop hop", new IvyMessageListener() {
	public void receive(IvyClient ic, String args[]){
	  System.out.println("stopping");
	  bus.stop();
	  System.out.println("end stopping");
	}
      });
      bus.start(domain);
      System.out.println("sending");
      if ( bus.sendMsg("hop hop") != 1) {
	System.out.println("error, lock, hop hop not received");
	System.exit(-1);
      }
    } catch (IvyException ie) {
      System.out.println("Ivy main test error");
      ie.printStackTrace();
    }
  }

  public static void main(final String[] args) throws IvyException,InterruptedException {
    new SendNowSelf(Ivy.getDomainArgs("SendNowSelf" , args));
  }

}