Пример #1
0
  /** Stops unicast and multicast receiver threads */
  void stopThreads() {
    Thread tmp;

    // 1. Stop the multicast receiver thread
    if (mcast_receiver != null) {
      if (mcast_receiver.isAlive()) {
        tmp = mcast_receiver;
        mcast_receiver = null;
        closeMulticastSocket(); // will cause the multicast thread to terminate
        tmp.interrupt();
        try {
          tmp.join(100);
        } catch (Exception e) {
        }
        tmp = null;
      }
      mcast_receiver = null;
    }

    // 2. Stop the unicast receiver thread
    if (ucast_receiver != null) {
      ucast_receiver.stop();
      ucast_receiver = null;
    }

    // 3. Stop the in_packet_handler thread
    if (incoming_packet_handler != null) {
      incoming_packet_handler.stop();
    }
  }
Пример #2
0
 synchronized void waitUntilCompleted(long timeout, boolean resume) {
   if (thread != null) {
     try {
       thread.join(timeout);
     } catch (InterruptedException e) {
       Thread.currentThread().interrupt(); // set interrupt flag again
     }
     thread = null; // Added after Brian noticed that ViewHandler leaks class loaders
   }
   if (resume) resumeForce();
 }
Пример #3
0
  protected void stopFlusher() {
    flushing = false;
    Thread tmp = flusher;

    while (tmp != null && tmp.isAlive()) {
      tmp.interrupt();
      ack_promise.setResult(null);
      try {
        tmp.join();
      } catch (InterruptedException e) {
      }
    }
  }
  /**
   * Tests concurrent reception of multiple messages with a different conn_id
   * (https://issues.jboss.org/browse/JGRP-1347)
   */
  public void testMultipleConcurrentResets() throws Exception {
    sendAndCheck(a, b_addr, 1, r2);

    // now close connection on A unilaterally
    System.out.println("==== Closing the connection on A");
    removeConnection(u1, b_addr);

    r2.clear();

    final UNICAST unicast = (UNICAST) b.getProtocolStack().findProtocol(UNICAST.class);

    int NUM = 10;

    final List<Message> msgs = new ArrayList<Message>(NUM);

    for (int i = 1; i <= NUM; i++) {
      Message msg = new Message(b_addr, a_addr, "m" + i);
      UNICAST.UnicastHeader hdr = UNICAST.UnicastHeader.createDataHeader(1, (short) 2, true);
      msg.putHeader(unicast.getId(), hdr);
      msgs.add(msg);
    }

    Thread[] threads = new Thread[NUM];
    final CyclicBarrier barrier = new CyclicBarrier(NUM + 1);
    for (int i = 0; i < NUM; i++) {
      final int index = i;
      threads[i] =
          new Thread() {
            public void run() {
              try {
                barrier.await();
                unicast.up(new Event(Event.MSG, msgs.get(index)));
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          };
      threads[i].start();
    }

    barrier.await();
    for (Thread thread : threads) thread.join();

    List<Message> list = r2.getMessages();
    System.out.println("list = " + print(list));

    assert list.size() == 1
        : "list must have 1 element but has " + list.size() + ": " + print(list);
  }
Пример #5
0
  /** Tests 2 channels calling FLUSH simultaneously */
  @Test
  public void testConcurrentFlush() throws Exception {
    c1 = createChannel(true, 2);
    c1.connect("testConcurrentFlush");
    c2 = createChannel(c1);
    c2.connect("testConcurrentFlush");

    assertViewsReceived(c1, c2);

    final CountDownLatch startFlushLatch = new CountDownLatch(1);
    final CountDownLatch stopFlushLatch = new CountDownLatch(1);
    final CountDownLatch flushStartReceived = new CountDownLatch(2);
    final CountDownLatch flushStopReceived = new CountDownLatch(2);

    Thread t1 =
        new Thread() {
          public void run() {
            try {
              startFlushLatch.await();
              boolean rc = Util.startFlush(c1);
              System.out.println("t1: rc=" + rc);
            } catch (InterruptedException e) {
              interrupt();
            }

            try {
              stopFlushLatch.await();
            } catch (InterruptedException e) {
              interrupt();
            } finally {
              c1.stopFlush();
            }
          }
        };

    Thread t2 =
        new Thread() {
          public void run() {
            try {
              startFlushLatch.await();
              boolean rc = Util.startFlush(c2);
              System.out.println("t2: rc=" + rc);
            } catch (InterruptedException e) {
              interrupt();
            }

            try {
              stopFlushLatch.await();
            } catch (InterruptedException e) {
              interrupt();
            } finally {
              c2.stopFlush();
            }
          }
        };

    Listener l1 = new Listener("c1", c1, flushStartReceived, flushStopReceived);
    Listener l2 = new Listener("c2", c2, flushStartReceived, flushStopReceived);
    t1.start();
    t2.start();

    startFlushLatch.countDown();

    assertTrue(flushStartReceived.await(60, TimeUnit.SECONDS));

    // at this stage both channels should have started a flush
    stopFlushLatch.countDown();

    t1.join();
    t2.join();

    assertTrue(flushStopReceived.await(60, TimeUnit.SECONDS));

    assert l1.blockReceived;
    assert l1.unblockReceived;
    assert l2.blockReceived;
    assert l2.unblockReceived;
  }
Пример #6
0
  /** Tests 2 channels calling partial FLUSHes and one calling FLUSH simultaneously */
  @Test
  public void testConcurrentFlushAndPartialFlush() throws Exception {
    c1 = createChannel(true, 3);
    c1.connect("testConcurrentFlushAndPartialFlush");

    c2 = createChannel(c1);
    c2.connect("testConcurrentFlushAndPartialFlush");

    c3 = createChannel(c1);
    c3.connect("testConcurrentFlushAndPartialFlush");
    assertViewsReceived(c1, c2, c3);

    final CountDownLatch startFlushLatch = new CountDownLatch(1);
    final CountDownLatch stopFlushLatch = new CountDownLatch(1);

    // 2 because either total or partial has to finish first
    final CountDownLatch flushStartReceived = new CountDownLatch(2);

    // 5 because we have total and partial flush
    final CountDownLatch flushStopReceived = new CountDownLatch(5);

    Thread t1 =
        new Thread() {
          public void run() {
            try {
              startFlushLatch.await();
              boolean rc = Util.startFlush(c1);
              System.out.println("t1: rc=" + rc);
            } catch (InterruptedException e) {
              interrupt();
            }

            try {
              stopFlushLatch.await();
            } catch (InterruptedException e) {
              interrupt();
            } finally {
              c1.stopFlush();
            }
          }
        };

    Thread t2 =
        new Thread() {
          public void run() {
            try {
              startFlushLatch.await();
              // partial, only between c2 and c3
              boolean rc = Util.startFlush(c2, (Arrays.asList(c2.getAddress(), c3.getAddress())));
              System.out.println("t2: partial flush rc=" + rc);
            } catch (InterruptedException e) {
              interrupt();
            }

            try {
              stopFlushLatch.await();
            } catch (InterruptedException e) {
              interrupt();
            } finally {
              c2.stopFlush(Arrays.asList(c2.getAddress(), c3.getAddress()));
            }
          }
        };

    Listener l1 = new Listener("c1", c1, flushStartReceived, flushStopReceived);
    Listener l2 = new Listener("c2", c2, flushStartReceived, flushStopReceived);
    Listener l3 = new Listener("c3", c3, flushStartReceived, flushStopReceived);

    t1.start();
    t2.start();

    startFlushLatch.countDown();

    assertTrue(flushStartReceived.await(60, TimeUnit.SECONDS));

    // at this stage both channels should have started a flush?
    stopFlushLatch.countDown();

    t1.join();
    t2.join();

    assertTrue(flushStopReceived.await(60, TimeUnit.SECONDS));

    assert l1.blockReceived;
    assert l1.unblockReceived;
    assert l2.blockReceived;
    assert l2.unblockReceived;
    assert l3.blockReceived;
    assert l3.unblockReceived;
  }