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

Examples of edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger


    public synchronized void addMessage(ConnectionContext context,Message message) throws IOException{
        int subscriberCount=subscriberAcks.size();
        if(subscriberCount>0){
            String id=message.getMessageId().toString();
            ackContainer.put(id,new AtomicInteger(subscriberCount));
            for(Iterator i=subscriberAcks.keySet().iterator();i.hasNext();){
                Object key=i.next();
                ListContainer container=store.getListContainer(key,"durable-subs");
                container.add(id);
            }
View Full Code Here


                String id=messageId.toString();
                ListContainer container=(ListContainer)subscriberAcks.get(subcriberId);
                if(container!=null){
                    // container.remove(id);
                    container.removeFirst();
                    AtomicInteger count=(AtomicInteger)ackContainer.remove(id);
                    if(count!=null){
                        if(count.decrementAndGet()>0){
                            ackContainer.put(id,count);
                        }else{
                            // no more references to message messageContainer so remove it
                            messageContainer.remove(messageId.toString());
                        }
View Full Code Here

            String id=messageId.toString();
            ListContainer container=(ListContainer)subscriberAcks.get(subcriberId);
            if(container!=null){
                // container.remove(id);
                container.removeFirst();
                AtomicInteger count=(AtomicInteger)ackContainer.remove(id);
                if(count!=null){
                    if(count.decrementAndGet()>0){
                        ackContainer.put(id,count);
                    }else{
                        // no more references to message messageContainer so remove it
                        messageContainer.remove(messageId.toString());
                    }
View Full Code Here

        String key=getSubscriptionKey(clientId,subscriptionName);
        subscriberContainer.remove(key);
        ListContainer list=(ListContainer)subscriberAcks.get(key);
        for(Iterator i=list.iterator();i.hasNext();){
            String id=i.next().toString();
            AtomicInteger count=(AtomicInteger)ackContainer.remove(id);
            if(count!=null){
                if(count.decrementAndGet()>0){
                    ackContainer.put(id,count);
                }else{
                    // no more references to message messageContainer so remove it
                    messageContainer.remove(id);
                }
View Full Code Here

        super.setUp();
        createBroker(new URI("broker:(tcp://localhost:61616)/BrokerA?persistent=false&useJmx=false"));
        createBroker(new URI("broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=false"));

        bridges = new ArrayList();
        msgDispatchCount = new AtomicInteger(0);
    }
View Full Code Here

*/
public class AtomicIntegerMarshaller implements Marshaller{
  

    public void writePayload(Object object,DataOutput dataOut) throws IOException{
       AtomicInteger ai = (AtomicInteger) object;
       dataOut.writeInt(ai.get());
      
    }
View Full Code Here

      
    }

    public Object readPayload(DataInput dataIn) throws IOException{
        int value = dataIn.readInt();
        return new AtomicInteger(value);
    }
View Full Code Here

        profilerPause("Benchmark ready.  Start profiler ");
       
        long start = System.currentTimeMillis();
       
       
        final AtomicInteger receiveCounter = new AtomicInteger(0);
        for( int i=0; i < CONSUMER_COUNT; i++) {
            new Thread() {
                public void run() {
                    try {
                       
                        // Consume the messages    
                        StubConnection connection = new StubConnection(broker);
                        ConnectionInfo connectionInfo = createConnectionInfo();
                        connection.send(connectionInfo);

                        SessionInfo sessionInfo = createSessionInfo(connectionInfo);
                        ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
                        consumerInfo.setPrefetchSize(1000);
                        connection.send(sessionInfo);
                        connection.send(consumerInfo);
                       
                        consumersStarted.release();
                       
                        while( receiveCounter.get() < CONSUME_COUNT ) {
               
                            int counter=0;
                            // Get a least 1 message.
                            Message msg = receiveMessage(connection, 2000);
                            if( msg!=null ) {
                                printer.increment();
                                receiveCounter.incrementAndGet();
                               
                                counter++;
                               
                                // Try to piggy back a few extra message acks if they are ready.
                                Message extra=null;
                                while( (extra = receiveMessage(connection,0))!=null ) {
                                    msg=extra;
                                    printer.increment();
                                    receiveCounter.incrementAndGet();
                                    counter++;
                                }
                            }
                           
                           
                            if(msg!=null) {
                                connection.send(createAck(consumerInfo, msg, counter, MessageAck.STANDARD_ACK_TYPE));
                            } else if ( receiveCounter.get() < CONSUME_COUNT )  {
                                System.out.println("Consumer stall, waiting for message #"+receiveCounter.get()+1);
                            }
                        }
                       
                        connection.send(closeConsumerInfo(consumerInfo));                       
                    } catch (Throwable e) {
View Full Code Here

        final Command command;
        final AtomicInteger ackCount;
       
        RequestCounter(Command command, int count) {
            this.command = command;
            this.ackCount = new AtomicInteger(count);
        }
View Full Code Here

                new Byte(ActiveMQDestination.TEMP_QUEUE_TYPE),
                new Byte(ActiveMQDestination.TEMP_TOPIC_TYPE) });
    }
    public void testMessageListenerWithConsumerCanBeStopped() throws Exception {

        final AtomicInteger counter = new AtomicInteger(0);
        final CountDownLatch done1 = new CountDownLatch(1);
        final CountDownLatch done2 = new CountDownLatch(1);
       
        // Receive a message with the JMS API
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        destination = createDestination(session, destinationType);
        ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) session.createConsumer(destination);
        consumer.setMessageListener(new MessageListener() {
            public void onMessage(Message m) {
                counter.incrementAndGet();
                if( counter.get()==1 )
                    done1.countDown();
                if( counter.get()==2 )
                    done2.countDown();
            }
        });

        // Send a first message to make sure that the consumer dispatcher is running
        sendMessages(session, destination, 1);
        assertTrue(done1.await(1, TimeUnit.SECONDS));
        assertEquals(1, counter.get());

        // Stop the consumer.
        consumer.stop();

        // Send a message, but should not get delivered.
        sendMessages(session, destination, 1);
        assertFalse(done2.await(1, TimeUnit.SECONDS));
        assertEquals(1, counter.get());
       
        // Start the consumer, and the message should now get delivered.
        consumer.start();
        assertTrue(done2.await(1, TimeUnit.SECONDS));
        assertEquals(2, counter.get());
    }
View Full Code Here

TOP

Related Classes of edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger

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.