/** * A helper method to block the caller thread until the broker has been * stopped */ public void waitUntilStopped() { while (isStarted() && !stopped.get()) { try { stoppedLatch.await(); } catch (InterruptedException e) { // ignore } } }
/** * Create a view of a running Broker * @param brokerService */ public MessageBrokerView(BrokerService brokerService){ this.brokerService = brokerService; if (brokerService == null){ throw new NullPointerException("BrokerService is null"); } if (!brokerService.isStarted()){ throw new IllegalStateException("BrokerService " + brokerService.getBrokerName() + " is not started"); } }
/** * A helper method to block the caller thread until the broker has fully started * * @param timeout * the amount of time to wait before giving up and returning false. * * @return boolean true if wait succeeded false if broker was not started or was stopped */ public boolean waitUntilStarted(long timeout) { boolean waitSucceeded = isStarted(); long expiration = Math.max(0, timeout + System.currentTimeMillis()); while (!isStarted() && !stopped.get() && !waitSucceeded && expiration > System.currentTimeMillis()) { try { if (getStartException() != null) { return waitSucceeded; } waitSucceeded = startedLatch.await(100L, TimeUnit.MILLISECONDS); } catch (InterruptedException ignore) { } } return waitSucceeded; }
/** * Create a view of a running Broker * @param brokerName */ public MessageBrokerView(String brokerName){ this.brokerService = BrokerRegistry.getInstance().lookup(brokerName); if (brokerService == null){ throw new NullPointerException("BrokerService is null"); } if (!brokerService.isStarted()){ throw new IllegalStateException("BrokerService " + brokerService.getBrokerName() + " is not started"); } }
private void stopActiveMqBrokerAndAwait() throws Exception { logger.debug("Stopping ActiveMQ broker and will await shutdown"); if (!this.activeMQBroker.isStarted()) { logger.debug("Broker not running"); return; } final CountDownLatch latch = new CountDownLatch(1); this.activeMQBroker.addShutdownHook(new Runnable() { public void run() { latch.countDown(); } }); this.activeMQBroker.stop(); assertTrue("Broker did not stop", latch.await(5, TimeUnit.SECONDS)); logger.debug("Broker stopped"); }
if (broker == null || waitForStart > 0) { final long expiry = System.currentTimeMillis() + waitForStart; while ((broker == null || !broker.isStarted()) && System.currentTimeMillis() - expiry < 0) { long timeout = Math.max(0, expiry - System.currentTimeMillis()); if (broker == null) { if (broker != null && !broker.isStarted()) { LOG.debug("waiting for broker named: " + brokerName + " to start"); timeout = Math.max(0, expiry - System.currentTimeMillis());
@Override public void handle(IOException exception) { if (!broker.isStarted() || ignoreAllErrors) { allowIOResumption(); LOG.info("Ignoring IO exception, " + exception, exception);
/** * A helper method to block the caller thread until the broker has been * stopped */ public void waitUntilStopped() { while (isStarted() && !stopped.get()) { try { stoppedLatch.await(); } catch (InterruptedException e) { // ignore } } }
/** * A helper method to block the caller thread until the broker has been * stopped */ public void waitUntilStopped() { while (isStarted() && !stopped.get()) { try { stoppedLatch.await(); } catch (InterruptedException e) { // ignore } } }
public void stop() { if (broker.isStarted()) { try { broker.stop(); } catch (Exception ignored) { } } }
/** * Create a view of a running Broker * @param brokerService */ public MessageBrokerView(BrokerService brokerService){ this.brokerService = brokerService; if (brokerService == null){ throw new NullPointerException("BrokerService is null"); } if (!brokerService.isStarted()){ throw new IllegalStateException("BrokerService " + brokerService.getBrokerName() + " is not started"); } }
/** * Create a view of a running Broker * @param brokerService */ public MessageBrokerView(BrokerService brokerService){ this.brokerService = brokerService; if (brokerService == null){ throw new NullPointerException("BrokerService is null"); } if (!brokerService.isStarted()){ throw new IllegalStateException("BrokerService " + brokerService.getBrokerName() + " is not started"); } }
/** * Create a view of a running Broker * @param brokerService */ public MessageBrokerView(BrokerService brokerService){ this.brokerService = brokerService; if (brokerService == null){ throw new NullPointerException("BrokerService is null"); } if (!brokerService.isStarted()){ throw new IllegalStateException("BrokerService " + brokerService.getBrokerName() + " is not started"); } }
/** * Create a view of a running Broker * @param brokerName */ public MessageBrokerView(String brokerName){ this.brokerService = BrokerRegistry.getInstance().lookup(brokerName); if (brokerService == null){ throw new NullPointerException("BrokerService is null"); } if (!brokerService.isStarted()){ throw new IllegalStateException("BrokerService " + brokerService.getBrokerName() + " is not started"); } }
public int getBrokerAmqpConnectorPort() { if (brokerService == null || !brokerService.isStarted()) { throw new IllegalStateException("Broker must be started first."); } try { return brokerService.getTransportConnectorByName(AMQP_CONNECTOR_NAME).getPublishableConnectURI().getPort(); } catch (Exception e) { throw new RuntimeException(); } }
@AfterClass public static void stopBroker() throws Exception { if (broker.isStarted()) { broker.stop(); } } }
@AfterClass public static void stopBroker() throws Exception{ if(broker.isStarted()){ broker.stop(); } } }
public void startBroker() throws Exception { if (brokerService != null && brokerService.isStarted()) { throw new IllegalStateException("Broker already started."); } brokerService = createBroker("localhost", true); brokerService.start(); brokerService.waitUntilStarted(); }
@BeforeClass public static void startBroker() throws Exception { broker = new BrokerService(); broker.setPersistent(false); broker.addConnector("tcp://127.0.0.1:61616"); broker.start(); if (!broker.isStarted()) { throw new Exception("Couldn't start the broker!"); } }
@BeforeClass public static void startBroker() throws Exception { broker = new BrokerService(); broker.setPersistent(false); broker.addConnector("tcp://127.0.0.1:61616"); broker.start(); if (!broker.isStarted()) { throw new Exception("Couldn't start the broker!"); } }