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

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


        .createQueue(QUEUE_NAME));

    // The runnable is likely to interrupt during the session#commit, since
    // this takes the longest
    final Object starter = new Object();
    final AtomicBoolean restarted = new AtomicBoolean();
    new Thread(new Runnable() {
      public void run() {
        try {
          synchronized (starter) {
            starter.wait();
          }

          // Simulate broker failure & restart
          bs.stop();
          bs = new BrokerService();
          bs.setPersistent(true);
          bs.setUseJmx(true);
          bs.addConnector(tcpUri);
          bs.start();

          restarted.set(true);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }).start();

    synchronized (starter) {
      starter.notifyAll();
    }
    for (int i = 0; i < MESSAGE_COUNT; i++) {
      Message message = consumer.receive(500);
      assertNotNull("No Message " + i + " found", message);

      if (i < 10)
        assertFalse("Timing problem, restarted too soon", restarted
            .get());
      if (i == 10) {
        synchronized (starter) {
          starter.notifyAll();
        }
      }
      if (i > MESSAGE_COUNT - 100) {
        assertTrue("Timing problem, restarted too late", restarted
            .get());
      }

      assertEquals(i, message.getIntProperty(PROPERTY_MSG_NUMBER));
      session.commit();
View Full Code Here


        .createQueue(QUEUE_NAME));

    // The runnable is likely to interrupt during the session#commit, since
    // this takes the longest
    final Object starter = new Object();
    final AtomicBoolean restarted = new AtomicBoolean();
    new Thread(new Runnable() {
      public void run() {
        try {
          synchronized (starter) {
            starter.wait();
          }

          // Simulate broker failure & restart
          bs.stop();
          bs = new BrokerService();
          bs.setPersistent(true);
          bs.setUseJmx(true);
          bs.addConnector(tcpUri);
          bs.start();

          restarted.set(true);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }).start();

    synchronized (starter) {
      starter.notifyAll();
    }
    Collection<Integer> results = new ArrayList<Integer>(MESSAGE_COUNT);
    for (int i = 0; i < MESSAGE_COUNT; i++) {
      Message message1 = consumer1.receive(20);
      Message message2 = consumer2.receive(20);
      if (message1 == null && message2 == null) {
        if (results.size() < MESSAGE_COUNT) {
          message1 = consumer1.receive(500);
          message2 = consumer2.receive(500);

          if (message1 == null && message2 == null) {
            // Missing messages
            break;
          }
        }
        break;
      }

      if (i < 10)
        assertFalse("Timing problem, restarted too soon", restarted
            .get());
      if (i == 10) {
        synchronized (starter) {
          starter.notifyAll();
        }
      }
      if (i > MESSAGE_COUNT - 50) {
        assertTrue("Timing problem, restarted too late", restarted
            .get());
      }

      if (message1 != null) {
        results.add(message1.getIntProperty(PROPERTY_MSG_NUMBER));
View Full Code Here

        final int COUNT = 1024;
        byte[] data = new byte[DATA_LENGTH];
        for (int i = 0;i < data.length;i++) {
            data[i] = TEST_DATA;
        }
        final AtomicBoolean complete = new AtomicBoolean(false);
        Thread runner = new Thread(new Runnable() {
            public void run() {
                try {
                    for (int x = 0;x < COUNT;x++) {
                        byte[] b = new byte[2048];
                        in.readFully(b);
                        for (int i = 0;i < b.length;i++) {
                            assertTrue(b[i] == TEST_DATA);
                        }
                    }
                    complete.set(true);
                    synchronized(complete){
                        complete.notify();
                    }
                }
                catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        runner.start();
        for (int i = 0;i < COUNT;i++) {
            out.write(data);
        }
        out.flush();
        synchronized (complete) {
            if (!complete.get()) {
                complete.wait(30000);
            }
        }
        assertTrue(complete.get());
    }
View Full Code Here

      assertFalse( pubishDoneToQeueuB.await(2, TimeUnit.SECONDS) );     
    }


  private void fillQueue(final ActiveMQQueue queue) throws JMSException, InterruptedException {
    final AtomicBoolean done = new AtomicBoolean(true);
    final AtomicBoolean keepGoing = new AtomicBoolean(true);
   
    // Starts an async thread that every time it publishes it sets the done flag to false.
    // Once the send starts to block it will not reset the done flag anymore.
    new Thread("Fill 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);
          while( keepGoing.get() ) {
            done.set(false);
            producer.send(session.createTextMessage("Hello World"));           
          }
        } catch (JMSException e) {
        } finally {
          safeClose(session);
        }
      }
    }.start();
   
    while( true ) {
      Thread.sleep(1000);
      // the producer is blocked once the done flag stays true.
      if( done.get() )
        break;
      done.set(true);
    }   
    keepGoing.set(false);
  }
View Full Code Here

     * any setup methods. As a rule, this method is used only when you are not sure, if the setUp and tearDown method
     * is propagated correctly.
     */
    public void startAutoFailThread() {
        setAutoFail(true);
        isTestSuccess = new AtomicBoolean(false);
        autoFailThread = new Thread(new Runnable() {
            public void run() {
                try {
                    // Wait for test to finish succesfully
                    Thread.sleep(getMaxTestTime());
View Full Code Here

    }

    public MessageId getNextMessageIdToDeliver(String clientId,String subscriptionName,MessageId id) throws Exception{
       
        final MessageId result = new MessageId();
        final AtomicBoolean initalized = new AtomicBoolean();
        TransactionContext c = persistenceAdapter.getTransactionContext();
        try {
            long sequence = id != null ? id.getBrokerSequenceId() : -1;
           adapter.doGetNextDurableSubscriberMessageIdStatement(c, destination, clientId, subscriptionName,sequence,new JDBCMessageRecoveryListener() {
               public void recoverMessage(long sequenceId, byte[] data) throws Exception {
                   Message msg = (Message) wireFormat.unmarshal(new ByteSequence(data));
                   msg.getMessageId().setBrokerSequenceId(sequenceId);
                   result.setBrokerSequenceId(msg.getMessageId().getBrokerSequenceId());
                   initalized.set(true);
                  
               }
               public void recoverMessageReference(String reference) throws Exception {
                   result.setValue(reference);
                   initalized.set(true);
                  
               }
              
               public void finished(){         
               }
           });
          
              
        } catch (SQLException e) {
            JDBCPersistenceAdapter.log("JDBC Failure: ",e);
            throw IOExceptionSupport.create("Failed to get next MessageId to deliver: " + clientId + ". Reason: " + e, e);
        } finally {
            c.close();
        }
        return initalized.get () ? result : null;
    }
View Full Code Here

        return initalized.get () ? result : null;
    }
   
    public MessageId getPreviousMessageIdToDeliver(String clientId,String subscriptionName,MessageId id) throws Exception{
        final MessageId result = new MessageId();
        final AtomicBoolean initalized = new AtomicBoolean();
        TransactionContext c = persistenceAdapter.getTransactionContext();
        try {
            long sequence = id != null ? id.getBrokerSequenceId() : -1;
           adapter.doGetPrevDurableSubscriberMessageIdStatement(c, destination, clientId, subscriptionName,sequence,new JDBCMessageRecoveryListener() {
               public void recoverMessage(long sequenceId, byte[] data) throws Exception {
                   Message msg = (Message) wireFormat.unmarshal(new ByteSequence(data));
                   msg.getMessageId().setBrokerSequenceId(sequenceId);
                   result.setProducerId(msg.getMessageId().getProducerId());
                   result.setProducerSequenceId(msg.getMessageId().getProducerSequenceId());
                   result.setBrokerSequenceId(msg.getMessageId().getBrokerSequenceId());
                   initalized.set(true);
                  
               }
               public void recoverMessageReference(String reference) throws Exception {
                   result.setValue(reference);
                   initalized.set(true);
                  
               }
              
               public void finished(){         
               }
           });
          
              
        } catch (SQLException e) {
            JDBCPersistenceAdapter.log("JDBC Failure: ",e);
            throw IOExceptionSupport.create("Failed to get next MessageId to deliver: " + clientId + ". Reason: " + e, e);
        } finally {
            c.close();
        }
        return initalized.get () ? result : null;
    }
View Full Code Here

   
   
    public AsyncBaseLifeCycle(BaseComponent component) {
        this.component = component;
        this.logger = component.logger;
        this.running = new AtomicBoolean(false);
        this.polling = new AtomicBoolean(false);
        this.processors = new ConcurrentHashMap();
    }
View Full Code Here

            final AxisHttpConnection conn, final IOProcessorCallback callback) {
        super();
        this.httpservice = httpservice;
        this.conn = conn;
        this.callback = callback;
        this.terminated = new AtomicBoolean(false);

        id = counter.incrementAndGet();
    }
View Full Code Here

    private String brokerURL = "vm://localhost?broker.persistent=false";

    protected long idGenerator=0;

    public void setUp() throws Exception {
        final AtomicBoolean connected = new AtomicBoolean(false);
        TransportConnector connector;

        // Start up a broker with a tcp connector.
        try {
            broker = BrokerFactory.createBroker(new URI(this.brokerURL));
            String brokerId = broker.getBrokerName();
            connector = new TransportConnector(broker.getBroker(), TransportFactory.bind(brokerId,new URI(this.brokerURL))) {
                // Hook into the connector so we can assert that the server accepted a connection.
                protected org.apache.activemq.broker.Connection createConnection(org.apache.activemq.transport.Transport transport) throws IOException {
                    connected.set(true);
                    return super.createConnection(transport);
                }
            };
            connector.start();
            broker.start();
View Full Code Here

TOP

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

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.