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);
}
}
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();
}
}
}
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();
}
}
}
Aggregations