Class JmsAccessor
- All Implemented Interfaces:
InitializingBean
- Direct Known Subclasses:
JmsDestinationAccessor
JmsTemplate and other
JMS-accessing gateway helpers, defining common properties such as the
JMS ConnectionFactory to operate on. The subclass
JmsDestinationAccessor
adds further, destination-related properties.
Not intended to be used directly.
See JmsTemplate.
- Since:
- 1.2
- Author:
- Juergen Hoeller, Sam Brannen
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.logging.LogLogger available to subclasses. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.protected JmsExceptionconvertJmsAccessException(jakarta.jms.JMSException ex) Convert the specified checkedJMSExceptionto a Spring runtimeJmsExceptionequivalent.protected jakarta.jms.ConnectionCreate a JMS Connection via this template's ConnectionFactory.protected jakarta.jms.SessioncreateSession(jakarta.jms.Connection con) Create a JMS Session for the given Connection.@Nullable jakarta.jms.ConnectionFactoryReturn the ConnectionFactory that this accessor uses for obtaining JMSConnections.intReturn the acknowledgement mode for JMSsessions.protected booleanisClientAcknowledge(jakarta.jms.Session session) Determine whether the given Session is in client acknowledge mode.booleanReturn whether the JMSsessionsused by this accessor are supposed to be transacted.protected final jakarta.jms.ConnectionFactoryObtain the ConnectionFactory for actual use.voidsetConnectionFactory(@Nullable jakarta.jms.ConnectionFactory connectionFactory) Set the ConnectionFactory to use for obtaining JMSConnections.voidsetSessionAcknowledgeMode(int sessionAcknowledgeMode) Set the JMS acknowledgement mode that is used when creating a JMSSessionto send a message.voidsetSessionAcknowledgeModeName(String constantName) Set the JMS acknowledgement mode by the name of the corresponding constant in the JMSSessioninterface — for example,"CLIENT_ACKNOWLEDGE".voidsetSessionTransacted(boolean sessionTransacted) Set the transaction mode that is used when creating a JMSSession.
-
Field Details
-
logger
protected final org.apache.commons.logging.Log loggerLogger available to subclasses.
-
-
Constructor Details
-
JmsAccessor
public JmsAccessor()
-
-
Method Details
-
setConnectionFactory
Set the ConnectionFactory to use for obtaining JMSConnections. -
getConnectionFactory
Return the ConnectionFactory that this accessor uses for obtaining JMSConnections. -
obtainConnectionFactory
protected final jakarta.jms.ConnectionFactory obtainConnectionFactory()Obtain the ConnectionFactory for actual use.- Returns:
- the ConnectionFactory (never
null) - Throws:
IllegalStateException- in case of no ConnectionFactory set- Since:
- 5.0
-
setSessionTransacted
public void setSessionTransacted(boolean sessionTransacted) Set the transaction mode that is used when creating a JMSSession. Default is "false".Note that within a JTA transaction, the parameters passed to
create(Queue/Topic)Session(boolean transacted, int acknowledgeMode)method are not taken into account. Depending on the Jakarta EE transaction context, the container makes its own decisions on these values. Analogously, these parameters are not taken into account within a locally managed transaction either, since the accessor operates on an existing JMS Session in this case.Setting this flag to "true" will use a short local JMS transaction when running outside a managed transaction, and a synchronized local JMS transaction in case of a managed transaction (other than an XA transaction) being present. This has the effect of a local JMS transaction being managed alongside the main transaction (which might be a native JDBC transaction), with the JMS transaction committing right after the main transaction.
- See Also:
-
isSessionTransacted
public boolean isSessionTransacted()Return whether the JMSsessionsused by this accessor are supposed to be transacted.- See Also:
-
setSessionAcknowledgeModeName
Set the JMS acknowledgement mode by the name of the corresponding constant in the JMSSessioninterface — for example,"CLIENT_ACKNOWLEDGE".If you want to use vendor-specific extensions to the acknowledgement mode, use
setSessionAcknowledgeMode(int)instead.- Parameters:
constantName- the name of theSessionacknowledge mode constant- See Also:
-
setSessionAcknowledgeMode
public void setSessionAcknowledgeMode(int sessionAcknowledgeMode) Set the JMS acknowledgement mode that is used when creating a JMSSessionto send a message.Default is
Session.AUTO_ACKNOWLEDGE.Vendor-specific extensions to the acknowledgement mode can be set here as well.
Note that inside an EJB, the parameters to the
create(Queue/Topic)Session(boolean transacted, int acknowledgeMode)method are not taken into account. Depending on the transaction context in the EJB, the container makes its own decisions on these values. See section 17.3.5 of the EJB spec.- Parameters:
sessionAcknowledgeMode- the acknowledgement mode constant- See Also:
-
getSessionAcknowledgeMode
public int getSessionAcknowledgeMode()Return the acknowledgement mode for JMSsessions. -
afterPropertiesSet
public void afterPropertiesSet()Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
convertJmsAccessException
Convert the specified checkedJMSExceptionto a Spring runtimeJmsExceptionequivalent.The default implementation delegates to the
JmsUtils.convertJmsAccessException(JMSException)method.- Parameters:
ex- the original checkedJMSExceptionto convert- Returns:
- the Spring runtime
JmsExceptionwrappingex - See Also:
-
createConnection
protected jakarta.jms.Connection createConnection() throws jakarta.jms.JMSExceptionCreate a JMS Connection via this template's ConnectionFactory.This implementation uses JMS 1.1 API.
- Returns:
- the new JMS Connection
- Throws:
jakarta.jms.JMSException- if thrown by JMS API methods- See Also:
-
createSession
protected jakarta.jms.Session createSession(jakarta.jms.Connection con) throws jakarta.jms.JMSException Create a JMS Session for the given Connection.This implementation uses JMS 1.1 API.
- Parameters:
con- the JMS Connection to create a Session for- Returns:
- the new JMS Session
- Throws:
jakarta.jms.JMSException- if thrown by JMS API methods- See Also:
-
isClientAcknowledge
protected boolean isClientAcknowledge(jakarta.jms.Session session) throws jakarta.jms.JMSException Determine whether the given Session is in client acknowledge mode.This implementation uses JMS 1.1 API.
- Parameters:
session- the JMS Session to check- Returns:
- whether the given Session is in client acknowledge mode
- Throws:
jakarta.jms.JMSException- if thrown by JMS API methods- See Also:
-