Search in sources :

Example 31 with IllegalStateException

use of javax.jms.IllegalStateException in project rabbitmq-jms-client by rabbitmq.

the class RMQConnection method setClientID.

/**
 * {@inheritDoc}
 */
@Override
public void setClientID(String clientID) throws JMSException {
    logger.trace("set ClientID to '{}'", clientID);
    illegalStateExceptionIfClosed();
    if (!canSetClientID)
        throw new IllegalStateException("Client ID can only be set right after connection creation");
    if (this.clientID == null) {
        if (CLIENT_IDS.putIfAbsent(clientID, clientID) == null) {
            this.clientID = clientID;
        } else {
            throw new InvalidClientIDException(String.format("A connection with client ID [%s] already exists.", clientID));
        }
    } else {
        throw new IllegalStateException("Client ID already set.");
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException)

Example 32 with IllegalStateException

use of javax.jms.IllegalStateException in project activemq-artemis by apache.

the class DurableSubscriptionTest method testUnsubscribeWithActiveConsumer.

// See JMS 1.1. spec sec 6.11
@Test
public void testUnsubscribeWithActiveConsumer() throws Exception {
    Connection conn = createConnection();
    conn.setClientID("zeke");
    Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber dursub = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "dursub0");
    try {
        s.unsubscribe("dursub0");
        ProxyAssertSupport.fail();
    } catch (IllegalStateException e) {
    // Ok - it is illegal to ubscribe a subscription if it has active consumers
    }
    dursub.close();
    s.unsubscribe("dursub0");
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) IllegalStateException(javax.jms.IllegalStateException) Connection(javax.jms.Connection) Session(javax.jms.Session) Test(org.junit.Test)

Example 33 with IllegalStateException

use of javax.jms.IllegalStateException 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 34 with IllegalStateException

use of javax.jms.IllegalStateException in project activemq-artemis by apache.

the class ChangeSessionDeliveryModeTest method testDoChangeSessionDeliveryMode.

/**
 * test following condition- which are defined by JMS Spec 1.1:
 * MessageConsumers cannot use a MessageListener and receive() from the same
 * session
 *
 * @throws Exception
 */
public void testDoChangeSessionDeliveryMode() throws Exception {
    Destination destination = createDestination("foo.bar");
    Connection connection = createConnection();
    connection.start();
    Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer1 = consumerSession.createConsumer(destination);
    consumer1.setMessageListener(this);
    MessageConsumer consumer2 = consumerSession.createConsumer(destination);
    try {
        consumer2.receive(10);
        fail("Did not receive expected exception.");
    } catch (JMSException e) {
        assertTrue(e instanceof IllegalStateException);
    }
}
Also used : Destination(javax.jms.Destination) IllegalStateException(javax.jms.IllegalStateException) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Example 35 with IllegalStateException

use of javax.jms.IllegalStateException in project activemq-artemis by apache.

the class ActiveMQSession method unsubscribe.

@Override
public void unsubscribe(final String name) throws JMSException {
    // As per spec. section 4.11
    if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) {
        throw new IllegalStateException("Cannot unsubscribe using a QueueSession");
    }
    SimpleString queueName = ActiveMQDestination.createQueueNameForSubscription(true, connection.getClientID(), name);
    try {
        QueueQuery response = session.queueQuery(queueName);
        if (!response.isExists()) {
            throw new InvalidDestinationException("Cannot unsubscribe, subscription with name " + name + " does not exist");
        }
        if (response.getConsumerCount() != 0) {
            throw new IllegalStateException("Cannot unsubscribe durable subscription " + name + " since it has active subscribers");
        }
        session.deleteQueue(queueName);
    } catch (ActiveMQException e) {
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) QueueQuery(org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)

Aggregations

IllegalStateException (javax.jms.IllegalStateException)44 Session (javax.jms.Session)19 Connection (javax.jms.Connection)12 QueueSession (javax.jms.QueueSession)12 Test (org.junit.Test)12 TopicSession (javax.jms.TopicSession)11 XAQueueSession (javax.jms.XAQueueSession)11 XATopicSession (javax.jms.XATopicSession)11 ActiveMQSession (org.apache.activemq.artemis.jms.client.ActiveMQSession)11 JMSException (javax.jms.JMSException)10 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 InvalidDestinationException (javax.jms.InvalidDestinationException)5 IOException (java.io.IOException)4 Queue (javax.jms.Queue)3 QueueBrowser (javax.jms.QueueBrowser)3 TopicSubscriber (javax.jms.TopicSubscriber)3 QueueQuery (org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)3 RMQJMSException (com.rabbitmq.jms.util.RMQJMSException)2 TemporaryQueue (javax.jms.TemporaryQueue)2