Package edu.emory.mathcs.backport.java.util.concurrent

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


            artifactCollector.collect( artifacts, originatingArtifact, managedVersions, localRepository,
                                       remoteRepositories, source, filter, listeners );

        List resolvedArtifacts = Collections.synchronizedList( new ArrayList() );
        List missingArtifacts = Collections.synchronizedList( new ArrayList() );
        CountDownLatch latch = new CountDownLatch( artifactResolutionResult.getArtifactResolutionNodes().size() );
        Map nodesByGroupId = new HashMap();
        for ( Iterator i = artifactResolutionResult.getArtifactResolutionNodes().iterator(); i.hasNext(); )
        {
            ResolutionNode node = (ResolutionNode) i.next();
            List nodes = (List) nodesByGroupId.get( node.getArtifact().getGroupId() );
            if ( nodes == null )
            {
                nodes = new ArrayList();
                nodesByGroupId.put( node.getArtifact().getGroupId(), nodes );
            }
            nodes.add( node );
        }

        List resolutionExceptions = Collections.synchronizedList( new ArrayList() );
        try
        {
            for ( Iterator i = nodesByGroupId.values().iterator(); i.hasNext(); )
            {
                List nodes = (List) i.next();
                resolveArtifactPool.execute( new ResolveArtifactTask( resolveArtifactPool, latch, nodes,
                                                                      localRepository, resolvedArtifacts,
                                                                      missingArtifacts, resolutionExceptions ) );
            }
            latch.await();
        }
        catch ( InterruptedException e )
        {
            throw new ArtifactResolutionException( "Resolution interrupted", null, e );
        }
View Full Code Here

            int nb = Integer.parseInt(args[0]);
            int th = 30;
            if (args.length > 1) {
                th = Integer.parseInt(args[1]);
            }
            latch = new CountDownLatch(nb);
            ExecutorService threadPool = Executors.newFixedThreadPool(th);
            for (int i = 0; i < nb; i++) {
                threadPool.submit(new JMSClient());
            }
            latch.await();
View Full Code Here

            int nb = Integer.parseInt(args[0]);
            int th = 30;
            if (args.length > 1) {
                th = Integer.parseInt(args[1]);
            }
            latch = new CountDownLatch(nb);
            ExecutorService threadPool = Executors.newFixedThreadPool(th);
            for (int i = 0; i < nb; i++) {
                threadPool.submit(new JMSClient());
            }
            latch.await();
View Full Code Here

        // Prevent broker startup. Broker must be run manually.
    }

    public void test() throws Exception
    {
        _failedOver = new CountDownLatch(1);

        _connection = new AMQConnection("amqp://guest:guest@client/test?brokerlist='localhost?retries='20'&connectdelay='2000''");

        _session = _connection.createSession(true, Session.SESSION_TRANSACTED);
        _queue = _session.createQueue("QAtest");
View Full Code Here

        if (args.length == 0) {
            new JMSClient().run();
        } else {
            GeronimoWorkManager wm = createWorkManager(30);
            int nb = Integer.parseInt(args[0]);
            latch = new CountDownLatch(nb);
            for (int i = 0; i < nb; i++) {
                wm.scheduleWork(new JMSClient());
            }
            latch.await();
            wm.doStop();
View Full Code Here

    public void doTestWakeup() throws InterruptedException, BrokenBarrierException {
       
        final AtomicInteger iterations = new AtomicInteger(0);
        final AtomicInteger counter = new AtomicInteger(0);
        final AtomicInteger queue = new AtomicInteger(0);
        final CountDownLatch doneCountDownLatch = new CountDownLatch(1);
        final int ENQUEUE_COUNT = 100000;
       
        TaskRunnerFactory factory = new TaskRunnerFactory();       
        final TaskRunner runner = factory.createTaskRunner(new Task() {           
            public boolean iterate() {
                if( queue.get()==0 ) {
                    return false;
                } else {
                    while(queue.get()>0) {
                        queue.decrementAndGet();
                        counter.incrementAndGet();
                    }
                    iterations.incrementAndGet();
                    if (counter.get()==ENQUEUE_COUNT)
                        doneCountDownLatch.countDown();
                    return true;
                }
            }
        }, "Thread Name");
       
        long start = System.currentTimeMillis();
        final int WORKER_COUNT=5;
        final CyclicBarrier barrier = new CyclicBarrier(WORKER_COUNT+1);
        for( int i=0; i< WORKER_COUNT; i++ ) {
            new Thread() {
                public void run() {
                    try {
                        barrier.await();
                        for( int i=0; i < ENQUEUE_COUNT/WORKER_COUNT; i++ ) {
                            queue.incrementAndGet();
                            runner.wakeup();
                            yield();
                        }
                    }
                    catch (BrokenBarrierException e) {
                    }
                    catch (InterruptedException e) {
                    }       
                }
            }.start();
        }
        barrier.await();
       
        boolean b = doneCountDownLatch.await(30, TimeUnit.SECONDS);
        long end = System.currentTimeMillis();
        log.info("Iterations: "+iterations.get());
        log.info("counter: "+counter.get());
        log.info("Dequeues/s: "+(1000.0*ENQUEUE_COUNT/(end-start)));
        log.info("duration: "+((end-start)/1000.0));
View Full Code Here

                      }
                  }
                 
                    localBridgeStarted.set(false);
                    remoteBridgeStarted.set(false);
                    startedLatch = new CountDownLatch(2);
                }
               
            }
   
            public void transportResumed(){               
View Full Code Here

        assertNoMessagesLeft(connection1);

        assertNotNull(receiveMessage(connection2));
        assertNoMessagesLeft(connection2);
       
        final CountDownLatch publishDone = new CountDownLatch(1);
       
        // The MockTransport is on the remote connection.
        // Slip in a new transport filter after the MockTransport
        MockTransport mt = (MockTransport) connection3.getTransport().narrow(MockTransport.class);
        mt.install(new TransportFilter(mt.getNext()) {
            public void oneway(Object command) throws IOException {
                log.info("Dropping: "+command);
                // just eat it! to simulate a recent failure.
            }
        });
               
        // Send a message (async) as this will block
        new Thread() {
            public void run() {
                // Send the message using the fail over publisher.
                try {
                    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                publishDone.countDown();
            }
        }.start();
       
        // Assert that we block:
        assertFalse( publishDone.await(3, TimeUnit.SECONDS)  );
       
        // Restart the remote server.  State should be re-played and the publish should continue.
        remoteURI = remoteConnector.getServer().getConnectURI().toString();
        restartRemoteBroker();

        // This should reconnect, and resend
        assertTrue( publishDone.await(10, TimeUnit.SECONDS)  );

    }
View Full Code Here

      MessageConsumer consumer = session.createConsumer(queueB);

      // Test sending to Queue B it should block.
      // Since even though  the it's queue limits have not been reached, the connection
      // is blocked.
      CountDownLatch pubishDoneToQeueuB = asyncSendTo(queueB, "Message 1");
      assertTrue( pubishDoneToQeueuB.await(2, TimeUnit.SECONDS) );
     
      TextMessage msg = (TextMessage) consumer.receive();
      assertEquals("Message 1", msg.getText());
      msg.acknowledge();
     
      pubishDoneToQeueuB = asyncSendTo(queueB, "Message 2");
      assertTrue( pubishDoneToQeueuB.await(2, TimeUnit.SECONDS) );
     
      msg = (TextMessage) consumer.receive();
      assertEquals("Message 2", msg.getText());
      msg.acknowledge();
    }
View Full Code Here

TOP

Related Classes of edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch

Copyright © 2018 www.massapicom. 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.