Search in sources :

Example 46 with IllegalStateException

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

the class RMQMessageConsumer method setMessageListener.

/**
 * From the on-line JavaDoc: <blockquote>
 * <p>
 * Sets the message consumer's {@link MessageListener}.
 * </p>
 * <p>
 * Setting the message listener to <code>null</code> is the equivalent of clearing the message listener for the
 * message consumer.
 * </p>
 * <p>
 * The effect of calling {@link #setMessageListener} while messages are being consumed by an existing listener or
 * the consumer is being used to consume messages synchronously is undefined.
 * </p>
 * </blockquote>
 * <p>
 * Notwithstanding, we attempt to clear the previous listener gracefully (by cancelling the Consumer) if there is
 * one.
 * </p>
 * {@inheritDoc}
 */
@Override
public void setMessageListener(MessageListener messageListener) throws JMSException {
    if (messageListener == this.messageListener) {
        // no change, so do nothing
        logger.info("MessageListener({}) already set", messageListener);
        return;
    }
    if (!this.session.aSyncAllowed()) {
        throw new IllegalStateException("A MessageListener cannot be set if receive() is outstanding on a session. (See JMS 1.1 ยง4.4.6.)");
    }
    logger.trace("setting MessageListener({})", messageListener);
    // if there is any
    this.removeListenerConsumer();
    this.messageListener = messageListener;
    try {
        // if needed
        this.setNewListenerConsumer(messageListener);
    } catch (JMSException e) {
        throw e;
    } catch (Exception e) {
        throw new RMQJMSException(e);
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) RMQJMSException(com.rabbitmq.jms.util.RMQJMSException) JMSException(javax.jms.JMSException) RMQJMSException(com.rabbitmq.jms.util.RMQJMSException) AbortedException(com.rabbitmq.jms.util.AbortedException) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) IOException(java.io.IOException) IllegalStateException(javax.jms.IllegalStateException) JMSException(javax.jms.JMSException) RMQJMSException(com.rabbitmq.jms.util.RMQJMSException)

Example 47 with IllegalStateException

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

the class RMQSession method commit.

/**
 * {@inheritDoc}
 */
@Override
public void commit() throws JMSException {
    logger.trace("commit transaction on session {}", this);
    illegalStateExceptionIfClosed();
    if (!this.transacted)
        throw new IllegalStateException("Session is not transacted");
    if (this.enterCommittingBlock()) {
        try {
            // Call commit on the channel.
            // All messages ought already to have been acked.
            this.channel.txCommit();
            this.clearUncommittedTags();
        } catch (Exception x) {
            this.logger.error("RabbitMQ exception on channel.txCommit() in session {}", this, x);
            throw new RMQJMSException(x);
        } finally {
            this.leaveCommittingBlock();
        }
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) RMQJMSException(com.rabbitmq.jms.util.RMQJMSException) TimeoutException(java.util.concurrent.TimeoutException) RMQJMSSelectorException(com.rabbitmq.jms.util.RMQJMSSelectorException) IllegalStateException(javax.jms.IllegalStateException) JMSException(javax.jms.JMSException) RMQJMSException(com.rabbitmq.jms.util.RMQJMSException) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) IOException(java.io.IOException) InvalidSelectorException(javax.jms.InvalidSelectorException)

Example 48 with IllegalStateException

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

the class RMQSession method rollback.

/**
 * {@inheritDoc}
 */
@Override
public void rollback() throws JMSException {
    logger.trace("rollback transaction on session {}", this);
    illegalStateExceptionIfClosed();
    if (!this.transacted)
        throw new IllegalStateException("Session is not transacted");
    if (this.enterCommittingBlock()) {
        try {
            // rollback the RabbitMQ transaction which may cause some messages to become unacknowledged
            this.channel.txRollback();
            if (this.nackOnRollback && this.uncommittedMessageTags.size() > 0) {
                for (Long dtag : this.uncommittedMessageTags) {
                    this.channel.basicNack(dtag, false, false);
                }
                this.channel.txCommit();
                this.clearUncommittedTags();
            }
            // requeue all unacknowledged messages (not automatically done by RabbitMQ)
            // requeue
            this.channel.basicRecover(true);
        } catch (IOException x) {
            this.logger.error("RabbitMQ exception on channel.txRollback() or channel.basicRecover(true) in session {}", this, x);
            throw new RMQJMSException(x);
        } finally {
            this.leaveCommittingBlock();
        }
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) RMQJMSException(com.rabbitmq.jms.util.RMQJMSException) IOException(java.io.IOException)

Aggregations

IllegalStateException (javax.jms.IllegalStateException)48 Session (javax.jms.Session)19 Connection (javax.jms.Connection)12 QueueSession (javax.jms.QueueSession)12 Test (org.junit.Test)12 JMSException (javax.jms.JMSException)11 TopicSession (javax.jms.TopicSession)11 XAQueueSession (javax.jms.XAQueueSession)11 XATopicSession (javax.jms.XATopicSession)11 ActiveMQSession (org.apache.activemq.artemis.jms.client.ActiveMQSession)11 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)6 IOException (java.io.IOException)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)3 RMQJMSException (com.rabbitmq.jms.util.RMQJMSException)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)3 ChannelPromise (io.netty.channel.ChannelPromise)3 MqttPubAckMessage (io.netty.handler.codec.mqtt.MqttPubAckMessage)3