Search in sources :

Example 1 with ConnectionState

use of org.apache.activemq.state.ConnectionState in project activemq-artemis by apache.

the class OpenWireConnection method initContext.

public AMQConnectionContext initContext(ConnectionInfo info) throws Exception {
    WireFormatInfo wireFormatInfo = inWireFormat.getPreferedWireFormatInfo();
    // they were not.
    if (wireFormatInfo != null && wireFormatInfo.getVersion() <= 2) {
        info.setClientMaster(true);
    }
    state = new ConnectionState(info);
    context = new AMQConnectionContext();
    state.reset(info);
    // Setup the context.
    String clientId = info.getClientId();
    context.setBroker(protocolManager);
    context.setClientId(clientId);
    context.setClientMaster(info.isClientMaster());
    context.setConnection(this);
    context.setConnectionId(info.getConnectionId());
    // for now we pass the manager as the connector and see what happens
    // it should be related to activemq's Acceptor
    context.setFaultTolerant(info.isFaultTolerant());
    context.setUserName(info.getUserName());
    context.setWireFormatInfo(wireFormatInfo);
    context.setReconnect(info.isFailoverReconnect());
    context.setConnectionState(state);
    if (info.getClientIp() == null) {
        info.setClientIp(getRemoteAddress());
    }
    createInternalSession(info);
    return context;
}
Also used : AMQConnectionContext(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext) WireFormatInfo(org.apache.activemq.command.WireFormatInfo) ConnectionState(org.apache.activemq.state.ConnectionState) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 2 with ConnectionState

use of org.apache.activemq.state.ConnectionState in project activemq-artemis by apache.

the class OpenWireConnection method addConsumer.

public void addConsumer(ConsumerInfo info) throws Exception {
    // Todo: add a destination interceptors holder here (amq supports this)
    SessionId sessionId = info.getConsumerId().getParentId();
    ConnectionId connectionId = sessionId.getParentId();
    ConnectionState cs = getState();
    if (cs == null) {
        throw new IllegalStateException("Cannot add a consumer to a connection that had not been registered: " + connectionId);
    }
    SessionState ss = cs.getSessionState(sessionId);
    if (ss == null) {
        throw new IllegalStateException(server + " Cannot add a consumer to a session that had not been registered: " + sessionId);
    }
    // Avoid replaying dup commands
    if (!ss.getConsumerIds().contains(info.getConsumerId())) {
        AMQSession amqSession = sessions.get(sessionId);
        if (amqSession == null) {
            throw new IllegalStateException("Session not exist! : " + sessionId);
        }
        List<AMQConsumer> consumersList = amqSession.createConsumer(info, new SlowConsumerDetection());
        if (consumersList.size() == 0) {
            return;
        }
        this.addConsumerBrokerExchange(info.getConsumerId(), amqSession, consumersList);
        ss.addConsumer(info);
        amqSession.start();
        if (AdvisorySupport.isAdvisoryTopic(info.getDestination())) {
            // advisory for temp destinations
            if (AdvisorySupport.isTempDestinationAdvisoryTopic(info.getDestination())) {
                // Replay the temporary destinations.
                List<DestinationInfo> tmpDests = this.protocolManager.getTemporaryDestinations();
                for (DestinationInfo di : tmpDests) {
                    ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(di.getDestination());
                    String originalConnectionId = di.getConnectionId().getValue();
                    protocolManager.fireAdvisory(context, topic, di, info.getConsumerId(), originalConnectionId);
                }
            }
        }
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) SessionState(org.apache.activemq.state.SessionState) DestinationInfo(org.apache.activemq.command.DestinationInfo) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) AMQConsumer(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConsumer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ConnectionId(org.apache.activemq.command.ConnectionId) AMQSession(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQSession) ConnectionState(org.apache.activemq.state.ConnectionState) SessionId(org.apache.activemq.command.SessionId)

Example 3 with ConnectionState

use of org.apache.activemq.state.ConnectionState in project activemq-artemis by apache.

the class OpenWireConnection method reconnect.

// raise the refCount of context
public void reconnect(AMQConnectionContext existingContext, ConnectionInfo info) {
    this.context = existingContext;
    WireFormatInfo wireFormatInfo = inWireFormat.getPreferedWireFormatInfo();
    // they were not.
    if (wireFormatInfo != null && wireFormatInfo.getVersion() <= 2) {
        info.setClientMaster(true);
    }
    if (info.getClientIp() == null) {
        info.setClientIp(getRemoteAddress());
    }
    state = new ConnectionState(info);
    state.reset(info);
    context.setConnection(this);
    context.setConnectionState(state);
    context.setClientMaster(info.isClientMaster());
    context.setFaultTolerant(info.isFaultTolerant());
    context.setReconnect(true);
    context.incRefCount();
}
Also used : WireFormatInfo(org.apache.activemq.command.WireFormatInfo) ConnectionState(org.apache.activemq.state.ConnectionState)

Aggregations

ConnectionState (org.apache.activemq.state.ConnectionState)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 WireFormatInfo (org.apache.activemq.command.WireFormatInfo)2 IllegalStateException (javax.jms.IllegalStateException)1 AMQConnectionContext (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext)1 AMQConsumer (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConsumer)1 AMQSession (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQSession)1 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)1 ConnectionId (org.apache.activemq.command.ConnectionId)1 DestinationInfo (org.apache.activemq.command.DestinationInfo)1 SessionId (org.apache.activemq.command.SessionId)1 SessionState (org.apache.activemq.state.SessionState)1