Save This Page
Home » spring-framework-2.5.6-with-dependencies » org.springframework » jms » listener » [javadoc | source]
org.springframework.jms.listener
abstract public class: AbstractPollingMessageListenerContainer [javadoc | source]
java.lang.Object
   org.springframework.jms.support.JmsAccessor
      org.springframework.jms.support.destination.JmsDestinationAccessor
         org.springframework.jms.listener.AbstractJmsListeningContainer
            org.springframework.jms.listener.AbstractMessageListenerContainer
               org.springframework.jms.listener.AbstractPollingMessageListenerContainer

All Implemented Interfaces:
    BeanNameAware, DisposableBean, Lifecycle, InitializingBean

Direct Known Subclasses:
    DefaultMessageListenerContainer, DefaultMessageListenerContainer102

Base class for listener container implementations which are based on polling. Provides support for listener handling based on javax.jms.MessageConsumer , optionally participating in externally managed transactions.

This listener container variant is built for repeated polling attempts, each invoking the #receiveAndExecute method. The MessageConsumer used may be reobtained fo reach attempt or cached inbetween attempts; this is up to the concrete implementation. The receive timeout for each attempt can be configured through the "receiveTimeout" property.

The underlying mechanism is based on standard JMS MessageConsumer handling, which is perfectly compatible with both native JMS and JMS in a J2EE environment. Neither the JMS MessageConsumer.setMessageListener facility nor the JMS ServerSessionPool facility is required. A further advantage of this approach is full control over the listening process, allowing for custom scaling and throttling and of concurrent message processing (which is up to concrete subclasses).

Message reception and listener execution can automatically be wrapped in transactions through passing a Spring org.springframework.transaction.PlatformTransactionManager into the "transactionManager" property. This will usually be a org.springframework.transaction.jta.JtaTransactionManager in a J2EE enviroment, in combination with a JTA-aware JMS ConnectionFactory obtained from JNDI (check your J2EE server's documentation).

This base class does not assume any specific mechanism for asynchronous execution of polling invokers. Check out DefaultMessageListenerContainer for a concrete implementation which is based on Spring's org.springframework.core.task.TaskExecutor abstraction, including dynamic scaling of concurrent consumers and automatic self recovery.

Field Summary
public static final  long DEFAULT_RECEIVE_TIMEOUT    The default receive timeout: 1000 ms = 1 second. 
Fields inherited from org.springframework.jms.listener.AbstractJmsListeningContainer:
sharedConnectionMonitor,  lifecycleMonitor
Fields inherited from org.springframework.jms.support.JmsAccessor:
logger
Method from org.springframework.jms.listener.AbstractPollingMessageListenerContainer Summary:
createConsumer,   createListenerConsumer,   doReceiveAndExecute,   getConnection,   getSession,   getTransactionManager,   initialize,   isPubSubNoLocal,   isSessionLocallyTransacted,   messageReceived,   noMessageReceived,   receiveAndExecute,   receiveMessage,   setPubSubNoLocal,   setReceiveTimeout,   setSessionTransacted,   setTransactionManager,   setTransactionName,   setTransactionTimeout
Methods from org.springframework.jms.listener.AbstractMessageListenerContainer:
checkMessageListener,   commitIfNecessary,   doExecuteListener,   doInvokeListener,   doInvokeListener,   executeListener,   getDefaultSubscriptionName,   getDestination,   getDestinationDescription,   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 from org.springframework.jms.listener.AbstractJmsListeningContainer:
afterPropertiesSet,   createSharedConnection,   destroy,   doInitialize,   doRescheduleTask,   doShutdown,   doStart,   doStop,   establishSharedConnection,   getBeanName,   getClientId,   getPausedTaskCount,   getSharedConnection,   initialize,   isActive,   isRunning,   logRejectedTask,   prepareSharedConnection,   refreshSharedConnection,   rescheduleTaskIfNecessary,   resumePausedTasks,   runningAllowed,   setAutoStartup,   setBeanName,   setClientId,   sharedConnectionEnabled,   shutdown,   start,   startSharedConnection,   stop,   stopSharedConnection,   validateConfiguration
Methods from org.springframework.jms.support.destination.JmsDestinationAccessor:
getDestinationResolver,   isPubSubDomain,   resolveDestinationName,   setDestinationResolver,   setPubSubDomain
Methods from org.springframework.jms.support.JmsAccessor:
afterPropertiesSet,   convertJmsAccessException,   createConnection,   createSession,   getConnectionFactory,   getSessionAcknowledgeMode,   isClientAcknowledge,   isSessionTransacted,   setConnectionFactory,   setSessionAcknowledgeMode,   setSessionAcknowledgeModeName,   setSessionTransacted
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.jms.listener.AbstractPollingMessageListenerContainer Detail:
 protected MessageConsumer createConsumer(Session session,
    Destination destination) throws JMSException 
    Create a JMS MessageConsumer for the given Session and Destination.

    This implementation uses JMS 1.1 API.

 protected MessageConsumer createListenerConsumer(Session session) throws JMSException 
    Create a MessageConsumer for the given JMS Session, registering a MessageListener for the specified listener.
 protected boolean doReceiveAndExecute(Object invoker,
    Session session,
    MessageConsumer consumer,
    TransactionStatus status) throws JMSException 
    Actually execute the listener for a message received from the given consumer, fetching all requires resources and invoking the listener.
 protected Connection getConnection(JmsResourceHolder holder) 
    Fetch an appropriate Connection from the given JmsResourceHolder.

    This implementation accepts any JMS 1.1 Connection.

 protected Session getSession(JmsResourceHolder holder) 
    Fetch an appropriate Session from the given JmsResourceHolder.

    This implementation accepts any JMS 1.1 Session.

 protected final PlatformTransactionManager getTransactionManager() 
    Return the Spring PlatformTransactionManager to use for transactional wrapping of message reception plus listener execution.
 public  void initialize() 
 protected boolean isPubSubNoLocal() 
    Return whether to inhibit the delivery of messages published by its own connection.
 protected boolean isSessionLocallyTransacted(Session session) 
    This implementation checks whether the Session is externally synchronized. In this case, the Session is not locally transacted, despite the listener container's "sessionTransacted" flag being set to "true".
 protected  void messageReceived(Object invoker,
    Session session) 
    Template method that gets called right when a new message has been received, before attempting to process it. Allows subclasses to react to the event of an actual incoming message, for example adapting their consumer count.
 protected  void noMessageReceived(Object invoker,
    Session session) 
    Template method that gets called right no message has been received, before attempting to process it. Allows subclasses to react to the event of an actual incoming message, for example marking .
 protected boolean receiveAndExecute(Object invoker,
    Session session,
    MessageConsumer consumer) throws JMSException 
    Execute the listener for a message received from the given consumer, wrapping the entire operation in an external transaction if demanded.
 protected Message receiveMessage(MessageConsumer consumer) throws JMSException 
    Receive a message from the given consumer.
 public  void setPubSubNoLocal(boolean pubSubNoLocal) 
    Set whether to inhibit the delivery of messages published by its own connection. Default is "false".
 public  void setReceiveTimeout(long receiveTimeout) 
    Set the timeout to use for receive calls, in milliseconds. The default is 1000 ms, that is, 1 second.

    NOTE: This value needs to be smaller than the transaction timeout used by the transaction manager (in the appropriate unit, of course). -1 indicates no timeout at all; however, this is only feasible if not running within a transaction manager.

 public  void setSessionTransacted(boolean sessionTransacted) 
 public  void setTransactionManager(PlatformTransactionManager transactionManager) 
 public  void setTransactionName(String transactionName) 
    Specify the transaction name to use for transactional wrapping. Default is the bean name of this listener container, if any.
 public  void setTransactionTimeout(int transactionTimeout) 
    Specify the transaction timeout to use for transactional wrapping, in seconds. Default is none, using the transaction manager's default timeout.