类 CachingConnectionFactory
- java.lang.Object
- org.springframework.jms.connection.SingleConnectionFactory
- org.springframework.jms.connection.CachingConnectionFactory
- 所有已实现的接口:
ConnectionFactory
,ExceptionListener
,QueueConnectionFactory
,TopicConnectionFactory
,DisposableBean
,InitializingBean
public class CachingConnectionFactory extends SingleConnectionFactory
SingleConnectionFactory
subclass that addsSession
caching as wellMessageProducer
caching. This ConnectionFactory also switches the"reconnectOnException" property
to "true" by default, allowing for automatic recovery of the underlying Connection.By default, only one single Session will be cached, with further requested Sessions being created and disposed on demand. Consider raising the
"sessionCacheSize" value
in case of a high-concurrency environment.When using the JMS 1.0.2 API, this ConnectionFactory will switch into queue/topic mode according to the JMS API methods used at runtime:
createQueueConnection
andcreateTopicConnection
will lead to queue/topic mode, respectively; genericcreateConnection
calls will lead to a JMS 1.1 connection which is able to serve both modes.NOTE: This ConnectionFactory requires explicit closing of all Sessions obtained from its shared Connection. This is the usual recommendation for native JMS access code anyway. However, with this ConnectionFactory, its use is mandatory in order to actually allow for Session reuse.
Note also that MessageConsumers obtained from a cached Session won't get closed until the Session will eventually be removed from the pool. This may lead to semantic side effects in some cases. For a durable subscriber, the logical
Session.close()
call will also close the subscription. Re-registering a durable consumer for the same subscription on the same Session handle is not supported; close and reobtain a cached Session first.- 从以下版本开始:
- 2.5.3
- 作者:
- Juergen Hoeller
字段概要
从类继承的字段 org.springframework.jms.connection.SingleConnectionFactory
logger
构造器概要
构造器 构造器 说明 CachingConnectionFactory()
Create a new CachingConnectionFactory for bean-style usage.CachingConnectionFactory(ConnectionFactory targetConnectionFactory)
Create a new CachingConnectionFactory for the given target ConnectionFactory.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected Session
getCachedSessionProxy(Session target, LinkedList<Session> sessionList)
Wrap the given Session with a proxy that delegates every method call to it but adapts close calls.protected Session
getSession(Connection con, Integer mode)
Checks for a cached Session for the given mode.int
getSessionCacheSize()
Return the desired size for the JMS Session cache (per JMS Session type).boolean
isCacheConsumers()
Return whether to cache JMS MessageConsumers per JMS Session instance.boolean
isCacheProducers()
Return whether to cache JMS MessageProducers per JMS Session instance.void
resetConnection()
Resets the Session cache as well.void
setCacheConsumers(boolean cacheConsumers)
Specify whether to cache JMS MessageConsumers per JMS Session instance (more specifically: one MessageConsumer per Destination, selector String and Session).void
setCacheProducers(boolean cacheProducers)
Specify whether to cache JMS MessageProducers per JMS Session instance (more specifically: one MessageProducer per Destination and Session).void
setSessionCacheSize(int sessionCacheSize)
Specify the desired size for the JMS Session cache (per JMS Session type).从类继承的方法 org.springframework.jms.connection.SingleConnectionFactory
afterPropertiesSet, closeConnection, createConnection, createConnection, createQueueConnection, createQueueConnection, createSession, createTopicConnection, createTopicConnection, destroy, doCreateConnection, getClientId, getConnection, getExceptionListener, getSharedConnectionProxy, getTargetConnectionFactory, initConnection, isReconnectOnException, onException, prepareConnection, setClientId, setExceptionListener, setReconnectOnException, setTargetConnectionFactory
构造器详细资料
CachingConnectionFactory
public CachingConnectionFactory()
Create a new CachingConnectionFactory for bean-style usage.
CachingConnectionFactory
public CachingConnectionFactory(ConnectionFactory targetConnectionFactory)
Create a new CachingConnectionFactory for the given target ConnectionFactory.- 参数:
targetConnectionFactory
- the target ConnectionFactory
方法详细资料
setSessionCacheSize
public void setSessionCacheSize(int sessionCacheSize)
Specify the desired size for the JMS Session cache (per JMS Session type).This cache size is the maximum limit for the number of cached Sessions per session acknowledgement type (auto, client, dups_ok, transacted). As a consequence, the actual number of cached Sessions may be up to four times as high as the specified value - in the unlikely case of mixing and matching different acknowledgement types.
Default is 1: caching a single Session, (re-)creating further ones on demand. Specify a number like 10 if you'd like to raise the number of cached Sessions; that said, 1 may be sufficient for low-concurrency scenarios.
getSessionCacheSize
public int getSessionCacheSize()
Return the desired size for the JMS Session cache (per JMS Session type).
setCacheProducers
public void setCacheProducers(boolean cacheProducers)
Specify whether to cache JMS MessageProducers per JMS Session instance (more specifically: one MessageProducer per Destination and Session).Default is "true". Switch this to "false" in order to always recreate MessageProducers on demand.
isCacheProducers
public boolean isCacheProducers()
Return whether to cache JMS MessageProducers per JMS Session instance.
setCacheConsumers
public void setCacheConsumers(boolean cacheConsumers)
Specify whether to cache JMS MessageConsumers per JMS Session instance (more specifically: one MessageConsumer per Destination, selector String and Session). Note that durable subscribers will only be cached until logical closing of the Session handle.Default is "true". Switch this to "false" in order to always recreate MessageConsumers on demand.
isCacheConsumers
public boolean isCacheConsumers()
Return whether to cache JMS MessageConsumers per JMS Session instance.
resetConnection
public void resetConnection()
Resets the Session cache as well.
getSession
protected Session getSession(Connection con, Integer mode) throws JMSException
Checks for a cached Session for the given mode.- 覆盖:
getSession
在类中SingleConnectionFactory
- 参数:
con
- the JMS Connection to operate onmode
- the Session acknowledgement mode (Session.TRANSACTED
or one of the common modes)- 返回:
- the Session to use, or
null
to indicate creation of a raw standard Session - 抛出:
JMSException
- if thrown by the JMS API
getCachedSessionProxy
protected Session getCachedSessionProxy(Session target, LinkedList<Session> sessionList)
Wrap the given Session with a proxy that delegates every method call to it but adapts close calls. This is useful for allowing application code to handle a special framework Session just like an ordinary Session.- 参数:
target
- the original Session to wrapsessionList
- the List of cached Sessions that the given Session belongs to- 返回:
- the wrapped Session