Examples of CountDownLatch


Examples of edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch

     *
     * @throws Exception
     */
  public void xtestOneWayInJmsOutPojo() throws Exception {
   
    final CountDownLatch receivedCountDown = new CountDownLatch(1);
   
        // Configure the components
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
        container.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
        PojoComponent component = new PojoComponent();
        component.addService("listener", new MessageListener(){
      public void onMessage(Message msg) {
        System.out.println("Received: "+msg);
        receivedCountDown.countDown();       
      }
    });
        container.addComponent("default", component);

        // lets add a jms -> pojo route
        container.addRoutes(new RouteBuilder() {
            public void configure() {
                from("jms:test").to("pojo:listener");
            }
        });
       
        container.start();
       
        // Send a message to the JMS endpoint
        JmsEndpoint endpoint = (JmsEndpoint) container.getEndpoint("jms:test");       
        Producer<JmsExchange> producer = endpoint.createProducer();
        JmsExchange exchange = producer.createExchange();
        JmsMessage in = exchange.getIn();
        in.setBody("Hello");
        in.setHeader("cheese", 123);
        producer.process(exchange);
       
        // The Activated endpoint should send it to the pojo due to the configured route.
        assertTrue("The message ware received by the Pojo", receivedCountDown.await(5, TimeUnit.SECONDS));
       

  }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

   
    protected  void testhelper(boolean useDispatcher) throws Throwable {
        final int count=8;

        final ExecutorService executor=Executors.newFixedThreadPool(count);
        final CountDownLatch latch=new CountDownLatch(count);
        final JChannel[] channels=new JChannel[count];
        final Task[] tasks=new Task[count];

        final long start=System.currentTimeMillis();
        for(int i=0;i < count;i++) {
            if(i == 0)
                channels[i]=createChannel(true, count);
            else
                channels[i]=createChannel(channels[0]);
           
            tasks[i]=new Task(latch, channels[i],useDispatcher);
            changeMergeInterval(channels[i]);
            changeViewBundling(channels[i]);
            replaceDiscoveryProtocol(channels[i]);
        }

        for(final Task t:tasks) {
            executor.execute(t);
        }

        int timeoutToConverge=120;
        boolean successConnecting  = false;
        try {
            // Wait for all channels to finish connecting
            successConnecting=latch.await(timeoutToConverge, TimeUnit.SECONDS);           
            if(successConnecting) {
                log.info("All connected. Converging...");
                for(Task t:tasks) {
                    Throwable ex=t.getException();
                    if(ex != null)
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

        Message msg=createMessage(local_addr, sender, 1L, oob, true);
        unicast.up(new Event(Event.MSG, msg));
        Util.sleep(500);


        final CountDownLatch latch=new CountDownLatch(1);
        Adder[] adders=new Adder[num_threads];
        for(int i=0; i < adders.length; i++) {
            adders[i]=new Adder(unicast, latch, counter, seqno, oob, local_addr, sender);
            adders[i].start();
        }

        long start=System.currentTimeMillis();
        latch.countDown(); // starts all adders

        lock.lock();
        try {
            while(delivered_msgs.get() < num_msgs) {
                try {
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

        Message msg=createMessage(local_addr, sender, 1L, oob, true);
        unicast.up(new Event(Event.MSG, msg));
        Util.sleep(500);


        final CountDownLatch latch=new CountDownLatch(1);
        Sender[] adders=new Sender[num_threads];
        for(int i=0; i < adders.length; i++) {
            adders[i]=new Sender(unicast, latch, counter, seqno, oob, local_addr, sender);
            adders[i].start();
        }

        long start=System.currentTimeMillis();
        latch.countDown(); // starts all adders

        lock.lock();
        try {
            while(delivered_msgs.get() < num_msgs) {
                try {
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

        MutableDigest digest=new MutableDigest();
        digest.add(local_addr, 0, 0, 0);
        digest.add(sender, 0, 0, 0);
        nak.down(new Event(Event.SET_DIGEST, digest));

        final CountDownLatch latch=new CountDownLatch(1);
        Sender[] adders=new Sender[num_threads];
        for(int i=0; i < adders.length; i++) {
            adders[i]=new Sender(nak, latch, counter, seqno, oob, sender);
            adders[i].start();
        }

        long start=System.currentTimeMillis();
        latch.countDown(); // starts all adders

        lock.lock();
        try {
            while(delivered_msgs.get() < num_msgs) {
                try {
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

    public static void testConcurrentAdds() throws InterruptedException {
        AckReceiverWindow win=new AckReceiverWindow(1);
        final int NUM=100;
        final int NUM_THREADS=10;
        final CountDownLatch latch=new CountDownLatch(1);

        final Adder[] adders=new Adder[NUM_THREADS];
        for(int i=0; i < adders.length; i++) {
            adders[i]=new Adder(1, NUM, 10, win, latch);
        }
        for(Adder adder: adders)
            adder.start();

        latch.countDown();

        for(Adder adder: adders)
            adder.join();

        System.out.println("win = " + win);
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

    @Test(invocationCount=10)
    public static void testConcurrentAddsAndRemoves() throws InterruptedException {
        AckReceiverWindow win=new AckReceiverWindow(1);
        final int NUM=100;
        final int NUM_THREADS=10;
        final CountDownLatch latch=new CountDownLatch(1);

        final Adder[] adders=new Adder[NUM_THREADS];
        for(int i=0; i < adders.length; i++) {
            adders[i]=new Adder(1, NUM, 10, win, latch);
            adders[i].start();
        }

        final AtomicInteger count=new AtomicInteger(NUM);
        final Remover[] removers=new Remover[NUM_THREADS];
        for(int i=0; i < removers.length; i++) {
            removers[i]=new Remover(win, latch, count);
            removers[i].start();
        }

        latch.countDown();

        for(Adder adder: adders)
            adder.join();

        int total=0;
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

  @Test
  public void simpleConcurrentGetRequestTest() {
    int nThreads = 8;
    int nRequests = 2048;
    final CountDownLatch latch = new CountDownLatch(nRequests);
    ExecutorService executor = Executors.newFixedThreadPool(nThreads);

    for (int i = 1; i <= nRequests; i++) {
      executor.submit(new Runnable() {

        @Override
        public void run() {
          try {
            doSimpleGetRequest();
            latch.countDown();
          } catch (Exception e) {
            e.printStackTrace();
          }
        }

      });
    }
    try {
      latch.await(15 * 1000, TimeUnit.MILLISECONDS)// max wait time
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    if (latch.getCount() != 0) {
      assertTrue("Did not finish " + nRequests + " # of requests", false);
    }
  }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

  }

  @Test
  public void timeoutTest() throws InterruptedException {
    long now = System.currentTimeMillis();
    final CountDownLatch latch = new CountDownLatch(5);
    final AsyncCallback cb = new AsyncCallback() {

      @Override public void onCallback() { latch.countDown(); }

    };

    Timeout t1 = new Timeout(now+1000, cb);
    Timeout t2 = new Timeout(now+1200, cb);
    Timeout t3 = new Timeout(now+1400, cb);
    Timeout t4 = new Timeout(now+1600, cb);
    Timeout t5 = new Timeout(now+1800, cb);
    IOLoop.INSTANCE.addTimeout(t1);
    IOLoop.INSTANCE.addTimeout(t2);
    IOLoop.INSTANCE.addTimeout(t3);
    IOLoop.INSTANCE.addTimeout(t4);
    IOLoop.INSTANCE.addTimeout(t5);

    latch.await(5 * 1000, TimeUnit.MILLISECONDS);
    assertTrue(latch.getCount() == 0);
  }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

    assertTrue(latch.getCount() == 0);
  }
 
  @Test
  public void callbackTest() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(5);
    final AsyncCallback cb = new AsyncCallback() {

      @Override public void onCallback() { latch.countDown(); }
   
    };
    IOLoop.INSTANCE.addCallback(cb);
    IOLoop.INSTANCE.addCallback(cb);
    IOLoop.INSTANCE.addCallback(cb);
    IOLoop.INSTANCE.addCallback(cb);
    IOLoop.INSTANCE.addCallback(cb);
   
    latch.await(5 * 1000, TimeUnit.MILLISECONDS);
    assertTrue(latch.getCount() == 0);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.