public void testBroadcastSequence() throws Exception {
    r1 = new MyReceiver(ch1.getLocalAddress());
    ch1.setReceiver(r1);
    r2 = new MyReceiver(ch2.getLocalAddress());
    ch2.setReceiver(r2);

    // use concurrent senders to send messages to the group

    Thread thread1 =
        new Thread() {
          public void run() {
            Util.sleep(300);
            for (int i = 1; i <= NUM_MSGS; i++) {
              try {
                ch1.send(new Message(null, null, new Integer(i)));
              } catch (Exception e) {
                throw new RuntimeException(e);
              }
              System.out.print("-- messages sent thread 1: " + i + "/" + NUM_MSGS + "\r");
            }
          }
        };

    Thread thread2 =
        new Thread() {
          public void run() {
            Util.sleep(300);
            for (int i = 1; i <= NUM_MSGS; i++) {
              try {
                ch2.send(new Message(null, null, new Integer(i)));
              } catch (Exception e) {
                throw new RuntimeException(e);
              }
              System.out.print("-- messages sent thread 2: " + i + "/" + NUM_MSGS + "\r");
            }
          }
        };

    thread1.start();
    thread2.start();
    thread1.join();
    thread2.join();

    System.out.println("");
    System.out.println("-- verifying messages on ch1 and ch2");
    verifyNumberOfMessages(NUM_MSGS * 2);
    verifyMessageOrder(r1.getMsgs());
    verifyMessageOrder(r2.getMsgs());
    verifySameOrder();
  }
예제 #2
0
 /** {@inheritDoc} */
 @Override
 public void receive(final Message message) {
   final String msg = (String) message.getObject();
   if (message.getSrc() != jchannel.getLocalAddress()) {
     if (msg != null) {
       receivedMessages.offer(msg);
       if (bc != null) {
         bc.broadcast(msg);
       }
     }
   }
 }