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

public Class JmsResourceHolder

extends ResourceHolderSupport
Class Inheritance
Known Direct Subclasses
org.springframework.jms.connection.JmsTransactionManager.LazyJmsResourceHolder, org.springframework.jms.listener.LocallyExposedJmsResourceHolder
Imports
java.lang.reflect.Method, java.util.ArrayDeque, .Deque, .HashMap, .Map, jakarta.jms.Connection, .ConnectionFactory, .JMSException, .Session, .TransactionInProgressException, org.apache.commons.logging.Log, .LogFactory, org.springframework.lang.Nullable, org.springframework.transaction.support.ResourceHolderSupport, .TransactionSynchronizationManager, org.springframework.util.Assert, .CollectionUtils, .ReflectionUtils

Resource holder wrapping a JMS Connection and a JMS Session. JmsTransactionManager binds instances of this class to the thread, for a given JMS ConnectionFactory.

Note

This is an SPI class, not intended to be used by applications.

Author
Juergen Hoeller
Since
1.1
See Also
JmsTransactionManager, org.springframework.jms.core.JmsTemplate

Field Summary

Modifier and TypeField and Description
private ConnectionFactory
private final Deque<Connection>
private boolean
private static final Log
private final Deque<Session>
private final Map<Connection, Deque<Session>>

Constructor Summary

AccessConstructor and Description
public
JmsResourceHolder()

Create a new JmsResourceHolder that is open for resources to be added.

public
JmsResourceHolder(ConnectionFactory
the JMS ConnectionFactory that this resource holder is associated with (may be null)
connectionFactory
)

Create a new JmsResourceHolder that is open for resources to be added.

public
JmsResourceHolder(Session
the JMS Session
session
)

Create a new JmsResourceHolder for the given JMS Session.

public
JmsResourceHolder(Connection
the JMS Connection
connection
,
Session
the JMS Session
session
)

Create a new JmsResourceHolder for the given JMS resources.

public
JmsResourceHolder(ConnectionFactory
the JMS ConnectionFactory that this resource holder is associated with (may be null)
connectionFactory
,
Connection
the JMS Connection
connection
,
Session
the JMS Session
session
)

Create a new JmsResourceHolder for the given JMS resources.

Method Summary

Modifier and TypeMethod and Description
public final void
addConnection(Connection connection)

Add the given Connection to this resource holder.

public final void
addSession(Session session)

Add the given Session to this resource holder.

public final void
addSession(Session session, Connection connection)

Add the given Session to this resource holder, registered for a specific Connection.

public void
closeAll()

Close all of this resource holder's Sessions and clear its state.

public void
commitAll()

Commit all of this resource holder's Sessions.

public boolean
containsSession(Session session)

Determine whether the given Session is registered with this resource holder.

public Connection
getConnection()

Return this resource holder's default Connection, or null if none.

public <C extends Connection> C
getConnection(Class<C> connectionType)

Return this resource holder's Connection of the given type, or null if none.

pack-priv Session
getOriginalSession()

Return an existing original Session, if any.

public Session
getSession()

Return this resource holder's default Session, or null if none.

public <S extends Session> S
getSession(Class<S> sessionType)

Return this resource holder's Session of the given type, or null if none.

public <S extends Session> S
getSession(Class<S> sessionType, Connection connection)

Return this resource holder's Session of the given type for the given connection, or null if none.

public final boolean
isFrozen()

Return whether this resource holder is frozen, i.e. does not allow for adding further Connections and Sessions to it.

Inherited from org.springframework.transaction.support.ResourceHolderSupport:
cleargetDeadlinegetTimeToLiveInMillisgetTimeToLiveInSecondshasTimeoutisOpenisRollbackOnlyisSynchronizedWithTransactionisVoidreleasedrequestedresetresetRollbackOnlysetRollbackOnlysetSynchronizedWithTransactionsetTimeoutInMillissetTimeoutInSecondsunbound

Field Detail

connectionFactoryback to summary
private ConnectionFactory connectionFactory
Annotations
@Nullable
connectionsback to summary
private final Deque<Connection> connections
frozenback to summary
private boolean frozen
loggerback to summary
private static final Log logger
sessionsback to summary
private final Deque<Session> sessions
sessionsPerConnectionback to summary
private final Map<Connection, Deque<Session>> sessionsPerConnection

Constructor Detail

JmsResourceHolderback to summary
public JmsResourceHolder()

Create a new JmsResourceHolder that is open for resources to be added.

See Also
addConnection, addSession
JmsResourceHolderback to summary
public JmsResourceHolder(ConnectionFactory connectionFactory)

Create a new JmsResourceHolder that is open for resources to be added.

Parameters
connectionFactory:ConnectionFactory

the JMS ConnectionFactory that this resource holder is associated with (may be null)

JmsResourceHolderback to summary
public JmsResourceHolder(Session session)

Create a new JmsResourceHolder for the given JMS Session.

Parameters
session:Session

the JMS Session

JmsResourceHolderback to summary
public JmsResourceHolder(Connection connection, Session session)

Create a new JmsResourceHolder for the given JMS resources.

Parameters
connection:Connection

the JMS Connection

session:Session

the JMS Session

JmsResourceHolderback to summary
public JmsResourceHolder(ConnectionFactory connectionFactory, Connection connection, Session session)

Create a new JmsResourceHolder for the given JMS resources.

Parameters
connectionFactory:ConnectionFactory

the JMS ConnectionFactory that this resource holder is associated with (may be null)

connection:Connection

the JMS Connection

session:Session

the JMS Session

Method Detail

addConnectionback to summary
public final void addConnection(Connection connection)

Add the given Connection to this resource holder.

addSessionback to summary
public final void addSession(Session session)

Add the given Session to this resource holder.

addSessionback to summary
public final void addSession(Session session, Connection connection)

Add the given Session to this resource holder, registered for a specific Connection.

closeAllback to summary
public void closeAll()

Close all of this resource holder's Sessions and clear its state.

See Also
Session#close()
commitAllback to summary
public void commitAll() throws JMSException

Commit all of this resource holder's Sessions.

Exceptions
JMSException:
if thrown from a Session commit attempt
See Also
Session#commit()
containsSessionback to summary
public boolean containsSession(Session session)

Determine whether the given Session is registered with this resource holder.

getConnectionback to summary
public Connection getConnection()

Return this resource holder's default Connection, or null if none.

Annotations
@Nullable
getConnectionback to summary
public <C extends Connection> C getConnection(Class<C> connectionType)

Return this resource holder's Connection of the given type, or null if none.

Annotations
@Nullable
getOriginalSessionback to summary
pack-priv Session getOriginalSession()

Return an existing original Session, if any.

In contrast to getSession(), this must not lazily initialize a new Session, not even in JmsResourceHolder subclasses.

Annotations
@Nullable
getSessionback to summary
public Session getSession()

Return this resource holder's default Session, or null if none.

Annotations
@Nullable
getSessionback to summary
public <S extends Session> S getSession(Class<S> sessionType)

Return this resource holder's Session of the given type, or null if none.

Annotations
@Nullable
getSessionback to summary
public <S extends Session> S getSession(Class<S> sessionType, Connection connection)

Return this resource holder's Session of the given type for the given connection, or null if none.

Annotations
@Nullable
isFrozenback to summary
public final boolean isFrozen()

Return whether this resource holder is frozen, i.e. does not allow for adding further Connections and Sessions to it.

See Also
addConnection, addSession