public void start() throws Exception { if (transportListener == null) { throw new IOException("TransportListener not set."); } try { enqueueValve.turnOff(); if (messageQueue != null && !async) { Object command; while ((command = messageQueue.poll()) != null && !stopping.get() ) { receiveCounter++; dispatch(this, transportListener, command); } } started = true; wakeup(); } finally { enqueueValve.turnOn(); } // If we get stopped while starting up, then do the actual stop now // that the enqueueValve is back on. if( stopping.get() ) { stop(); } }
protected void dispatch(final ConnectionContext context, Message message) throws Exception { // AMQ-2586: Better to leave this stat at zero than to give the user // misleading metrics. // destinationStatistics.getMessages().increment(); destinationStatistics.getEnqueues().increment(); dispatchValve.increment(); MessageEvaluationContext msgContext = null; try { if (!subscriptionRecoveryPolicy.add(context, message)) { return; } synchronized (consumers) { if (consumers.isEmpty()) { onMessageWithNoConsumers(context, message); return; } } msgContext = context.getMessageEvaluationContext(); msgContext.setDestination(destination); msgContext.setMessageReference(message); if (!dispatchPolicy.dispatch(message, msgContext, consumers)) { onMessageWithNoConsumers(context, message); } } finally { dispatchValve.decrement(); if (msgContext != null) { msgContext.clear(); } } }