@Override public void bufferReceived(Object connectionID, ActiveMQBuffer buffer) { try { dataReceived = true; Command command = (Command) wireFormat.unmarshal(buffer); boolean responseRequired = command.isResponseRequired(); int commandId = command.getCommandId(); // the connection handles pings, negotiations directly. // and delegate all other commands to manager. if (command.getClass() == KeepAliveInfo.class) { KeepAliveInfo info = (KeepAliveInfo) command; info.setResponseRequired(false); // if we don't respond to KeepAlive commands then the client will think the server is dead // and timeout // for some reason KeepAliveInfo.isResponseRequired() is always false protocolManager.sendReply(this, info); } else if (command.getClass() == WireFormatInfo.class) { // amq here starts a read/write monitor thread (detect ttl?) negotiate((WireFormatInfo) command); } else if (command.getClass() == ConnectionInfo.class || command.getClass() == ConsumerInfo.class || command.getClass() == RemoveInfo.class || command.getClass() == SessionInfo.class || command.getClass() == ProducerInfo.class || ActiveMQMessage.class.isAssignableFrom(command.getClass()) || command.getClass() == MessageAck.class || command.getClass() == TransactionInfo.class || command.getClass() == DestinationInfo.class || command.getClass() == ShutdownInfo.class || command.getClass() == RemoveSubscriptionInfo.class) { Response response = null; if (pendingStop) { response = new ExceptionResponse(this.stopError); } else { response = ((Command) command).visit(this); if (response instanceof ExceptionResponse) { if (!responseRequired) { Throwable cause = ((ExceptionResponse) response).getException(); serviceException(cause); response = null; } } } if (responseRequired) { if (response == null) { response = new Response(); } } // The context may have been flagged so that the response is not // sent. if (context != null) { if (context.isDontSendReponse()) { context.setDontSendReponse(false); response = null; } } if (response != null && !protocolManager.isStopping()) { response.setCorrelationId(commandId); dispatchSync(response); } } else { // note!!! wait for negotiation (e.g. use a countdown latch) // before handling any other commands this.protocolManager.handleCommand(this, command); } } catch (IOException e) { ActiveMQServerLogger.LOGGER.error("error decoding", e); } catch (Throwable t) { ActiveMQServerLogger.LOGGER.error("error decoding", t); } }