aboutsummaryrefslogtreecommitdiff
path: root/tests/Filter.java
blob: 92ef19012f8402d2b29438125120cd24bbb5127d (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
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
/**
 * Another Ivy java library API tester: filters
 *
 * @author  Yannick Jestin <mailto:jestin@cena.fr>
 *
 * (c) CENA
 *
 * usage: java Request
 *
 * Changelog
 *   1.2.16 : first release
 *
 *   rationale:
 *   	Filter limits the bounded sends to  toto and blah
 *   	Remote subscribes to (.*), unbounded, and truc, bounded
 *   	Filter sends truc ble bli (should have one hit only )
 *   	Filter sends TOTO rules, one hit
 *   	total should be 3 (ready message)
 *
 */
import fr.dgac.ivy.*;

class Filter {

  public static void main(String[] args) throws IvyException {
    String domain=Ivy.getDomainArgs("FilterTest",args);
    new Filter(domain);
  }

  int nb=0;
  private Ivy bus;
  private String[] filterStrings = { "toto", "blah" };

  public Filter(String domain) throws IvyException {
    bus = new Ivy("FilterTest","FilterTest ready", null);
    bus.setFilter(filterStrings);
    bus.start(domain);
    new Remote(domain);
    IvyClient remote = bus.waitForClient("Remote", 0);
    bus.sendMsg("truc ble bli");
    bus.sendMsg("TOTO rules");
    remote.sendDie("goodbye");
    bus.stop();
    if (nb != 3) {
      System.out.println("n = "+nb+" should be 3");
      System.exit(-1);
    }
    System.out.println("Filter test successful");
  }

  private class Remote implements IvyMessageListener {
    Ivy bus;
    String name;
    public Remote(String domain) throws IvyException {
      bus = new Ivy("Remote","Remote ready",null);
      bus.bindMsg("^truc (.*)",this);
      bus.bindMsg("(.*)", new IvyMessageListener() {
	public void receive(IvyClient ic,String[] args) {
	  System.out.println("something received: "+args[0]);
	  nb++;
	}
      });
      bus.start(domain);
    }
    
    public void receive(IvyClient ic,String[] args) {
      System.out.println("truc received"+args[0]);
      nb++;
    }

  }

}