connectionInfo = new ConnectionInfo(); connectionInfo.setConnectionId(new ConnectionId(ID_GENERATOR.generateId())); connectionInfo.setClientId(clientId); localBroker.oneway(connectionInfo); remoteBroker.oneway(connectionInfo); sessionInfo = new SessionInfo(connectionInfo, 1); 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);
/** * @param transport * @param sessionState * @throws IOException */ protected void restoreConsumers(Transport transport, SessionState sessionState) throws IOException { // Restore the session's consumers but possibly in pull only (prefetch 0 state) till recovery complete final ConnectionState connectionState = connectionStates.get(sessionState.getInfo().getSessionId().getParentId()); final boolean connectionInterruptionProcessingComplete = connectionState.isConnectionInterruptProcessingComplete(); for (ConsumerState consumerState : sessionState.getConsumerStates()) { ConsumerInfo infoToSend = consumerState.getInfo(); if (!connectionInterruptionProcessingComplete && infoToSend.getPrefetchSize() > 0) { infoToSend = consumerState.getInfo().copy(); connectionState.getRecoveringPullConsumers().put(infoToSend.getConsumerId(), consumerState.getInfo()); infoToSend.setPrefetchSize(0); if (LOG.isDebugEnabled()) { LOG.debug("restore consumer: " + infoToSend.getConsumerId() + " in pull mode pending recovery, overriding prefetch: " + consumerState.getInfo().getPrefetchSize()); } } if (LOG.isDebugEnabled()) { LOG.debug("consumer: " + infoToSend.getConsumerId()); } transport.oneway(infoToSend); } }
/** * 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); SessionInfo info = (SessionInfo)o; info.setSessionId((org.apache.activemq.command.SessionId) looseUnmarsalCachedObject(wireFormat, dataIn)); }
public RemoveInfo createRemoveCommand() { RemoveInfo command = new RemoveInfo(getSessionId()); command.setResponseRequired(isResponseRequired()); return command; }
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()); remoteBroker.oneway(remoteConnectionInfo); SessionInfo remoteSessionInfo = new SessionInfo(remoteConnectionInfo, 1); remoteBroker.oneway(remoteSessionInfo); producerInfo = new ProducerInfo(remoteSessionInfo, 1); demandConsumerInfo = new ConsumerInfo(remoteSessionInfo, 1); demandConsumerInfo.setDispatchAsync(true); String advisoryTopic = configuration.getDestinationFilter(); if (configuration.isBridgeTempDestinations()) { advisoryTopic += "," + AdvisorySupport.TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC; demandConsumerInfo.setDestination(new ActiveMQTopic(advisoryTopic)); configureConsumerPrefetch(demandConsumerInfo); remoteBroker.oneway(demandConsumerInfo);
protected DemandSubscription doCreateDemandSubscription(ConsumerInfo info) throws IOException { DemandSubscription result = new DemandSubscription(info); result.getLocalInfo().setConsumerId(new ConsumerId(localSessionInfo.getSessionId(), consumerIdGenerator.getNextSequenceId())); if (info.getDestination().isTemporary()) { // reset the local connection Id ActiveMQTempDestination dest = (ActiveMQTempDestination) result.getLocalInfo().getDestination(); dest.setConnectionId(localConnectionInfo.getConnectionId().toString()); } if (configuration.isDecreaseNetworkConsumerPriority()) { byte priority = (byte) configuration.getConsumerPriorityBase(); if (info.getBrokerPath() != null && info.getBrokerPath().length > 1) { // The longer the path to the consumer, the less it's consumer priority. priority -= info.getBrokerPath().length + 1; } result.getLocalInfo().setPriority(priority); LOG.debug("{} using priority: {} for subscription: {}", new Object[]{configuration.getBrokerName(), priority, info}); } configureDemandSubscription(info, result); return result; }
localConnectionInfo = new ConnectionInfo(); localConnectionInfo.setConnectionId(new ConnectionId(idGenerator.generateId())); localClientId = configuration.getName() + configuration.getClientIdToken() + remoteBrokerName + configuration.getClientIdToken() + "inbound" + configuration.getClientIdToken() + configuration.getBrokerName(); localConnectionInfo.setClientId(localClientId); localConnectionInfo.setUserName(configuration.getUserName()); localConnectionInfo.setPassword(configuration.getPassword()); X509Certificate[] peerCerts = originalTransport.getPeerCertificates(); localConnectionInfo.setTransportContext(peerCerts); Object resp = localBroker.request(localConnectionInfo); if (resp instanceof ExceptionResponse) { throw ((ExceptionResponse) resp).getException(); localSessionInfo = new SessionInfo(localConnectionInfo, 1); localBroker.oneway(localSessionInfo); ConnectionInfo duplexLocalConnectionInfo = new ConnectionInfo(); duplexLocalConnectionInfo.setConnectionId(new ConnectionId(idGenerator.generateId())); duplexLocalConnectionInfo.setClientId(configuration.getName() + configuration.getClientIdToken() + remoteBrokerName + configuration.getClientIdToken() + "inbound" + configuration.getClientIdToken() + "duplex" + configuration.getClientIdToken() + configuration.getBrokerName()); throw ((ExceptionResponse) resp).getException(); SessionInfo duplexInboundSession = new SessionInfo(duplexLocalConnectionInfo, 1); duplexInboundLocalProducerInfo = new ProducerInfo(duplexInboundSession, 1); duplexInboundLocalBroker.oneway(duplexInboundSession);
@Override protected DemandSubscription createDemandSubscription(ConsumerInfo info) throws IOException { boolean isForcedDurable = NetworkBridgeUtils.isForcedDurable(info, dynamicallyIncludedDestinations, staticallyIncludedDestinations); if (addToAlreadyInterestedConsumers(info, isForcedDurable)) { return null; // don't want this subscription added } //add our original id to ourselves info.addNetworkConsumerId(info.getConsumerId()); ConsumerId forcedDurableId = isForcedDurable ? info.getConsumerId() : null; if(info.isDurable() || isForcedDurable) { // set the subscriber name to something reproducible info.setSubscriptionName(getSubscriberName(info.getDestination())); // and override the consumerId with something unique so that it won't // be removed if the durable subscriber (at the other end) goes away info.setConsumerId(new ConsumerId(localSessionInfo.getSessionId(), consumerIdGenerator.getNextSequenceId())); } info.setSelector(null); DemandSubscription demandSubscription = doCreateDemandSubscription(info); if (forcedDurableId != null) { demandSubscription.addForcedDurableConsumer(forcedDurableId); forcedDurableRemoteId.add(forcedDurableId); } return demandSubscription; }
final protected DemandSubscription createDemandSubscription(ActiveMQDestination destination, final String subscriptionName) { ConsumerInfo info = new ConsumerInfo(); info.setNetworkSubscription(true); info.setDestination(destination); if (subscriptionName != null) { info.setSubscriptionName(subscriptionName); } // Indicate that this subscription is being made on behalf of the remote broker. info.setBrokerPath(new BrokerId[]{remoteBrokerId}); // the remote info held by the DemandSubscription holds the original // consumerId, the local info get's overwritten info.setConsumerId(new ConsumerId(localSessionInfo.getSessionId(), consumerIdGenerator.getNextSequenceId())); DemandSubscription result = null; try { result = createDemandSubscription(info); } catch (IOException e) { LOG.error("Failed to create DemandSubscription ", e); } return result; }
BrokerId[] path = info.getBrokerPath(); if (info.isBrowser()) { LOG.debug("{} Ignoring sub from {}, browsers explicitly suppressed", configuration.getBrokerName(), remoteBrokerName); return; if (!isPermissableDestination(info.getDestination())) { return; destInfo.setConnectionId(localConnectionInfo.getConnectionId()); if (destInfo.getDestination() instanceof ActiveMQTempDestination) { tempDest.setConnectionId(localSessionInfo.getSessionId().getConnectionId()); localBroker.oneway(destInfo);
protected void startBridge() throws Exception { connectionInfo = new ConnectionInfo(); connectionInfo.setConnectionId(new ConnectionId(idGenerator.generateId())); connectionInfo.setClientId(idGenerator.generateId()); connectionInfo.setUserName(userName); connectionInfo.setPassword(password); connectionInfo.setBrokerMasterConnector(true); sessionInfo = new SessionInfo(connectionInfo, 1); producerInfo = new ProducerInfo(sessionInfo, 1); producerInfo.setResponseRequired(false); if (connector != null) { brokerInfo = connector.getBrokerInfo(); } else { brokerInfo = new BrokerInfo(); } brokerInfo.setBrokerName(broker.getBrokerName()); brokerInfo.setPeerBrokerInfos(broker.getBroker().getPeerBrokerInfos()); brokerInfo.setSlaveBroker(true); brokerInfo.setPassiveSlave(broker.isPassiveSlave()); restartBridge(); LOG.info("Slave connection between " + localBroker + " and " + remoteBroker + " has been established."); }
@Override public Response processAddSession(SessionInfo sessionInfo) throws Exception { SessionInfo copy = new SessionInfo(); sessionInfo.copy(copy); SessionId originalSessionId = sessionInfo.getSessionId(); SessionId sessionId = new SessionId(getMultiplexerConnectionId(), multiplexer.getNextSessionId()); sessionIdMap.put(originalSessionId, sessionId); copy.setSessionId(sessionId); multiplexer.sendOutAll(this, copy); multiplexerConnectionStateRegister.addSession(copy); return null; }
final protected DemandSubscription createDemandSubscription(ActiveMQDestination destination) { ConsumerInfo info = new ConsumerInfo(); info.setDestination(destination); // the remote info held by the DemandSubscription holds the original // consumerId, // the local info get's overwritten info.setConsumerId(new ConsumerId(localSessionInfo.getSessionId(), consumerIdGenerator.getNextSequenceId())); DemandSubscription result = null; try { result = createDemandSubscription(info); } catch (IOException e) { LOG.error("Failed to create DemandSubscription ", e); } if (result != null) { result.getLocalInfo().setPriority(ConsumerInfo.NETWORK_CONSUMER_PRIORITY); } return result; }
public void initialize() { String name = sessInfo.getSessionId().toString(); String username = connInfo.getUserName(); String password = connInfo.getPassword(); int minLargeMessageSize = Integer.MAX_VALUE; // disable // minLargeMessageSize for // now try { coreSession = server.createSession(name, username, password, minLargeMessageSize, connection, true, false, false, false, null, this, true, connection.getOperationContext(), protocolManager.getPrefixes()); long sessionId = sessInfo.getSessionId().getValue(); if (sessionId == -1) { this.connection.setAdvisorySession(this); } } catch (Exception e) { ActiveMQServerLogger.LOGGER.error("error init session", e); } }
/** * @param transport * @param connectionState * @throws IOException */ protected void restoreSessions(Transport transport, ConnectionState connectionState) throws IOException { // Restore the connection's sessions for (Iterator iter2 = connectionState.getSessionStates().iterator(); iter2.hasNext();) { SessionState sessionState = (SessionState)iter2.next(); if (LOG.isDebugEnabled()) { LOG.debug("session: " + sessionState.getInfo().getSessionId()); } transport.oneway(sessionState.getInfo()); if (restoreProducers) { restoreProducers(transport, sessionState); } if (restoreConsumers) { restoreConsumers(transport, sessionState); } } }
/** * Returns the SessionInfo bean. * * @return info - SessionInfo bean. * @throws JMSException */ protected SessionInfo getSessionInfo() throws JMSException { SessionInfo info = new SessionInfo(connection.getConnectionInfo(), getSessionId().getValue()); return info; }
public Multiplexer(Model model, String name, AsyncExecutors asyncExecutors, MessageDistribution messageDistribution) { this.model = model; this.name = name; this.asyncExecutors = asyncExecutors; this.messageDistribution = messageDistribution; inputs = new ConcurrentHashMap<>(); consumerIdMultiplexerInputMap = new ConcurrentHashMap<>(); outTransports = new ConcurrentHashMap<>(); inputId = new IdGenerator("InTransport"); multiplexerConnectionInfo = new ConnectionInfo(new ConnectionId(inputId.generateSanitizedId())); multiplexerSessionInfo = new SessionInfo(multiplexerConnectionInfo, -1); sessionIdGenerator = new AtomicLong(); producerIdGenerator = new AtomicLong(); consumerIdGenerator = new AtomicLong(); transactionIdGenerator = new AtomicLong(); inputCount = new AtomicLong(); userName = ""; password = ""; }
MultiplexerInput(Multiplexer multiplexer, String name, String protocol, AsyncExecutors asyncExecutors, TransportConnectionStateRegister transportConnectionStateRegister, Transport input) { this.multiplexer = multiplexer; this.name = name; this.protocol = protocol; this.model = multiplexer.getModel(); this.asyncExecutors = asyncExecutors; this.multiplexerConnectionStateRegister = transportConnectionStateRegister; this.input = input; this.multiplexerConnectionId = multiplexer.getMultiplexerConnectionInfo().getConnectionId(); this.multiplexerSessionId = multiplexer.getMultiplexerSessionInfo().getSessionId(); this.destinationRegister = new DestinationRegister(model, this); }
/** * @return a new object instance */ public DataStructure createObject() { return new SessionInfo(); }
@Override public Response processAddSession(SessionInfo info) { if (info != null) { ConnectionId connectionId = info.getSessionId().getParentId(); if (connectionId != null) { ConnectionState cs = connectionStates.get(connectionId); if (cs != null) { cs.addSession(info); } } } return TRACKED_RESPONSE_MARKER; }