Class JMSOperation
- java.lang.Object
-
- org.silverpeas.core.notification.system.JMSOperation
-
@Technical @Bean @Singleton public class JMSOperation extends Object
A JMS operation processor. But why?
In fact,JMSContext
can be used asapplication-managed
way or it can be used ascontainer-managed
.In the first way and according to the documentation, the
JMSContext
must be get by usingConnectionFactory
and it has to be explicitly closed when it is no more needed. For example:@Resource private javax.jms.ConnectionFactory jmsConnectionFactory; ... public void performSend(Destination destination , Serializable event) try (JMSContext context = jmsConnectionFactory.createContext()) { final JMSProducer producer = context.createProducer(); producer.send(destination, event); } }
So that is kind of manual management.
In the second way, the
JMSContext
must be injected and used directly. For example:@Inject private javax.jms.JMSContext context; ... public void performSend(Destination destination , Serializable event) final JMSProducer producer = context.createProducer(); producer.send(destination, event); }
There is no manual management here concerning the
JMSContext
because that is handled by the container.
But to be managed efficiently, a JTA transaction must exist, and also, the following rule must be verified (from documentation ofJMSContext
): Applications running in the Java EE web and EJB containers are not permitted to create more than one active session on a connection so combining them in a single object takes advantage of this restriction to offer a simpler API.So, to get the code the simplest possible in callers, this class provides static method that simplifies the processing of a JMS operation by observing the different mandatory rules concerning the
JMSContext
.- Author:
- Yohann Chastagnier
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
JMSOperation.Operation
Defines a JMS operation to perform.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
realize(JMSOperation.Operation operation)
Realizes a JMS operation with a managedJMSContext
.
-
-
-
Method Detail
-
realize
public static void realize(JMSOperation.Operation operation)
Realizes a JMS operation with a managedJMSContext
.- Parameters:
operation
- the operation to realize.- See Also:
JMSOperation
-
-