Search in sources :

Example 6 with IllegalStateException

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

the class AcknowledgeAnomaliesQueueMessageIT method messageTestBase.

private void messageTestBase(MessageTestType mtt) throws Exception {
    try {
        queueConn.start();
        QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
        Queue queue = queueSession.createQueue(QUEUE_NAME);
        drainQueue(queueSession, queue);
        QueueSender queueSender = queueSession.createSender(queue);
        queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        for (int i = 0; i < 2; ++i) {
            // send two messages
            queueSender.send(mtt.gen(queueSession, (Serializable) queue));
        }
    } finally {
        reconnect();
    }
    Message msgNotAcked = null;
    try {
        queueConn.start();
        QueueSession queueSession = queueConn.createQueueSession(false, RMQSession.CLIENT_INDIVIDUAL_ACKNOWLEDGE);
        Queue queue = queueSession.createQueue(QUEUE_NAME);
        QueueReceiver queueReceiver = queueSession.createReceiver(queue);
        msgNotAcked = queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
        mtt.check(msgNotAcked, (Serializable) queue);
        Message msg2 = queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
        mtt.check(msg2, (Serializable) queue);
        msg2.acknowledge();
        // repeat acknowledgement: should be a no-op
        msg2.acknowledge();
    } finally // requeues unacknowledged messages
    {
        reconnect();
    }
    try {
        // should get an illegal state exception
        msgNotAcked.acknowledge();
    } catch (IllegalStateException ise) {
    // brilliant
    } catch (Exception e) {
        fail(String.format("Message acknowledged outside session gave wrong exception: %s", e));
    }
    {
        queueConn.start();
        // automatically acknowledged
        QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
        Queue queue = queueSession.createQueue(QUEUE_NAME);
        QueueReceiver queueReceiver = queueSession.createReceiver(queue);
        Message msg = queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
        mtt.check(msg, (Serializable) queue);
        // repeat ack: should be a no-op
        msg.acknowledge();
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) Serializable(java.io.Serializable) Message(javax.jms.Message) QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) IllegalStateException(javax.jms.IllegalStateException)

Example 7 with IllegalStateException

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

the class ActiveMQRASession method commit.

/**
 * Commit
 *
 * @throws JMSException Failed to close session.
 */
@Override
public void commit() throws JMSException {
    if (cri.getType() == ActiveMQRAConnectionFactory.XA_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) {
        throw new TransactionInProgressException("XA connection");
    }
    lock();
    try {
        Session session = getSessionInternal();
        if (cri.isTransacted() == false) {
            throw new IllegalStateException("Session is not transacted");
        }
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("Commit session " + this);
        }
        session.commit();
    } finally {
        unlock();
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) TransactionInProgressException(javax.jms.TransactionInProgressException) XAQueueSession(javax.jms.XAQueueSession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) TopicSession(javax.jms.TopicSession) XATopicSession(javax.jms.XATopicSession) QueueSession(javax.jms.QueueSession)

Example 8 with IllegalStateException

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

the class ActiveMQRASession method createTopic.

/**
 * Create a topic
 *
 * @param topicName The topic name
 * @return The topic
 * @throws JMSException Thrown if an error occurs
 */
@Override
public Topic createTopic(final String topicName) throws JMSException {
    if (cri.getType() == ActiveMQRAConnectionFactory.QUEUE_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION) {
        throw new IllegalStateException("Cannot create topic for javax.jms.QueueSession");
    }
    Session session = getSessionInternal();
    if (ActiveMQRASession.trace) {
        ActiveMQRALogger.LOGGER.trace("createTopic " + session + " topicName=" + topicName);
    }
    Topic result = session.createTopic(topicName);
    if (ActiveMQRASession.trace) {
        ActiveMQRALogger.LOGGER.trace("createdTopic " + session + " topic=" + result);
    }
    return result;
}
Also used : IllegalStateException(javax.jms.IllegalStateException) TemporaryTopic(javax.jms.TemporaryTopic) Topic(javax.jms.Topic) XAQueueSession(javax.jms.XAQueueSession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) TopicSession(javax.jms.TopicSession) XATopicSession(javax.jms.XATopicSession) QueueSession(javax.jms.QueueSession)

Example 9 with IllegalStateException

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

the class ActiveMQRASession method createDurableSubscriber.

/**
 * Create a durable topic subscriber
 *
 * @param topic The topic
 * @param name  The name
 * @return The subscriber
 * @throws JMSException Thrown if an error occurs
 */
@Override
public TopicSubscriber createDurableSubscriber(final Topic topic, final String name) throws JMSException {
    if (cri.getType() == ActiveMQRAConnectionFactory.QUEUE_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION) {
        throw new IllegalStateException("Cannot create durable subscriber from javax.jms.QueueSession");
    }
    lock();
    try {
        Session session = getSessionInternal();
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("createDurableSubscriber " + session + " topic=" + topic + " name=" + name);
        }
        TopicSubscriber result = session.createDurableSubscriber(topic, name);
        result = new ActiveMQRATopicSubscriber(result, this);
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("createdDurableSubscriber " + session + " ActiveMQTopicSubscriber=" + result);
        }
        addConsumer(result);
        return result;
    } finally {
        unlock();
    }
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) IllegalStateException(javax.jms.IllegalStateException) XAQueueSession(javax.jms.XAQueueSession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) TopicSession(javax.jms.TopicSession) XATopicSession(javax.jms.XATopicSession) QueueSession(javax.jms.QueueSession)

Example 10 with IllegalStateException

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

the class ActiveMQRASession method createQueue.

/**
 * Create a queue
 *
 * @param queueName The queue name
 * @return The queue
 * @throws JMSException Thrown if an error occurs
 */
@Override
public Queue createQueue(final String queueName) throws JMSException {
    if (cri.getType() == ActiveMQRAConnectionFactory.TOPIC_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) {
        throw new IllegalStateException("Cannot create browser or javax.jms.TopicSession");
    }
    Session session = getSessionInternal();
    if (ActiveMQRASession.trace) {
        ActiveMQRALogger.LOGGER.trace("createQueue " + session + " queueName=" + queueName);
    }
    Queue result = session.createQueue(queueName);
    if (ActiveMQRASession.trace) {
        ActiveMQRALogger.LOGGER.trace("createdQueue " + session + " queue=" + result);
    }
    return result;
}
Also used : IllegalStateException(javax.jms.IllegalStateException) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) XAQueueSession(javax.jms.XAQueueSession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) TopicSession(javax.jms.TopicSession) XATopicSession(javax.jms.XATopicSession) QueueSession(javax.jms.QueueSession)

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