The Spring Framework

org.springframework.jms.listener.serversession
Class ServerSessionMessageListenerContainer

java.lang.Object
  extended by org.springframework.jms.support.JmsAccessor
      extended by org.springframework.jms.support.destination.JmsDestinationAccessor
          extended by org.springframework.jms.listener.AbstractJmsListeningContainer
              extended by org.springframework.jms.listener.AbstractMessageListenerContainer
                  extended by org.springframework.jms.listener.serversession.ServerSessionMessageListenerContainer
All Implemented Interfaces:
BeanNameAware, DisposableBean, InitializingBean, Lifecycle, ListenerSessionManager
Direct Known Subclasses:
ServerSessionMessageListenerContainer102

public class ServerSessionMessageListenerContainer
extends AbstractMessageListenerContainer
implements ListenerSessionManager

Message listener container that builds on the ServerSessionPool SPI, creating JMS ServerSession instances through a pluggable ServerSessionFactory.

NOTE: This class requires a JMS 1.1+ provider, because it builds on the domain-independent API. Use the ServerSessionMessageListenerContainer102 subclass for a JMS 1.0.2 provider, e.g. when running on a J2EE 1.3 server.

The default ServerSessionFactory is a SimpleServerSessionFactory, which will create a new ServerSession for each listener execution. Consider specifying a CommonsPoolServerSessionFactory to reuse JMS Sessions and/or to limit the number of concurrent ServerSession executions.

See the AbstractMessageListenerContainer javadoc for details on acknowledge modes and other configuration options.

This is an 'advanced' (special-purpose) message listener container. For a simpler message listener container, in particular when using a JMS provider without ServerSessionPool support, consider using SimpleMessageListenerContainer. For a general one-stop shop that is nevertheless very flexible, consider DefaultMessageListenerContainer.

Since:
2.0
Author:
Juergen Hoeller
See Also:
SimpleMessageListenerContainer, DefaultMessageListenerContainer

Nested Class Summary
 
Nested classes/interfaces inherited from class org.springframework.jms.listener.AbstractJmsListeningContainer
AbstractJmsListeningContainer.SharedConnectionNotInitializedException
 
Field Summary
 
Fields inherited from class org.springframework.jms.listener.AbstractJmsListeningContainer
lifecycleMonitor, sharedConnectionMonitor
 
Fields inherited from class org.springframework.jms.support.JmsAccessor
logger
 
Constructor Summary
ServerSessionMessageListenerContainer()
           
 
Method Summary
protected  ConnectionConsumer createConsumer(Connection con, Destination destination, ServerSessionPool pool)
          Create a JMS ConnectionConsumer for the given Connection.
 Session createListenerSession()
          Create a JMS Session with the specified listener registered.
protected  ServerSessionPool createServerSessionPool()
          Create a JMS ServerSessionPool for the specified message listener, via this container's ServerSessionFactory.
protected  void doInitialize()
          Creates a JMS ServerSessionPool for the specified listener and registers it with a JMS ConnectionConsumer for the specified destination.
protected  void doShutdown()
          Close the JMS ServerSessionPool for the specified message listener, via this container's ServerSessionFactory, and subsequently also this container's JMS ConnectionConsumer.
 void executeListenerSession(Session session)
          Execute the given JMS Session, triggering invocation of its listener.
protected  ConnectionConsumer getConsumer()
          Return the JMS ConnectionConsumer used by this message listener container.
protected  int getMaxMessagesPerTask()
          Return the maximum number of messages to load into a JMS Session.
protected  ServerSessionFactory getServerSessionFactory()
          Return the Spring ServerSessionFactory to use.
 void setMaxMessagesPerTask(int maxMessagesPerTask)
          Set the maximum number of messages to load into a JMS Session.
 void setServerSessionFactory(ServerSessionFactory serverSessionFactory)
          Set the Spring ServerSessionFactory to use.
protected  boolean sharedConnectionEnabled()
          Always use a shared JMS Connection.
 
Methods inherited from class org.springframework.jms.listener.AbstractMessageListenerContainer
checkMessageListener, commitIfNecessary, doExecuteListener, doInvokeListener, doInvokeListener, executeListener, getDestination, getDestinationName, getDurableSubscriptionName, getExceptionListener, getMessageListener, getMessageSelector, handleListenerException, invokeExceptionListener, invokeListener, isAcceptMessagesWhileStopping, isExposeListenerSession, isSessionLocallyTransacted, isSubscriptionDurable, rollbackIfNecessary, rollbackOnExceptionIfNecessary, setAcceptMessagesWhileStopping, setDestination, setDestinationName, setDurableSubscriptionName, setExceptionListener, setExposeListenerSession, setMessageListener, setMessageSelector, setSubscriptionDurable, validateConfiguration
 
Methods inherited from class org.springframework.jms.listener.AbstractJmsListeningContainer
afterPropertiesSet, createSharedConnection, destroy, doRescheduleTask, doStart, doStop, establishSharedConnection, getBeanName, getClientId, getSharedConnection, initialize, isActive, isRunning, prepareSharedConnection, refreshSharedConnection, rescheduleTaskIfNecessary, setAutoStartup, setBeanName, setClientId, shutdown, start, startSharedConnection, stop, stopSharedConnection, waitWhileNotRunning
 
Methods inherited from class org.springframework.jms.support.destination.JmsDestinationAccessor
getDestinationResolver, isPubSubDomain, resolveDestinationName, setDestinationResolver, setPubSubDomain
 
Methods inherited from class org.springframework.jms.support.JmsAccessor
convertJmsAccessException, createConnection, createSession, getConnectionFactory, getSessionAcknowledgeMode, isClientAcknowledge, isSessionTransacted, setConnectionFactory, setSessionAcknowledgeMode, setSessionAcknowledgeModeName, setSessionTransacted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerSessionMessageListenerContainer

public ServerSessionMessageListenerContainer()
Method Detail

setServerSessionFactory

public void setServerSessionFactory(ServerSessionFactory serverSessionFactory)
Set the Spring ServerSessionFactory to use.

Default is a plain SimpleServerSessionFactory. Consider using a CommonsPoolServerSessionFactory to reuse JMS Sessions and/or to limit the number of concurrent ServerSession executions.

See Also:
SimpleServerSessionFactory, CommonsPoolServerSessionFactory

getServerSessionFactory

protected ServerSessionFactory getServerSessionFactory()
Return the Spring ServerSessionFactory to use.


setMaxMessagesPerTask

public void setMaxMessagesPerTask(int maxMessagesPerTask)
Set the maximum number of messages to load into a JMS Session. Default is 1.

See the corresponding JMS createConnectionConsumer argument for details.

See Also:
Connection.createConnectionConsumer(javax.jms.Destination, java.lang.String, javax.jms.ServerSessionPool, int)

getMaxMessagesPerTask

protected int getMaxMessagesPerTask()
Return the maximum number of messages to load into a JMS Session.


sharedConnectionEnabled

protected final boolean sharedConnectionEnabled()
Always use a shared JMS Connection.

Specified by:
sharedConnectionEnabled in class AbstractJmsListeningContainer
See Also:
AbstractJmsListeningContainer.getSharedConnection()

doInitialize

protected void doInitialize()
                     throws JMSException
Creates a JMS ServerSessionPool for the specified listener and registers it with a JMS ConnectionConsumer for the specified destination.

Specified by:
doInitialize in class AbstractJmsListeningContainer
Throws:
JMSException - if registration failed
See Also:
createServerSessionPool(), createConsumer(javax.jms.Connection, javax.jms.Destination, javax.jms.ServerSessionPool)

createServerSessionPool

protected ServerSessionPool createServerSessionPool()
                                             throws JMSException
Create a JMS ServerSessionPool for the specified message listener, via this container's ServerSessionFactory.

This message listener container implements the ListenerSessionManager interface, hence can be passed to the ServerSessionFactory itself.

Returns:
the ServerSessionPool
Throws:
JMSException - if creation of the ServerSessionPool failed
See Also:
setServerSessionFactory(org.springframework.jms.listener.serversession.ServerSessionFactory), ServerSessionFactory.getServerSession(ListenerSessionManager)

getConsumer

protected final ConnectionConsumer getConsumer()
Return the JMS ConnectionConsumer used by this message listener container. Available after initialization.


doShutdown

protected void doShutdown()
                   throws JMSException
Close the JMS ServerSessionPool for the specified message listener, via this container's ServerSessionFactory, and subsequently also this container's JMS ConnectionConsumer.

This message listener container implements the ListenerSessionManager interface, hence can be passed to the ServerSessionFactory itself.

Specified by:
doShutdown in class AbstractJmsListeningContainer
Throws:
JMSException - if shutdown failed
See Also:
setServerSessionFactory(org.springframework.jms.listener.serversession.ServerSessionFactory), ServerSessionFactory.getServerSession(ListenerSessionManager)

createListenerSession

public Session createListenerSession()
                              throws JMSException
Create a JMS Session with the specified listener registered. Listener execution is delegated to the executeListener method.

Default implementation simply calls setMessageListener on a newly created JMS Session, according to the JMS specification's ServerSessionPool section.

Specified by:
createListenerSession in interface ListenerSessionManager
Returns:
the JMS Session
Throws:
JMSException - if thrown by JMS API methods
See Also:
AbstractMessageListenerContainer.executeListener(javax.jms.Session, javax.jms.Message)

executeListenerSession

public void executeListenerSession(Session session)
Execute the given JMS Session, triggering invocation of its listener.

Default implementation simply calls run() on the JMS Session, according to the JMS specification's ServerSessionPool section.

Specified by:
executeListenerSession in interface ListenerSessionManager
Parameters:
session - the JMS Session to execute
See Also:
Session.run()

createConsumer

protected ConnectionConsumer createConsumer(Connection con,
                                            Destination destination,
                                            ServerSessionPool pool)
                                     throws JMSException
Create a JMS ConnectionConsumer for the given Connection.

This implementation uses JMS 1.1 API.

Parameters:
con - the JMS Connection to create a Session for
destination - the JMS Destination to listen to
pool - the ServerSessionpool to use
Returns:
the new JMS Session
Throws:
JMSException - if thrown by JMS API methods

The Spring Framework

Copyright © 2002-2007 The Spring Framework.