/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { ConnectionId info = (ConnectionId)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalString(info.getValue(), dataOut); } }
@Override public String getConnectionId() { List<TransportConnectionState> connectionStates = listConnectionStates(); for (TransportConnectionState cs : connectionStates) { if (cs.getInfo().getClientId() != null) { return cs.getInfo().getClientId(); } return cs.getInfo().getConnectionId().toString(); } return null; }
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);
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);
String connectionID = session.connection.getConnectionInfo().getConnectionId().getValue(); this.info = new ConsumerInfo(consumerId); this.info.setExclusive(this.session.connection.isExclusiveConsumer()); this.info.setClientId(this.session.connection.getClientID()); this.info.setSubscriptionName(name); this.info.setPrefetchSize(prefetch);
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; }
String uniqueId = connectionIdGenerator.generateId(); 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());
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);
return "ConsumerId: " + ci.getConsumerId().toString() + " destination: " + ci.getDestination().toString(); String connStr = connInfo.getUserName() != null ? connInfo.getUserName() + "@" + connInfo.getClientIp() : connInfo.getClientIp(); return "ConnectionId: " + connInfo.getConnectionId().toString() + " Connection from: " + connStr + " clientId: " + connInfo.getClientId();
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."); }
ConnectionId connectionId = new ConnectionId(connectionIdGenerator.generateId()); SessionId sessionId = new SessionId(connectionId, sessionIdGenerator.getNextSequenceId()); ConsumerId consumerId = new ConsumerId(sessionId, consumerIdGenerator.getNextSequenceId()); info = new ConsumerInfo(consumerId); ActiveMQTopic topic = AdvisorySupport.getVirtualDestinationConsumerAdvisoryTopic(info.getDestination()); fireConsumerAdvisory(context, info.getDestination(), topic, 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 = ""; }
protected ProducerId createProducerId() { String id = idGenerator.generateId(); ConnectionId connectionId = new ConnectionId(id); SessionId sessionId = new SessionId(connectionId, 1); return new ProducerId(sessionId, 1); } }
/** * Removes any TempDestinations that this connection has cached, ignoring * any exceptions generated because the destination is in use as they should * not be removed. * Used from a pooled connection, b/c it will not be explicitly closed. */ public void cleanUpTempDestinations() { if (this.activeTempDestinations == null || this.activeTempDestinations.isEmpty()) { return; } Iterator<ConcurrentMap.Entry<ActiveMQTempDestination, ActiveMQTempDestination>> entries = this.activeTempDestinations.entrySet().iterator(); while(entries.hasNext()) { ConcurrentMap.Entry<ActiveMQTempDestination, ActiveMQTempDestination> entry = entries.next(); try { // Only delete this temp destination if it was created from this connection. The connection used // for the advisory consumer may also have a reference to this temp destination. ActiveMQTempDestination dest = entry.getValue(); String thisConnectionId = (info.getConnectionId() == null) ? "" : info.getConnectionId().toString(); if (dest.getConnectionId() != null && dest.getConnectionId().equals(thisConnectionId)) { this.deleteTempDestination(entry.getValue()); } } catch (Exception ex) { // the temp dest is in use so it can not be deleted. // it is ok to leave it to connection tear down phase } } }
/** * @return Returns the resourceManagerId. * @throws JMSException */ public String getResourceManagerId() throws JMSException { if (isRmIdFromConnectionId()) { return info.getConnectionId().getValue(); } waitForBrokerInfo(); if (brokerInfo == null) { throw new JMSException("Connection failed before Broker info was received."); } return brokerInfo.getBrokerId().getValue(); }
/** * @return a new object instance */ public DataStructure createObject() { return new ConnectionId(); }
public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { for (Iterator<Transaction> iter = context.getTransactions().values().iterator(); iter.hasNext();) { try { Transaction transaction = iter.next(); transaction.rollback(); } catch (Exception e) { LOG.warn("ERROR Rolling back disconnected client's transactions: ", e); } iter.remove(); } synchronized (xaTransactions) { // first find all txs that belongs to the connection ArrayList<XATransaction> txs = new ArrayList<XATransaction>(); for (XATransaction tx : xaTransactions.values()) { if (tx.getConnectionId() != null && tx.getConnectionId().equals(info.getConnectionId()) && !tx.isPrepared()) { txs.add(tx); } } // then remove them // two steps needed to avoid ConcurrentModificationException, from removeTransaction() for (XATransaction tx : txs) { try { tx.rollback(); } catch (Exception e) { LOG.warn("ERROR Rolling back disconnected client's xa transactions: ", e); } } } next.removeConnection(context, info, error); }
public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { final SecurityContext subject = context.getSecurityContext(); if (subject == null) throw new SecurityException("User is not authenticated."); if (info.getDestination().getPhysicalName().equals(Constants.NOTIFICATION_UPDATES_QUEUE)) { if (!subject.getPrincipals().contains(Constants.defaultSystemRole)) { throw new SecurityException("User " + subject.getUserName() + " is not authorized to read from: " + info.getDestination()); } } else if (info.getDestination().getPhysicalName().equals(Constants.NOTIFICATION_CONTROL_QUEUE)) { if (!subject.getPrincipals().contains(Constants.defaultSystemRole)) { throw new SecurityException("User " + subject.getUserName() + " is not authorized to read from: " + info.getDestination()); } } if (info.getDestination().isTemporary() && !((ActiveMQTempDestination) info.getDestination()).getConnectionId().equals(context.getConnectionId().getValue())) { throw new SecurityException("User " + subject.getUserName() + " is not authorized to read from: " + info.getDestination()); } subject.getAuthorizedReadDests().put(info.getDestination(), info.getDestination()); return super.addConsumer(context, info); }
/** * 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 tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn, BooleanStream bs) throws IOException { super.tightUnmarshal(wireFormat, o, dataIn, bs); ConnectionId info = (ConnectionId)o; info.setValue(tightUnmarshalString(dataIn, bs)); }
public synchronized TransportConnectionState unregisterConnectionState(ConnectionId connectionId) { TransportConnectionState rc = null; if (connectionId != null && connectionState != null && this.connectionId!=null){ if (this.connectionId.equals(connectionId)){ rc = connectionState; connectionState = null; connectionId = null; } } return rc; }