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

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


      acf1 = createConnectionFactory(URL1);
      acf2 = createConnectionFactory(URL2);

      Thread.sleep(1000);

      doneLatch = new CountDownLatch(NUM_MESSAGE_TO_SEND*MAX_PRODUCERS);

      container1 = createDefaultMessageListenerContainer(acf2, new TestMessageListener1(500), QUEUE1_NAME);
      container1.afterPropertiesSet();
      container2 = createDefaultMessageListenerContainer(acf2, new TestMessageListener1(30000), QUEUE2_NAME);
      container2.afterPropertiesSet();
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

      fillQueue(queueA);

      // 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");
      assertFalse( pubishDoneToQeueuB.await(2, TimeUnit.SECONDS) );     
    }
View Full Code Here

    }   
    keepGoing.set(false);
  }

  private CountDownLatch asyncSendTo(final ActiveMQQueue queue, final String message) throws JMSException {
    final CountDownLatch done = new CountDownLatch(1);
    new Thread("Send thread.") {
      public void run() {
        Session session=null;
          try {
          session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
          MessageProducer producer = session.createProducer(queue);
          producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
          producer.send(session.createTextMessage(message));
          done.countDown();
        } catch (JMSException e) {
        } finally {
          safeClose(session);
        }
      }
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", originatingArtifact, e );
        }
View Full Code Here

        final SubscribeWait waiter = new SubscribeWait(workspaces.length,
                                                       this.pr,
                                                       this.name,
                                                       this.executor);

        final CountDownLatch targetLatch = waiter.getTargetLatch();
        final CountDownLatch terminationLatch = waiter.getTerminationLatch();

        for (int i = 0; i < workspaces.length; i++) {
            // in poll mode, the polling master creates RP query threads via
            // the track* methods
            this.registerListeners(this.eitherMaster,
View Full Code Here

        } else {
            this.executor = executorService;
            this.privateExecutor = false;
        }

        this.targetLatch = new CountDownLatch(this.targetNumber);
        this.terminationLatch = new CountDownLatch(this.targetNumber);
        this.exitLatch = new CountDownLatch(1);
    }
View Full Code Here

public class VmPipeSessionCrossCommunicationTest extends TestCase {
    public void testOneSessionTalkingBackAndForthDoesNotDeadlock() throws Exception {
        final VmPipeAddress address = new VmPipeAddress( 1 );
        final IoConnector connector = new VmPipeConnector();
        final AtomicReference c1 = new AtomicReference();
        final CountDownLatch latch = new CountDownLatch( 1 );
        final CountDownLatch messageCount = new CountDownLatch( 2 );
        IoAcceptor acceptor = new VmPipeAcceptor();

        acceptor.bind( address, new IoHandlerAdapter() {
            public void messageReceived( IoSession session, Object message ) throws Exception {
                System.out.println( Thread.currentThread().getName() + ": " + message );

                if ( "start".equals( message ) ) {
                    session.write( "open new" );
                } else if ( "re-use c1".equals( message ) ) {
                    session.write( "tell me something on c1 now" );
                } else if ( ( (String) message ).startsWith( "please don't deadlock" ) ) {
                    messageCount.countDown();
                } else {
                    fail( "unexpected message received " + message );
                }
            }
        } );

        connector.getDefaultConfig().setThreadModel( ThreadModel.MANUAL );

        ConnectFuture future = connector.connect( address, new IoHandlerAdapter() {
            public void messageReceived( IoSession session, Object message ) throws Exception {
                System.out.println( Thread.currentThread().getName() + ": " + message );
               
                if ( "open new".equals( message ) ) {
                    System.out.println( "opening c2 from " + Thread.currentThread().getName() );

                    ConnectFuture c2Future = connector.connect( address, new IoHandlerAdapter() {
                        public void sessionOpened( IoSession session ) throws Exception {
                            session.write( "re-use c1" );
                        }

                        public void messageReceived( IoSession session, Object message ) throws Exception {
                            System.out.println( Thread.currentThread().getName() + ": " + message );

                            if ( "tell me something on c1 now".equals( message ) ) {
                                latch.countDown();
                                ((IoSession) c1.get()).write( "please don't deadlock via c1" );
                            } else {
                                fail( "unexpected message received " + message );
                            }
                        }
                    } );

                    c2Future.join();

                    latch.await();

                    c2Future.getSession().write( "please don't deadlock via c2" );
                } else {
                    fail( "unexpeced message received " + message );
                }
            }
        } );

        future.join();

        c1.set( future.getSession() );
        ((IoSession) c1.get()).write( "start" );

        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();

        while ( !messageCount.await( 100, TimeUnit.MILLISECONDS ) ) {
            long[] threads = threadMXBean.findMonitorDeadlockedThreads();

            if ( null != threads ) {
                StringBuffer sb = new StringBuffer( 256 );
                ThreadInfo[] infos = threadMXBean.getThreadInfo( threads, Integer.MAX_VALUE );
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

    /* (non-Javadoc)
     * @see javax.resource.spi.work.WorkManager#startWork(javax.resource.spi.work.Work)
     */
    public long startWork(final Work work) throws WorkException {
        final CountDownLatch latch = new CountDownLatch(1);
        executor.execute(new Work() {
            public void release() {
                work.release();
            }
            public void run() {
                latch.countDown();
                work.run();
            }
        });
        long t = System.currentTimeMillis();
        try {
            latch.await();
        } catch (InterruptedException e) {
            throw new WorkException("Interrupted", e);
        }
        return System.currentTimeMillis() - t;
    }
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.