protected TimeStampStream getWriter() { return next.narrow(TimeStampStream.class); }
private void doOnewaySend(Object command) throws IOException { if (failed.get()) { throw new InactivityIOException("Cannot send, channel has already failed: " + next.getRemoteAddress()); } if (command.getClass() == WireFormatInfo.class) { synchronized (this) { processOutboundWireFormatInfo((WireFormatInfo) command); } } next.oneway(command); }
/** * @see org.apache.activemq.Service#stop() */ @Override public void stop() throws Exception { next.stop(); }
@Override protected void doStart() throws Exception { LOG.info("Starting " + this); configuredTransport.setTransportListener(new TransportListener() { @Override public void onCommand(Object o) { final Command command = (Command)o; processInboundConnection(command); } @Override public void onException(IOException error) { LOG.error("Caught: " + error, error); } @Override public void transportInterupted() { } @Override public void transportResumed() { } }); configuredTransport.start(); }
@Override public void start() throws Exception { if (!running.compareAndSet(false, true)) { return; this.localTransport.setTransportListener(new DefaultTransportListener() { @Override public void onCommand(Object command) { this.remoteTransport.setTransportListener(new DefaultTransportListener() { @Override public void onCommand(Object command) { localTransport.start(); remoteTransport.start();
final void readCheck() { int currentCounter = next.getReceiveCounter(); int previousCounter = lastReceiveCounter.getAndSet(currentCounter); if (inReceive.get() || currentCounter != previousCounter) { LOG.trace("A receive is in progress, skipping read check."); return; if (!commandReceived.get() && monitorStarted.get() && !ASYNC_TASKS.isShutdown()) { LOG.debug("No message received since last read check for {}. Throwing InactivityIOException.", this);
@Override public void start() throws Exception { if (started.compareAndSet(false, true)) { networkBridgeStatistics.setEnabled(brokerService.isEnableStatistics()); duplexInboundLocalBroker = NetworkBridgeFactory.createLocalAsyncTransport(brokerService.getBroker().getVmConnectorURI()); duplexInboundLocalBroker.setTransportListener(new DefaultTransportListener() { duplexInboundLocalBroker.start(); localBroker.setTransportListener(new DefaultTransportListener() { remoteBroker.setTransportListener(new DefaultTransportListener() { remoteBroker.start(); localBroker.start(); if (!disposed.get()) { try { triggerStartAsyncNetworkBridgeCreation();
X509Certificate[] peerCerts = originalTransport.getPeerCertificates(); Object resp = localBroker.request(localConnectionInfo); if (resp instanceof ExceptionResponse) { throw ((ExceptionResponse) resp).getException(); localBroker.oneway(localSessionInfo); duplexInboundLocalBroker.oneway(remoteBrokerInfo); duplexLocalConnectionInfo.setConnectionId(new ConnectionId(idGenerator.generateId())); X509Certificate[] peerCerts = originalTransport.getPeerCertificates(); resp = duplexInboundLocalBroker.request(duplexLocalConnectionInfo); if (resp instanceof ExceptionResponse) { throw ((ExceptionResponse) resp).getException(); duplexInboundLocalBroker.oneway(duplexInboundSession); duplexInboundLocalBroker.oneway(duplexInboundLocalProducerInfo); brokerService.getBroker().networkBridgeStarted(remoteBrokerInfo, this.createdByDuplex, remoteBroker.toString()); NetworkBridgeListener l = this.networkBridgeListener; if (l != null) { localBroker.oneway(remoteBrokerInfo); brokerService.getBroker().addBroker(null, remoteBrokerInfo);
brokerInfo.setNetworkProperties(str); brokerInfo.setBrokerId(this.localBrokerId); remoteBroker.oneway(brokerInfo); if (configuration.isSyncDurableSubs() && remoteBroker.getWireFormat().getVersion() >= CommandTypes.PROTOCOL_VERSION_DURABLE_SYNC) { remoteBroker.oneway(NetworkBridgeUtils.getBrokerSubscriptionInfo(brokerService, configuration)); remoteBroker.oneway(remoteConnectionInfo.createRemoveCommand()); remoteConnectionInfo = new ConnectionInfo(); remoteConnectionInfo.setConnectionId(new ConnectionId(idGenerator.generateId())); remoteConnectionInfo.setClientId(configuration.getName() + configuration.getClientIdToken() + configuration.getBrokerName() + configuration.getClientIdToken() + "outbound"); remoteConnectionInfo.setUserName(configuration.getUserName()); remoteConnectionInfo.setPassword(configuration.getPassword()); remoteBroker.oneway(remoteConnectionInfo); remoteBroker.oneway(remoteSessionInfo); producerInfo = new ProducerInfo(remoteSessionInfo, 1); producerInfo.setResponseRequired(false); remoteBroker.oneway(producerInfo); demandConsumerInfo = new ConsumerInfo(remoteSessionInfo, 1); demandConsumerInfo.setDestination(new ActiveMQTopic(advisoryTopic)); configureConsumerPrefetch(demandConsumerInfo); remoteBroker.oneway(demandConsumerInfo);
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(); Response reply = new Response(); reply.setCorrelationId(message.getCommandId()); remoteBroker.oneway(reply); if (duplexInitiatingConnection != null && duplexInitiatingConnectionInfoReceived.compareAndSet(false, true)) { localBroker.oneway(command); localBroker.oneway(command); break; case ProducerInfo.DATA_STRUCTURE_TYPE: DemandSubscription localSub = subscriptionMapByRemoteId.get(ack.getConsumerId()); if (localSub != null) { ack.setConsumerId(localSub.getLocalInfo().getConsumerId()); localBroker.oneway(ack); } else { LOG.warn("Matching local subscription not found for ack: {}", ack);
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()); processRemoveConnection(cs.getInfo().getConnectionId(), RemoveInfo.LAST_DELIVERED_UNKNOWN); } catch (Throwable ignore) { LOG.debug("Exception caught removing connection {}. This exception is ignored.", cs.getInfo().getConnectionId(), ignore);
public void serviceLocalException(MessageDispatch messageDispatch, Throwable error) { LOG.trace("serviceLocalException: disposed {} ex", disposed.get(), error); if (!disposed.get()) { if (error instanceof DestinationDoesNotExistException && ((DestinationDoesNotExistException) error).isTemporary()) { LOG.warn("PoisonAck of {} on forwarding error: {}", messageDispatch.getMessage().getMessageId(), error); try { MessageAck poisonAck = new MessageAck(messageDispatch, MessageAck.POSION_ACK_TYPE, 1); poisonAck.setPoisonCause(error); localBroker.oneway(poisonAck); } catch (IOException ioe) { LOG.error("Failed to posion ack message following forward failure: ", ioe); LOG.debug("The local Exception was: {}", error, error); brokerService.getTaskRunnerFactory().execute(new Runnable() { @Override public void run() {
configuration.getBrokerName(), remoteBrokerName, Arrays.toString(md.getMessage().getBrokerPath()), md.getMessage() }); localBroker.oneway(new MessageAck(md, MessageAck.INDIVIDUAL_ACK_TYPE, 1)); } finally { sub.decrementOutstandingResponses(); configuration.getBrokerName(), remoteBrokerName, md.getConsumerId(), message.getDestination(), Arrays.toString(message.getBrokerPath()), (LOG.isTraceEnabled() ? message : message.getMessageId()) }); if (isDuplex() && NetworkBridgeFilter.isAdvisoryInterpretedByNetworkBridge(message)) { try { remoteBroker.oneway(message); } finally { sub.decrementOutstandingResponses(); remoteBroker.asyncRequest(message, new ResponseCallback() { @Override public void onCompletion(FutureResponse future) { remoteBroker.oneway(message); localBroker.oneway(new MessageAck(md, MessageAck.INDIVIDUAL_ACK_TYPE, 1)); networkBridgeStatistics.getDequeues().increment(); } finally {
@Override public void onCommand(Object command) { boolean shutdown = false; if (command.getClass() == ShutdownInfo.class) { shuttingDown.set(true); shutdown = true; } // skipping WireFormat infos if (command.getClass() == WireFormatInfo.class) { return; } try { remoteTransport.oneway(command); if (shutdown) { stop(); } } catch (IOException error) { onFailure(error); } catch (Exception error) { onFailure(IOExceptionSupport.create(error)); } }
connectionInfo = new ConnectionInfo(); connectionInfo.setConnectionId(new ConnectionId(ID_GENERATOR.generateId())); connectionInfo.setClientId(clientId); localBroker.oneway(connectionInfo); remoteBroker.oneway(connectionInfo); localBroker.oneway(sessionInfo); remoteBroker.oneway(sessionInfo); queueConsumerInfo = new ConsumerInfo(sessionInfo, 1); queueConsumerInfo.setDispatchAsync(dispatchAsync); queueConsumerInfo.setDestination(new ActiveMQQueue(destinationFilter)); queueConsumerInfo.setPrefetchSize(prefetchSize); queueConsumerInfo.setPriority(ConsumerInfo.NETWORK_CONSUMER_PRIORITY); localBroker.oneway(queueConsumerInfo); remoteBroker.oneway(producerInfo); if (connectionInfo.getClientId() != null) { topicConsumerInfo.setPrefetchSize(prefetchSize); topicConsumerInfo.setPriority(ConsumerInfo.NETWORK_CONSUMER_PRIORITY); localBroker.oneway(topicConsumerInfo);
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;
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); } }
this.info = new ConnectionInfo(new ConnectionId(uniqueId)); this.info.setManageable(true); this.info.setFaultTolerant(transport.isFaultTolerant()); this.connectionSessionId = new SessionId(info.getConnectionId(), -1); this.transport.setTransportListener(this); this.connectionAudit.setCheckForDuplicates(transport.isFaultTolerant());
if (command.isShutdownInfo()) { } else if (command instanceof RemoveInfo || command.isMessageAck()) { if (command.isResponseRequired()) { Response response = new Response(); response.setCorrelationId(command.getCommandId()); MessageDispatch dispatch = new MessageDispatch(); dispatch.setConsumerId(pullRequest.getConsumerId()); dispatch.setDestination(pullRequest.getDestination()); processCommand(dispatch); transport.oneway(command); stateTracker.trackBack(command); if (command.isShutdownInfo()) {
private void cleanupDurableSub(final DemandSubscription ds, Iterator<DemandSubscription> i) throws IOException { if (ds != null && ds.getLocalDurableSubscriber() != null && ds.getDurableRemoteSubs().isEmpty() && ds.getForcedDurableConsumersSize() == 0) { // deactivate subscriber RemoveInfo removeInfo = new RemoveInfo(ds.getLocalInfo().getConsumerId()); localBroker.oneway(removeInfo); // remove subscriber RemoveSubscriptionInfo sending = new RemoveSubscriptionInfo(); sending.setClientId(localClientId); sending.setSubscriptionName(ds.getLocalDurableSubscriber().getSubscriptionName()); sending.setConnectionId(this.localConnectionInfo.getConnectionId()); localBroker.oneway(sending); //remove subscriber from map i.remove(); } }