MDC.put("activemq.connector", connector.getUri().toString()); Response response = null; boolean responseRequired = command.isResponseRequired(); int commandId = command.getCommandId(); try { if (status.get() != PENDING_STOP) { response = command.visit(this); } else { response = new ExceptionResponse(transportException.get()); if (e instanceof SecurityException || e.getCause() instanceof SecurityException) { SERVICELOG.warn("Security Error occurred on connection to: {}, {}", transport.getRemoteAddress(), e.getMessage()); response = new ExceptionResponse(e); } else { forceRollbackOnlyOnFailedAsyncTransactionOp(e, command); response = new Response(); response.setCorrelationId(commandId);
@Override public void onCommand(Object o) { Command command = (Command) o; if (command.isResponse()) { Integer id = new Integer(((Response) command).getCorrelationId()); RequestCounter rc = requestMap.get(id); if (rc != null) { if (rc.ackCount.decrementAndGet() <= 0) { requestMap.remove(id); transportListenerOnCommand(command); } } else { transportListenerOnCommand(command); } } else { transportListenerOnCommand(command); } }
public void onCompletion(FutureResponse future) { try { Response response = future.getResult(); if (response.isException()) { ExceptionResponse er = (ExceptionResponse)response; serviceLocalException(er.getException()); } else { dequeueCounter.incrementAndGet(); localBroker.oneway(new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, 1)); } } catch (IOException e) { serviceLocalException(e); } } };
if (command.isResponse()) { ResponseHandler rh = resposeHandlers.remove(Integer.valueOf(response.getCorrelationId())); if (rh != null) { rh.onResponse(this, response); } else { if (response.isException()) { Throwable exception = ((ExceptionResponse)response).getException(); handleException(exception, null); } else if (command.isMessageDispatch()) { StompSubscription sub = subscriptionsByConsumerId.get(md.getConsumerId()); if (sub != null) { sub.onMessageDispatch(md); } else if (command.getDataStructureType() == ConnectionError.DATA_STRUCTURE_TYPE) {
if (command.isResponse()) { Response response = (Response)command; ResponseHandler rh = resposeHandlers.remove(Integer.valueOf(response.getCorrelationId())); if (rh != null) { rh.onResponse(this, response); } else { if (response.isException()) { Throwable exception = ((ExceptionResponse)response).getException(); handleException(exception, null); } else if (command.isMessageDispatch()) { MessageDispatch md = (MessageDispatch)command; StompSubscription sub = subscriptionsByConsumerId.get(md.getConsumerId()); if (sub != null) { String ackId = null; if (version.equals(Stomp.V1_2) && sub.getAckMode() != Stomp.Headers.Subscribe.AckModeValues.AUTO && md.getMessage() != null) { AckEntry pendingAck = new AckEntry(md.getMessage().getMessageId().toString(), sub); ackId = this.ACK_ID_GENERATOR.generateId(); this.pedingAcks.put(ackId, pendingAck); } else if (command.getDataStructureType() == CommandTypes.KEEP_ALIVE_INFO) { stompTransport.sendToStomp(ping); } else if (command.getDataStructureType() == ConnectionError.DATA_STRUCTURE_TYPE) {
public void sendToActiveMQ(Command command, ResponseHandler handler) { // Lets intercept message send requests.. if (command instanceof ActiveMQMessage) { ActiveMQMessage msg = (ActiveMQMessage) command; try { if (!getPublishDollarTopics() && findSubscriptionStrategy().isControlTopic(msg.getDestination())) { // We don't allow users to send to $ prefixed topics to avoid failing MQTT 3.1.1 // specification requirements for system assigned destinations. if (handler != null) { try { handler.onResponse(this, new Response()); } catch (IOException e) { LOG.warn("Failed to send command " + command, e); } } return; } } catch (IOException e) { LOG.warn("Failed to send command " + command, e); } } command.setCommandId(generateCommandId()); if (handler != null) { command.setResponseRequired(true); resposeHandlers.put(command.getCommandId(), handler); } getMQTTTransport().sendToActiveMQ(command); }
} else { if (isDuplex()) { LOG.trace("{} duplex command type: {}", configuration.getBrokerName(), command.getDataStructureType()); message.setProducerId(duplexInboundLocalProducerInfo.getProducerId()); if (message.isResponseRequired() || configuration.isAlwaysSyncSend()) { duplexInboundLocalBroker.asyncRequest(message, new ResponseCallback() { final int correlationId = message.getCommandId(); duplexInboundLocalBroker.oneway(message); networkBridgeStatistics.getReceivedCount().increment(); } else { if (message.isResponseRequired() || configuration.isAlwaysSyncSend()) { Response reply = new Response(); reply.setCorrelationId(message.getCommandId()); remoteBroker.oneway(reply); case MessageAck.DATA_STRUCTURE_TYPE: MessageAck ack = (MessageAck) command; DemandSubscription localSub = subscriptionMapByRemoteId.get(ack.getConsumerId()); if (localSub != null) { ack.setConsumerId(localSub.getLocalInfo().getConsumerId());
/** * Un-marshal an object instance from the data input stream * * @param o the object to un-marshal * @param dataIn the data input stream to build the object from * @throws IOException */ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn) throws IOException { super.looseUnmarshal(wireFormat, o, dataIn); Response info = (Response)o; info.setCorrelationId(dataIn.readInt()); }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { Response info = (Response)o; super.looseMarshal(wireFormat, o, dataOut); dataOut.writeInt(info.getCorrelationId()); } }
if (command.isShutdownInfo()) { } else if (command instanceof RemoveInfo || command.isMessageAck()) { if (command.isResponseRequired()) { Response response = new Response(); response.setCorrelationId(command.getCommandId()); processCommand(response); MessageDispatch dispatch = new MessageDispatch(); dispatch.setConsumerId(pullRequest.getConsumerId()); dispatch.setDestination(pullRequest.getDestination()); processCommand(dispatch); transport.oneway(command); stateTracker.trackBack(command); if (command.isShutdownInfo()) {
protected void serviceRemoteCommand(Command command) { try { if (command.isMessageDispatch()) { MessageDispatch md = (MessageDispatch)command; command = md.getMessage(); } if (command.getDataStructureType() == CommandTypes.SHUTDOWN_INFO) { LOG.warn("The Master has shutdown"); shutDown(); } else { boolean responseRequired = command.isResponseRequired(); int commandId = command.getCommandId(); if (responseRequired) { Response response = (Response)localBroker.request(command); response.setCorrelationId(commandId); remoteBroker.oneway(response); } else { localBroker.oneway(command); } } } catch (IOException e) { serviceRemoteException(e); } }
protected void process(MultiplexerInput input, int realCorrelationId, Response response) throws IOException { if (response.isException()) { ExceptionResponse er = (ExceptionResponse) response; onFailure(er.getException()); } else { Response copy = new Response(); response.copy(copy); copy.setCorrelationId(realCorrelationId); input.oneway(copy); } }
try { response = resp.getResult(); if (response.isException()) { ExceptionResponse er = (ExceptionResponse)response; exception = er.getException();
? this.transport.request(command, timeout) : this.transport.request(command)); if (response.isException()) { ExceptionResponse er = (ExceptionResponse)response; if (er.getException() instanceof JMSException) { throw (JMSException)er.getException(); } else { if (isClosed() || closing.get()) { jmsEx = JMSExceptionSupport.create(er.getException()); } catch(Throwable e) { LOG.error("Caught an exception trying to create a JMSException for " +er.getException(),e);
@Override public void run() { try { // While waiting for space to free up... the // message may have expired. if (message.isExpired()) { broker.messageExpired(context, message, null); getDestinationStatistics().getExpired().increment(); } else { doMessageSend(producerExchange, message); } if (sendProducerAck) { ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), message .getSize()); context.getConnection().dispatchAsync(ack); } else { Response response = new Response(); response.setCorrelationId(message.getCommandId()); context.getConnection().dispatchAsync(response); } } catch (Exception e) { if (!sendProducerAck && !context.isInRecoveryMode()) { ExceptionResponse response = new ExceptionResponse(e); response.setCorrelationId(message.getCommandId()); context.getConnection().dispatchAsync(response); } } } });
public void onActiveMQCommand(Command command) throws Exception { if (command.isResponse()) { Response response = (Response)command; Handler<Response> handler = responseHandlers.remove(new Integer(response.getCorrelationId())); if (handler != null) { handler.handle(response); } else { LOG.warn("No handler for response: " + response); } } else if (command.isMessageDispatch()) { MessageDispatch md = (MessageDispatch)command; Handler<MessageDispatch> handler = subscriptionsByConsumerId.get(md.getConsumerId()); if (handler != null) { handler.handle(md); } else { LOG.warn("No handler for message: " + md); } } }
protected void processCommand(Object o) { try { Command command = (Command) o; Response response = command.visit(this); if (response != null) { //we are processing this locally - not via the Broker response.setCorrelationId(command.getCommandId()); oneway(response); } } catch (Throwable e) { onFailure(e); } }
@Override public void onCompletion(FutureResponse resp) { try { Response reply = resp.getResult(); reply.setCorrelationId(correlationId); remoteBroker.oneway(reply); //increment counter when messages are received in duplex mode networkBridgeStatistics.getReceivedCount().increment(); } catch (IOException error) { LOG.error("Exception: {} on duplex forward of: {}", error, message); serviceRemoteException(error); } } });
private void processCommand(Object incoming) { Command command = (Command) incoming; if (command == null) { return; } if (command.isResponse()) { Object object = null; synchronized (requestMap) { object = requestMap.remove(Integer.valueOf(((Response) command).getCorrelationId())); } if (object != null && object.getClass() == Tracked.class) { ((Tracked) object).onResponses(command); } } if (command.isConnectionControl()) { handleConnectionControl((ConnectionControl) command); } else if (command.isConsumerControl()) { ConsumerControl consumerControl = (ConsumerControl)command; if (consumerControl.isClose()) { stateTracker.processRemoveConsumer(consumerControl.getConsumerId(), RemoveInfo.LAST_DELIVERED_UNKNOWN); } } if (transportListener != null) { transportListener.onCommand(command); } }
/** * @return a new object instance */ public DataStructure createObject() { return new Response(); }