Top Description Fields Constructors Methods
org.springframework.jms.support

public abstract Class JmsAccessor

extends Object
implements InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean
Known Direct Subclasses
org.springframework.jms.support.destination.JmsDestinationAccessor
Imports
java.util.Map, jakarta.jms.Connection, .ConnectionFactory, .JMSException, .Session, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.factory.InitializingBean, org.springframework.jms.JmsException, org.springframework.lang.Nullable, org.springframework.util.Assert

Base class for org.springframework.jms.core.JmsTemplate and other JMS-accessing gateway helpers, defining common properties such as the JMS ConnectionFactory to operate on. The subclass org.springframework.jms.support.destination.JmsDestinationAccessor adds further, destination-related properties.

Not intended to be used directly. See org.springframework.jms.core.JmsTemplate.

Authors
Juergen Hoeller, Sam Brannen
Since
1.2
See Also
org.springframework.jms.support.destination.JmsDestinationAccessor, org.springframework.jms.core.JmsTemplate

Field Summary

Modifier and TypeField and Description
private ConnectionFactory
protected final Log
logger

Logger available to subclasses.

private int
private static final Map<String, Integer>
sessionConstants

Map of constant names to constant values for the constants defined in jakarta.jms.Session.

private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

protected JmsException

Returns:

the Spring runtime JmsException wrapping ex
convertJmsAccessException
(JMSException
the original checked JMSException to convert
ex
)

Convert the specified checked JMSException to a Spring runtime JmsException equivalent.

protected Connection

Returns:

the new JMS Connection
createConnection
()

Create a JMS Connection via this template's ConnectionFactory.

protected Session

Returns:

the new JMS Session
createSession
(Connection
the JMS Connection to create a Session for
con
)

Create a JMS Session for the given Connection.

public ConnectionFactory
getConnectionFactory()

Return the ConnectionFactory that this accessor uses for obtaining JMS Connections.

public int
getSessionAcknowledgeMode()

Return the acknowledgement mode for JMS sessions.

protected boolean

Returns:

whether the given Session is in client acknowledge mode
isClientAcknowledge
(Session
the JMS Session to check
session
)

Determine whether the given Session is in client acknowledge mode.

public boolean
isSessionTransacted()

Return whether the JMS sessions used by this accessor are supposed to be transacted.

protected final ConnectionFactory

Returns:

the ConnectionFactory (never null)
obtainConnectionFactory
()

Obtain the ConnectionFactory for actual use.

public void
setConnectionFactory(ConnectionFactory connectionFactory)

Set the ConnectionFactory to use for obtaining JMS Connections.

public void
setSessionAcknowledgeMode(int
the acknowledgement mode constant
sessionAcknowledgeMode
)

Set the JMS acknowledgement mode that is used when creating a JMS Session to send a message.

public void
setSessionAcknowledgeModeName(String
the name of the Session acknowledge mode constant
constantName
)

Set the JMS acknowledgement mode by the name of the corresponding constant in the JMS Session interface — for example, "CLIENT_ACKNOWLEDGE".

public void
setSessionTransacted(boolean sessionTransacted)

Set the transaction mode that is used when creating a JMS Session.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionFactoryback to summary
private ConnectionFactory connectionFactory
Annotations
@Nullable
loggerback to summary
protected final Log logger

Logger available to subclasses.

sessionAcknowledgeModeback to summary
private int sessionAcknowledgeMode
sessionConstantsback to summary
private static final Map<String, Integer> sessionConstants

Map of constant names to constant values for the constants defined in jakarta.jms.Session.

sessionTransactedback to summary
private boolean sessionTransacted

Constructor Detail

JmsAccessorback to summary
public JmsAccessor()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

Annotations
@Override
convertJmsAccessExceptionback to summary
protected JmsException convertJmsAccessException(JMSException ex)

Convert the specified checked JMSException to a Spring runtime JmsException equivalent.

The default implementation delegates to the JmsUtils#convertJmsAccessException method.

Parameters
ex:JMSException

the original checked JMSException to convert

Returns:JmsException

the Spring runtime JmsException wrapping ex

See Also
JmsUtils#convertJmsAccessException
createConnectionback to summary
protected Connection createConnection() throws JMSException

Create a JMS Connection via this template's ConnectionFactory.

This implementation uses JMS 1.1 API.

Returns:Connection

the new JMS Connection

Exceptions
JMSException:
if thrown by JMS API methods
See Also
jakarta.jms.ConnectionFactory#createConnection()
createSessionback to summary
protected Session createSession(Connection con) throws JMSException

Create a JMS Session for the given Connection.

This implementation uses JMS 1.1 API.

Parameters
con:Connection

the JMS Connection to create a Session for

Returns:Session

the new JMS Session

Exceptions
JMSException:
if thrown by JMS API methods
See Also
jakarta.jms.Connection#createSession(boolean, int)
getConnectionFactoryback to summary
public ConnectionFactory getConnectionFactory()

Return the ConnectionFactory that this accessor uses for obtaining JMS Connections.

Annotations
@Nullable
getSessionAcknowledgeModeback to summary
public int getSessionAcknowledgeMode()

Return the acknowledgement mode for JMS sessions.

isClientAcknowledgeback to summary
protected boolean isClientAcknowledge(Session session) throws JMSException

Determine whether the given Session is in client acknowledge mode.

This implementation uses JMS 1.1 API.

Parameters
session:Session

the JMS Session to check

Returns:boolean

whether the given Session is in client acknowledge mode

Exceptions
JMSException:
if thrown by JMS API methods
See Also
jakarta.jms.Session#getAcknowledgeMode(), jakarta.jms.Session#CLIENT_ACKNOWLEDGE
isSessionTransactedback to summary
public boolean isSessionTransacted()

Return whether the JMS sessions used by this accessor are supposed to be transacted.

See Also
setSessionTransacted(boolean)
obtainConnectionFactoryback to summary
protected final ConnectionFactory obtainConnectionFactory()

Obtain the ConnectionFactory for actual use.

Returns:ConnectionFactory

the ConnectionFactory (never null)

Exceptions
IllegalStateException:
in case of no ConnectionFactory set
Since
5.0
setConnectionFactoryback to summary
public void setConnectionFactory(ConnectionFactory connectionFactory)

Set the ConnectionFactory to use for obtaining JMS Connections.

setSessionAcknowledgeModeback to summary
public void setSessionAcknowledgeMode(int sessionAcknowledgeMode)

Set the JMS acknowledgement mode that is used when creating a JMS Session to 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:int

the acknowledgement mode constant

See Also
jakarta.jms.Session#AUTO_ACKNOWLEDGE, jakarta.jms.Session#CLIENT_ACKNOWLEDGE, jakarta.jms.Session#DUPS_OK_ACKNOWLEDGE, jakarta.jms.Session#SESSION_TRANSACTED, jakarta.jms.Connection#createSession(boolean, int)
setSessionAcknowledgeModeNameback to summary
public void setSessionAcknowledgeModeName(String constantName)

Set the JMS acknowledgement mode by the name of the corresponding constant in the JMS Session interface — for example, "CLIENT_ACKNOWLEDGE".

If you want to use vendor-specific extensions to the acknowledgement mode, use setSessionAcknowledgeMode(int) instead.

Parameters
constantName:String

the name of the Session acknowledge mode constant

See Also
jakarta.jms.Session#AUTO_ACKNOWLEDGE, jakarta.jms.Session#CLIENT_ACKNOWLEDGE, jakarta.jms.Session#DUPS_OK_ACKNOWLEDGE, jakarta.jms.Session#SESSION_TRANSACTED, jakarta.jms.Connection#createSession(int)
setSessionTransactedback to summary
public void setSessionTransacted(boolean sessionTransacted)

Set the transaction mode that is used when creating a JMS Session. 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
jakarta.jms.Connection#createSession(boolean, int)