@Override public void setStarted(final boolean started) { synchronized (lock) { boolean locked = lockDelivery(); // This is to make sure nothing would sneak to the client while started = false // the client will stop the session and perform a rollback in certain cases. // in case something sneaks to the client you could get to messaging delivering forever until // you restart the server try { this.started = browseOnly || started; } finally { if (locked) { lockDelivery.writeLock().unlock(); } } } // Outside the lock if (started) { promptDelivery(); } }
@Override public void setTransferring(final boolean transferring) { synchronized (lock) { // This is to make sure that the delivery process has finished any pending delivery // otherwise a message may sneak in on the client while we are trying to stop the consumer boolean locked = lockDelivery(); try { this.transferring = transferring; } finally { if (locked) { lockDelivery.writeLock().unlock(); } } } // Outside the lock if (transferring) { // And we must wait for any force delivery to be executed - this is executed async so we add a future to the // executor and // wait for it to complete FutureLatch future = new FutureLatch(); messageQueue.getExecutor().execute(future); boolean ok = future.await(10000); if (!ok) { ActiveMQServerLogger.LOGGER.errorTransferringConsumer(); } } if (!transferring) { promptDelivery(); } }