Search in sources :

Example 1 with SessionState

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

the class OpenWireConnection method getProducerBrokerExchange.

private AMQProducerBrokerExchange getProducerBrokerExchange(ProducerId id) throws IOException {
    AMQProducerBrokerExchange result = producerExchanges.get(id);
    if (result == null) {
        synchronized (producerExchanges) {
            result = new AMQProducerBrokerExchange();
            result.setConnectionContext(context);
            // todo: this used to check for  && this.acceptorUsed.isAuditNetworkProducers()
            if (context.isReconnect() || (context.isNetworkConnection())) {
                // once implemented ARTEMIS-194, we need to set the storedSequenceID here somehow
                // We have different semantics on Artemis Journal, but we could adapt something for this
                // TBD during the implementation of ARTEMIS-194
                result.setLastStoredSequenceId(0);
            }
            SessionState ss = state.getSessionState(id.getParentId());
            if (ss != null) {
                result.setProducerState(ss.getProducerState(id));
                ProducerState producerState = ss.getProducerState(id);
                if (producerState != null && producerState.getInfo() != null) {
                    ProducerInfo info = producerState.getInfo();
                }
            }
            producerExchanges.put(id, result);
        }
    }
    return result;
}
Also used : SessionState(org.apache.activemq.state.SessionState) ProducerInfo(org.apache.activemq.command.ProducerInfo) ProducerState(org.apache.activemq.state.ProducerState) AMQProducerBrokerExchange(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQProducerBrokerExchange)

Example 2 with SessionState

use of org.apache.activemq.state.SessionState 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)

Aggregations

SessionState (org.apache.activemq.state.SessionState)2 IllegalStateException (javax.jms.IllegalStateException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 AMQConsumer (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConsumer)1 AMQProducerBrokerExchange (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQProducerBrokerExchange)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 ProducerInfo (org.apache.activemq.command.ProducerInfo)1 SessionId (org.apache.activemq.command.SessionId)1 ConnectionState (org.apache.activemq.state.ConnectionState)1 ProducerState (org.apache.activemq.state.ProducerState)1