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.AbstractMessageListenerContainer
              extended by org.springframework.jms.listener.serversession.ServerSessionMessageListenerContainer
All Implemented Interfaces:
DisposableBean, InitializingBean, Lifecycle, ListenerSessionManager
Direct Known Subclasses:
ServerSessionMessageListenerContainer102

public class ServerSessionMessageListenerContainer
extends AbstractMessageListenerContainer
implements ListenerSessionManager

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

This is the most sophisticated message listener container possible with standard JMS. It allows for dynamic management of JMS Sessions, potentially using a pool of Sessions that receive messages in parallel.

Note that 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 transaction options.

For a simpler message listener container, in particular if using a JMS provider without ServerSessionPool support, consider using SimpleMessageListenerContainer.

This class requires a JMS 1.1+ provider, because it builds on the domain-independent API. Use the ServerSessionMessageListenerContainer102 subclass for JMS 1.0.2 providers.

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

Nested Class Summary
 
Nested classes/interfaces inherited from class org.springframework.jms.listener.AbstractMessageListenerContainer
AbstractMessageListenerContainer.SharedConnectionNotInitializedException
 
Field Summary
 
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 destroyListener()
          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.
protected  void registerListener()
          Creates a JMS ServerSessionPool for the specified listener and registers it with a JMS ConnectionConsumer for the specified destination.
 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
afterPropertiesSet, checkMessageListener, commitIfNecessary, createConnection, createSession, destroy, doExecuteListener, doInvokeListener, doInvokeListener, doRescheduleTask, doStart, doStop, establishSharedConnection, executeListener, getClientId, getDestination, getDestinationName, getDurableSubscriptionName, getExceptionListener, getMessageListener, getMessageSelector, getSharedConnection, handleListenerException, initialize, invokeExceptionListener, invokeListener, isActive, isClientAcknowledge, isExposeListenerSession, isRunning, isSubscriptionDurable, prepareSharedConnection, refreshSharedConnection, rescheduleTaskIfNecessary, rollbackOnExceptionIfNecessary, setAutoStartup, setClientId, setDestination, setDestinationName, setDurableSubscriptionName, setExceptionListener, setExposeListenerSession, setMessageListener, setMessageSelector, setSubscriptionDurable, 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, getConnectionFactory, getSessionAcknowledgeMode, 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 AbstractMessageListenerContainer
See Also:
AbstractMessageListenerContainer.getSharedConnection()

registerListener

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

Specified by:
registerListener in class AbstractMessageListenerContainer
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.

Throws:
JMSException
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.


destroyListener

protected void destroyListener()
                        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:
destroyListener in class AbstractMessageListenerContainer
Throws:
JMSException - if destruction 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
Returns:
the new JMS Session
Throws:
JMSException - if thrown by JMS API methods

The Spring Framework

Copyright © 2002-2006 The Spring Framework.