Connection Testing Java EE Compliance Pooled JMS Connection Objects

4-8 Programming JMS for Oracle WebLogic Server

4.3.3 Connection Testing

The JMS wrapper classes monitor each connection that is established to the JMS provider. They do this in two ways: ■ Registering a JMS ExceptionListener object on the connection. ■ Testing the connection every two minutes by sending a message to a temporary queue or topic and then receiving it again.

4.3.4 Java EE Compliance

The Java EE specification states that you should not be allowed to make certain JMS API calls inside a Java EE application. The JMS wrappers enforce these restrictions by throwing the following exceptions when they are violated: ■ On the connection object, the methods createConnectionConsumer, createDurableConnectionConsumer, setClientID, setExceptionListener, and stop should not be called. ■ On the session object, the methods getMessageListener and setMessageListener should not be called. ■ On the consumer object a QueueReceiver or TopicSubscriber object, the methods getMessageListener and setMessageListener should not be called. Furthermore, the createSession method, and the associated createQueueSession and createTopicSession methods, are handled differently. The createSession method takes two parameters: an acknowledgement mode and a transacted flag. When used inside an EJB, these two parameters are ignored. If a transaction is present, then the JMS session is enlisted in the transaction as described in Section 4.3.1, Automatically Enlisting Transactions ; otherwise, it is not. By default, the acknowledgement mode is set to auto acknowledge. This behavior is expected by the Java EE specification. Inside a servlet, however, the parameters to createQueueSession and createTopicSession are handled normally, and users can make use of all the various message acknowledgement modes.

4.3.5 Pooled JMS Connection Objects

The JMS wrappers pool various session objects in order to make code like the example provided in Section 4.6.2, Sending a JMS Message In a Java EE Container more efficient. A pooled JMS connection is a session pool used by EJBs and servlets that use a resource-ref element in their deployment descriptor to define their JMS connection factories, as discussed in Section 4.1.1.1, Declaring a Wrapped JMS Factory using Deployment Descriptors. Note: This may make it more difficult to receive messages from inside an EJB, but the recommended way to receive messages from inside an EJB is to use a MDB, as described in Programming Message-Driven Beans for Oracle WebLogic Server. Enhanced Support for Using WebLogic JMS with EJBs and Servlets 4-9

4.3.6 Monitoring Pooled Connections