Ejemplo n.º 1
0
  public void start() throws Exception {
    int c;

    channel = new JChannel();
    channel.connect("PullPushTestMux");
    adapter = new PullPushAdapter(channel);
    adapter.setListener(this);

    listeners = new MyListener[10];
    for (int i = 0; i < listeners.length; i++) {
      listeners[i] = new MyListener(i, adapter);
    }

    while ((c = choice()) != 'q') {
      c -= 48;
      if (c < 0 || c > 9) {
        System.err.println("Choose between 0 and 9");
        continue;
      }
      if (c == 0) adapter.send(new Message(null, null, "Message from default message listener"));
      else listeners[c].sendMessage();
    }

    channel.close();
    System.exit(0);
  }
Ejemplo n.º 2
0
 MyListener(int id, PullPushAdapter ad) {
   this.id = new Integer(id);
   this.ad = ad;
   ad.registerListener(this.id, this);
 }
Ejemplo n.º 3
0
 void sendMessage() throws Exception {
   Message msg = new Message(null, null, "Message from " + id);
   ad.send(id, msg);
 }