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 Response(); response.setCorrelationId(commandId);
protected void serviceLocalCommand(Command command) { if (!disposed.get()) { try { if (command.isMessageDispatch()) { safeWaitUntilStarted(); networkBridgeStatistics.getEnqueues().increment(); final MessageDispatch md = (MessageDispatch) command; final DemandSubscription sub = subscriptionMapByLocalId.get(md.getConsumerId()); if (sub != null && md.getMessage() != null && sub.incrementOutstandingResponses()) { configuration.getBrokerName(), remoteBrokerName, Arrays.toString(md.getMessage().getBrokerPath()), md.getMessage() }); localBroker.oneway(new MessageAck(md, MessageAck.INDIVIDUAL_ACK_TYPE, 1)); } finally { sub.decrementOutstandingResponses(); } else if (command.isBrokerInfo()) { futureLocalBrokerInfo.set((BrokerInfo) command); } else if (command.isShutdownInfo()) { LOG.info("{} Shutting down {}", configuration.getBrokerName(), configuration.getName()); stop(); } else if (command.getClass() == ConnectionError.class) { ConnectionError ce = (ConnectionError) command; serviceLocalException(ce.getException()); } else { switch (command.getDataStructureType()) { case WireFormatInfo.DATA_STRUCTURE_TYPE: break;
@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 oneway(Object o) throws IOException { Command command = (Command)o; command.setCommandId(sequenceGenerator.getNextSequenceId()); command.setResponseRequired(false); next.oneway(command); }
/** * @param command * @return */ private boolean isFanoutCommand(Command command) { if (command.isMessage()) { if (fanOutQueues) { return true; } return ((Message) command).getDestination().isTopic(); } if (command.getDataStructureType() == ConsumerInfo.DATA_STRUCTURE_TYPE || command.getDataStructureType() == RemoveInfo.DATA_STRUCTURE_TYPE) { return false; } return true; }
public FutureResponse asyncRequest(Object o, ResponseCallback responseCallback) throws IOException { Command command = (Command) o; command.setCommandId(sequenceGenerator.getNextSequenceId()); command.setResponseRequired(true); FutureResponse future = new FutureResponse(responseCallback, this); IOException priorError = null; synchronized (requestMap) { priorError = this.error; if (priorError == null) { requestMap.put(new Integer(command.getCommandId()), future); } } if (priorError != null) { future.set(new ExceptionResponse(priorError)); throw priorError; } next.oneway(command); return future; }
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) { Throwable exception = ((ConnectionError)command).getException(); handleException(exception, null);
protected void serviceRemoteCommand(Command command) { if (!disposed.get()) { try { if (command.isMessageDispatch()) { safeWaitUntilStarted(); MessageDispatch md = (MessageDispatch) command; serviceRemoteConsumerAdvisory(md.getMessage().getDataStructure()); ackAdvisory(md.getMessage()); } else if (command.isBrokerInfo()) { futureRemoteBrokerInfo.set((BrokerInfo) command); } else if (command instanceof BrokerSubscriptionInfo) { serviceRemoteException(ce.getException()); } else { if (isDuplex()) { LOG.trace("{} duplex command type: {}", configuration.getBrokerName(), command.getDataStructureType()); if (command.isMessage()) { final ActiveMQMessage message = (ActiveMQMessage) command; if (NetworkBridgeFilter.isAdvisoryInterpretedByNetworkBridge(message)) { switch (command.getDataStructureType()) { case ConnectionInfo.DATA_STRUCTURE_TYPE: if (duplexInitiatingConnection != null && duplexInitiatingConnectionInfoReceived.compareAndSet(false, true)) { switch (command.getDataStructureType()) { case KeepAliveInfo.DATA_STRUCTURE_TYPE: case WireFormatInfo.DATA_STRUCTURE_TYPE:
@Override public void dispatchAsync(Command message) { if (!stopping.get()) { if (taskRunner == null) { dispatchSync(message); } else { synchronized (dispatchQueue) { dispatchQueue.add(message); } try { taskRunner.wakeup(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } else { if (message.isMessageDispatch()) { MessageDispatch md = (MessageDispatch) message; TransmitCallback sub = md.getTransmitCallback(); broker.postProcessDispatch(md); if (sub != null) { sub.onFailure(); } } } }
protected void doStop() throws Exception { LOG.debug("Stopping connection: {}", transport.getRemoteAddress()); connector.onStopped(this); try { transport.stop(); LOG.debug("Stopped transport: {}", transport.getRemoteAddress()); } catch (Exception e) { LOG.debug("Could not stop transport to {}. This exception is ignored.", transport.getRemoteAddress(), e); for (Iterator<Command> iter = dispatchQueue.iterator(); iter.hasNext(); ) { Command command = iter.next(); if (command.isMessageDispatch()) { MessageDispatch md = (MessageDispatch) command; TransmitCallback sub = md.getTransmitCallback(); broker.postProcessDispatch(md); if (sub != null) { connectionStates = listConnectionStates(); for (TransportConnectionState cs : connectionStates) { cs.getContext().getStopping().set(true); try { LOG.debug("Cleaning up connection resources: {}", getRemoteAddress());
@Override public void onActiveMQCommand(Command command) throws Exception { if (command.isResponse()) { Response response = (Response) command; ResponseHandler rh = resposeHandlers.remove(Integer.valueOf(response.getCorrelationId())); if (rh != null) { rh.onResponse(this, response); } else { } else if (command.isMessageDispatch()) { MessageDispatch dispatch = (MessageDispatch) command; AmqpSender sender = subscriptionsByConsumerId.get(dispatch.getConsumerId()); if (sender != null) { if (dispatch.getMessage() != null) { LOG.trace("Finished Dispatch of MessageId: {} to consumer", dispatch.getMessage().getMessageId()); } else if (command.getDataStructureType() == ConnectionError.DATA_STRUCTURE_TYPE) { Throwable exception = ((ConnectionError) command).getException(); handleException(exception); } else if (command.isConsumerControl()) { ConsumerControl control = (ConsumerControl) command; AmqpSender sender = subscriptionsByConsumerId.get(control.getConsumerId()); if (sender != null) { sender.onConsumerControl(control); } else if (command.isBrokerInfo()) {
void sendToActiveMQ(Command command, ResponseHandler handler) { command.setCommandId(lastCommandId.incrementAndGet()); if (handler != null) { command.setResponseRequired(true); resposeHandlers.put(Integer.valueOf(command.getCommandId()), handler); } amqpTransport.sendToActiveMQ(command); }
protected void processDispatch(Command command) throws IOException { MessageDispatch messageDispatch = (MessageDispatch) (command.isMessageDispatch() ? command : null); try { if (!stopping.get()) { if (messageDispatch != null) { try { TransmitCallback sub = messageDispatch.getTransmitCallback(); broker.postProcessDispatch(messageDispatch); if (sub != null) { } else { if (TRANSPORTLOG.isDebugEnabled()) { TRANSPORTLOG.debug("Unexpected exception on asyncDispatch, command of type: " + command.getDataStructureType(), e); TransmitCallback sub = messageDispatch.getTransmitCallback(); broker.postProcessDispatch(messageDispatch); if (sub != null) {
if (stateTracker.track(command) == null && command.isResponseRequired()) { int size = fanout ? minAckCount : 1; requestMap.put(new Integer(command.getCommandId()), new RequestCounter(command, size)); if (th.transport != null) { try { th.transport.oneway(command); } catch (IOException e) { LOG.debug("Send attempt: failed."); primary.transport.oneway(command); } catch (IOException e) { LOG.debug("Send attempt: failed.");
public void restore(Transport transport) throws IOException { // Restore the connections. for (Iterator<ConnectionState> iter = connectionStates.values().iterator(); iter.hasNext();) { ConnectionState connectionState = iter.next(); connectionState.getInfo().setFailoverReconnect(true); if (LOG.isDebugEnabled()) { LOG.debug("conn: " + connectionState.getInfo().getConnectionId()); } transport.oneway(connectionState.getInfo()); restoreTempDestinations(transport, connectionState); if (restoreSessions) { restoreSessions(transport, connectionState); } if (restoreTransaction) { restoreTransactions(transport, connectionState); } } // now flush messages and MessagePull commands. for (Command msg : messageCache.values()) { if (LOG.isDebugEnabled()) { LOG.debug("command: " + (msg.isMessage() ? ((Message) msg).getMessageId() : msg)); } transport.oneway(msg); } }
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; MQTTSubscription sub = findSubscriptionStrategy().getSubscription(md.getConsumerId()); if (sub != null) { MessageAck ack = sub.createMessageAck(md); PUBLISH publish = sub.createPublish((ActiveMQMessage) md.getMessage()); switch (publish.qos()) { case AT_LEAST_ONCE: case EXACTLY_ONCE: publish.dup(publish.dup() ? true : md.getMessage().isRedelivered()); case AT_MOST_ONCE: } else if (command.getDataStructureType() == ConnectionError.DATA_STRUCTURE_TYPE) { Throwable exception = ((ConnectionError) command).getException(); handleException(exception, null); } else if (command.isBrokerInfo()) {
protected void populateInitialHeaders(Map<String, Object> map) { Message message = null; if (command.isMessage()) { message = (Message) this.command; } if (command.isMessageDispatch()) { message = ((MessageDispatch) command).getMessage(); } if (message != null) { map.put("JMSCorrelationID", message.getCorrelationId()); map.put("JMSDestination", message.getDestination()); map.put("JMSExpiration", message.getExpiration()); map.put("JMSMessageID", message.getMessageId().toString()); map.put("JMSPriority", message.getPriority()); map.put("JMSRedelivered", message.isRedelivered()); map.put("JMSTimestamp", message.getTimestamp()); map.put("JMSReplyTo", message.getReplyTo()); map.put("JMSType", message.getType()); map.put("JMSXGroupID", message.getGroupID()); map.put("JMSXGroupSeq", message.getGroupSequence()); map.put("JMSXUserID", message.getUserID()); } } }
protected void serviceLocalCommand(Command command) { try { if (command.isMessageDispatch()) { Message message = md.getMessage(); message.setProducerId(producerInfo.getProducerId()); if (message.getOriginalTransactionId() == null) { message.setOriginalTransactionId(message.getTransactionId()); message.setTransactionId(null); remoteBroker.oneway(message); dequeueCounter.incrementAndGet(); localBroker.oneway(new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, 1)); remoteBroker.asyncRequest(message, callback); } else if (command.isBrokerInfo()) { synchronized (this) { localBrokerInfo = (BrokerInfo)command;
if (command.isShutdownInfo()) { } else if (command instanceof RemoveInfo || command.isMessageAck()) { if (command.isResponseRequired()) { Response response = new Response(); response.setCorrelationId(command.getCommandId()); processCommand(response); if (command.isMessage() && timeout > 0 && (end - start > timeout)) { timedout = true; LOG.info("Failover timed out after {} ms", (end - start)); requestMap.put(Integer.valueOf(command.getCommandId()), tracked); } else if (tracked == null && command.isResponseRequired()) { requestMap.put(Integer.valueOf(command.getCommandId()), command); transport.oneway(command); stateTracker.trackBack(command); if (command.isShutdownInfo()) { shuttingDown = true; if (command.isResponseRequired()) { requestMap.remove(Integer.valueOf(command.getCommandId()));