Java Code Examples for org.apache.activemq.broker.BrokerService#waitUntilStopped()

The following examples show how to use org.apache.activemq.broker.BrokerService#waitUntilStopped() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Broker.java    From reactive-integration-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception{
  final String brokerName = args[0];
  final String connector = args[1];
  final BrokerService broker = new BrokerService() {
    { // We use an instance-initializer to set up our broker service.
      this.setUseJmx(false);
      this.setSchedulerSupport(false);
      this.setPersistent(false);
      this.setAdvisorySupport(false);
      this.setBrokerName(brokerName);
      final String connectTo = this.addConnector(connector).getPublishableConnectString();
      System.out.println("MQ running on: " + connectTo);
    }
  };
  broker.start(); // Once we've configured the broker, we'll start it.
  System.in.read();
  broker.stop();
  broker.waitUntilStopped();
}
 
Example 2
Source File: ActiveMQResourceAdapter.java    From tomee with Apache License 2.0 6 votes vote down vote up
private void stopImpl() throws Exception {
    super.stop();
    final Collection<BrokerService> brokers = ActiveMQFactory.getBrokers();
    final Iterator<BrokerService> it = brokers.iterator();
    while (it.hasNext()) {
        final BrokerService bs = it.next();
        try {
            bs.stop();
            bs.waitUntilStopped();
        } catch (final Throwable t) {
            //Ignore
        }
        it.remove();
    }
    stopScheduler();
    Logger.getInstance(LogCategory.OPENEJB_STARTUP, ActiveMQResourceAdapter.class).getChildLogger("service").info("Stopped ActiveMQ broker");
}
 
Example 3
Source File: DuplexNetworkMBeanTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMbeanPresenceOnNetworkBrokerRestart() throws Exception {
   BrokerService broker = createBroker();
   try {
      broker.start();
      assertEquals(1, countMbeans(broker, "connector", 30000));
      assertEquals(0, countMbeans(broker, "connectionName"));
      BrokerService networkedBroker = null;
      for (int i = 0; i < numRestarts; i++) {
         networkedBroker = createNetworkedBroker();
         try {
            networkedBroker.start();
            assertEquals(1, countMbeans(networkedBroker, "networkBridge", 2000));
            assertEquals(1, countMbeans(broker, "networkBridge", 2000));
            assertEquals(2, countMbeans(broker, "connectionName"));
         } finally {
            networkedBroker.stop();
            networkedBroker.waitUntilStopped();
         }
         assertEquals(0, countMbeans(networkedBroker, "stopped"));
         assertEquals(0, countMbeans(broker, "networkBridge"));
      }

      assertEquals(0, countMbeans(networkedBroker, "networkBridge"));
      assertEquals(0, countMbeans(networkedBroker, "connector"));
      assertEquals(0, countMbeans(networkedBroker, "connectionName"));
      assertEquals(1, countMbeans(broker, "connector"));
   } finally {
      broker.stop();
      broker.waitUntilStopped();
   }
}
 
Example 4
Source File: DuplexNetworkMBeanTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMbeanPresenceOnBrokerRestart() throws Exception {

   BrokerService networkedBroker = createNetworkedBroker();
   try {
      networkedBroker.start();
      assertEquals(1, countMbeans(networkedBroker, "connector=networkConnectors", 30000));
      assertEquals(0, countMbeans(networkedBroker, "connectionName"));

      BrokerService broker = null;
      for (int i = 0; i < numRestarts; i++) {
         broker = createBroker();
         try {
            broker.start();
            assertEquals(1, countMbeans(networkedBroker, "networkBridge", 5000));
            assertEquals("restart number: " + i, 2, countMbeans(broker, "connectionName", 10000));
         } finally {
            broker.stop();
            broker.waitUntilStopped();
         }
         assertEquals(0, countMbeans(broker, "stopped"));
      }

      assertEquals(1, countMbeans(networkedBroker, "connector=networkConnectors"));
      assertEquals(0, countMbeans(networkedBroker, "connectionName"));
      assertEquals(0, countMbeans(broker, "connectionName"));
   } finally {
      networkedBroker.stop();
      networkedBroker.waitUntilStopped();
   }
}
 
Example 5
Source File: FailoverClusterTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void destroyBrokerCluster() throws JMSException, Exception {
   for (BrokerService b : brokers.values()) {
      try {
         b.stop();
         b.waitUntilStopped();
      } catch (Exception e) {
         // Keep on going, we want to try and stop them all.
         logger.info("Error while stopping broker[" + b.getBrokerName() + "] continuing...");
      }
   }
   brokers.clear();
}
 
Example 6
Source File: SearchSenderTest.java    From oneops with Apache License 2.0 4 votes vote down vote up
private void stopBroker(BrokerService searchBroker) throws Exception {
	searchBroker.stop();
	searchBroker.waitUntilStopped();
}
 
Example 7
Source File: SchedulerDBVersionTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void doTestScheduleRepeated(File existingStore) throws Exception {
   File testDir = new File("target/activemq-data/store/scheduler/versionDB");
   IOHelper.deleteFile(testDir);
   IOHelper.copyFile(existingStore, testDir);

   final int NUMBER = 10;
   ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost");

   for (int i = 0; i < 3; ++i) {
      JobSchedulerStoreImpl scheduler = new JobSchedulerStoreImpl();
      scheduler.setDirectory(testDir);
      scheduler.setJournalMaxFileLength(1024 * 1024);
      BrokerService broker = createBroker(scheduler);
      broker.start();
      broker.waitUntilStarted();

      final AtomicInteger count = new AtomicInteger();
      Connection connection = cf.createConnection();

      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Queue queue = session.createQueue("test.queue");

      MessageConsumer consumer = session.createConsumer(queue);

      final CountDownLatch latch = new CountDownLatch(NUMBER);
      consumer.setMessageListener(new MessageListener() {
         @Override
         public void onMessage(Message message) {
            LOG.info("Received scheduled message: {}", message);
            latch.countDown();
            count.incrementAndGet();
         }
      });

      connection.start();
      assertEquals(latch.getCount(), NUMBER);
      latch.await(30, TimeUnit.SECONDS);

      connection.close();
      broker.stop();
      broker.waitUntilStopped();

      assertEquals(0, latch.getCount());
   }
}
 
Example 8
Source File: FailoverClusterTestSupport.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected void stopBroker(String name) throws Exception {
   BrokerService broker = brokers.remove(name);
   broker.stop();
   broker.waitUntilStopped();
}
 
Example 9
Source File: NIOSSLBasicTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void stopBroker(BrokerService broker) throws Exception {
   if (broker != null) {
      broker.stop();
      broker.waitUntilStopped();
   }
}
 
Example 10
Source File: TestSupport.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void stopBrokerWithStoreFailure(BrokerService broker, PersistenceAdapterChoice choice) throws Exception {
   switch (choice) {
      case KahaDB:
         KahaDBPersistenceAdapter kahaDBPersistenceAdapter = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();

         // have the broker stop with an IOException on next checkpoint so it has a pending local transaction to recover
         kahaDBPersistenceAdapter.getStore().getJournal().close();
         break;
      default:
         // just stop normally by default
         broker.stop();
   }
   broker.waitUntilStopped();
}
 
Example 11
Source File: ActiveMQTestBase.java    From vertx-proton with Apache License 2.0 4 votes vote down vote up
public void stopBroker(BrokerService broker) throws Exception {
  if (broker != null) {
    broker.stop();
    broker.waitUntilStopped();
  }
}
 
Example 12
Source File: QpidJmsTestSupport.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public void stopBroker(BrokerService broker) throws Exception {
    if (broker != null) {
        broker.stop();
        broker.waitUntilStopped();
    }
}