Search in sources :

Example 1 with AMQSession

use of org.apache.activemq.artemis.core.protocol.openwire.amq.AMQSession in project activemq-artemis by apache.

the class OpenWireConnection method addSession.

public AMQSession addSession(SessionInfo ss, boolean internal) {
    AMQSession amqSession = new AMQSession(getState().getInfo(), ss, server, this, protocolManager);
    amqSession.initialize();
    if (internal) {
        amqSession.disableSecurity();
    }
    sessions.put(ss.getSessionId(), amqSession);
    sessionIdMap.put(amqSession.getCoreSession().getName(), ss.getSessionId());
    return amqSession;
}
Also used : AMQSession(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQSession)

Example 2 with AMQSession

use of org.apache.activemq.artemis.core.protocol.openwire.amq.AMQSession 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 AMQSession

use of org.apache.activemq.artemis.core.protocol.openwire.amq.AMQSession in project activemq-artemis by apache.

the class OpenWireProtocolManager method fireAdvisory.

/*
    * See AdvisoryBroker.fireAdvisory()
    */
public void fireAdvisory(AMQConnectionContext context, ActiveMQTopic topic, Command command, ConsumerId targetConsumerId, String originalConnectionId) throws Exception {
    if (!this.isSupportAdvisory()) {
        return;
    }
    ActiveMQMessage advisoryMessage = new ActiveMQMessage();
    if (originalConnectionId == null) {
        originalConnectionId = context.getConnectionId().getValue();
    }
    advisoryMessage.setStringProperty(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString(), originalConnectionId);
    advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_NAME, getBrokerName());
    String id = getBrokerId() != null ? getBrokerId().getValue() : "NOT_SET";
    advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_ID, id);
    String url = context.getConnection().getLocalAddress();
    advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_URL, url);
    // set the data structure
    advisoryMessage.setDataStructure(command);
    advisoryMessage.setPersistent(false);
    advisoryMessage.setType(AdvisorySupport.ADIVSORY_MESSAGE_TYPE);
    advisoryMessage.setMessageId(new MessageId(advisoryProducerId, messageIdGenerator.getNextSequenceId()));
    advisoryMessage.setTargetConsumerId(targetConsumerId);
    advisoryMessage.setDestination(topic);
    advisoryMessage.setResponseRequired(false);
    advisoryMessage.setProducerId(advisoryProducerId);
    boolean originalFlowControl = context.isProducerFlowControl();
    final AMQProducerBrokerExchange producerExchange = new AMQProducerBrokerExchange();
    producerExchange.setConnectionContext(context);
    producerExchange.setProducerState(new ProducerState(new ProducerInfo()));
    try {
        context.setProducerFlowControl(false);
        AMQSession sess = context.getConnection().getAdvisorySession();
        if (sess != null) {
            sess.send(producerExchange.getProducerState().getInfo(), advisoryMessage, false);
        }
    } finally {
        context.setProducerFlowControl(originalFlowControl);
    }
}
Also used : AMQSession(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQSession) ProducerInfo(org.apache.activemq.command.ProducerInfo) ProducerState(org.apache.activemq.state.ProducerState) AMQProducerBrokerExchange(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQProducerBrokerExchange) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) MessageId(org.apache.activemq.command.MessageId)

Aggregations

AMQSession (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQSession)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 IllegalStateException (javax.jms.IllegalStateException)1 AMQConsumer (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConsumer)1 AMQProducerBrokerExchange (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQProducerBrokerExchange)1 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)1 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)1 ConnectionId (org.apache.activemq.command.ConnectionId)1 DestinationInfo (org.apache.activemq.command.DestinationInfo)1 MessageId (org.apache.activemq.command.MessageId)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 SessionState (org.apache.activemq.state.SessionState)1