jsr343-experts@jms-spec.java.net

[jsr343-experts] Re: (JMS_SPEC-48) Specify that connection.stop() or close() may not be called from a MessageListener

From: Nigel Deakin <nigel.deakin_at_oracle.com>
Date: Wed, 05 Dec 2012 17:21:02 +0000

(Sorry if all these emails arrive at the same time: java.net has been down today)

On 05/12/2012 14:41, Nigel Deakin wrote:
> On 05/12/2012 14:24, Nigel Deakin wrote:
>> I'd like to revisit an old issue that we discussed back in January
>> http://java.net/jira/browse/JMS_SPEC-48
>> Specify that Connection.stop() or Connection.close() may not be called from a MessageListener

As promised, I've now drafted the necessary API changes:

New javadoc comment on MessageConsumer.close():
http://jms-spec.java.net/2.0-SNAPSHOT/apidocs/javax/jms/MessageConsumer.html#close%28%29

         * This call blocks until a {_at_code receive} or message listener in progress
         * has completed. A blocked message consumer {_at_code receive} call returns
         * null when this message consumer is closed.
         * <p>
         * A {_at_code MessageListener} must not attempt to close its own
         * {_at_code MessageConsumer} as this would lead to deadlock. The JMS provider
         * must detect this and throw a {_at_code IllegalStateException}.
         *
         * @exception IllegalStateException
         * this method has been called by a {_at_code MessageListener}
         * on its own {_at_code MessageConsumer}

Note that the words "this call blocks until a... message listener in progress has completed" are not new and were in JMS
1.1.

New javadoc comment on JMSConsumer.close()
http://jms-spec.java.net/2.0-SNAPSHOT/apidocs/javax/jms/JMSConsumer.html#close%28%29

         * This call blocks until a {_at_code receive} or message listener in progress has completed.
         * A blocked {_at_code receive} call returns null when
         * this {_at_code JMSConsumer} is closed.
         * <p>
         * A {_at_code MessageListener} must not attempt to close its own
         * {_at_code JMSConsumer} as this would lead to deadlock. The JMS provider
         * must detect this and throw a {_at_code IllegalStateRuntimeException}.
         *
           * @exception IllegalStateRuntimeException
         * this method has been called by a {_at_code MessageListener}
         * on its own {_at_code JMSConsumer}

In addition I've added a new section to the spec: 4.5.3 "Closing a MessageConsumer"

"When the MessageConsumer's close method is invoked it should not return until its message processing has been shut down
in an orderly fashion. This means that none of its message listeners are running, and that if there is a pending
receive, it has returned with either null or a message.

"A message listener must not attempt to close its own MessageConsumer as this would lead to deadlock. The JMS provider
must detect this and throw a javax.jms.IllegalStateException."

(I intend to generalise this section to cover JMSContext as part of a later spec reworking).

Nigel