org.exolab.jms.messagemgr
Class QueueDestinationCache

java.lang.Object
  |
  +--org.exolab.jms.messagemgr.AbstractDestinationCache
        |
        +--org.exolab.jms.messagemgr.QueueDestinationCache
All Implemented Interfaces:
DestinationCache, GarbageCollectable, LeaseEventListenerIfc, MessageManagerEventListener

public class QueueDestinationCache
extends AbstractDestinationCache

A DestinationCache for queues.

Version:
$Revision: 1.9 $ $Date: 2006/06/09 12:58:56 $
Author:
Jim Alateras, Tim Anderson

Constructor Summary
QueueDestinationCache(JmsQueue queue, DatabaseService database, LeaseManager leases, ServerConnectionManager connections)
          Construct a new QueueDestinationCache.
 
Method Summary
protected  void addMessage(MessageRef reference, MessageImpl message, MessageHandle handle)
          Add a message, and notify any listeners.
 void addQueueListener(QueueBrowserEndpoint listener)
          A Queue can also hav a queue listener, which simply gets informed of all messages that arrive at this destination.
 boolean canDestroy()
          Determines if this cache can be destroyed.
 void destroy()
          Destroy this object.
 MessageHandle getMessage(Selector selector, Condition cancel)
          Returns the first available message matching the supplied message selector.
 int getMessageCount()
          Returns the number of messages in the cache.
 boolean hasConsumers()
          Determines if there are any registered consumers.
protected  void init()
          Initialise the cache.
 void messageAdded(JmsDestination destination, MessageImpl message)
          Invoked when the MessageMgr receives a non-persistent message.
protected  void messageExpired(MessageRef reference)
          Remove an expired non-peristent message, and notify any listeners.
protected  void notifyQueueListeners(MessageHandle handle, MessageImpl message)
          Notify queue browsers that a message has arrived.
 void persistentMessageAdded(JmsDestination destination, MessageImpl message)
          Invoked when the MessageMgr receives a persistent message.
protected  void persistentMessageExpired(MessageRef reference)
          Remove an expired persistent message, and notify any listeners.
 void playbackMessages(QueueBrowserEndpoint browser)
          Playback all the messages in the cache to the specified QueueBrowserEndpoint.
 void removeQueueListener(QueueBrowserEndpoint listener)
          Remove the queue listener associated with this cache
 void returnMessageHandle(MessageHandle handle)
          Return a message handle back to the cache, to recover unsent or unacknowledged messages.
 
Methods inherited from class org.exolab.jms.messagemgr.AbstractDestinationCache
addConsumer, addMessage, checkMessageExpiry, checkMessageExpiry, collectGarbage, getConsumerArray, getConsumerEndpoint, getDestination, getMessageCache, onLeaseExpired, removeConsumer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueueDestinationCache

public QueueDestinationCache(JmsQueue queue,
                             DatabaseService database,
                             LeaseManager leases,
                             ServerConnectionManager connections)
                      throws javax.jms.JMSException
Construct a new QueueDestinationCache.
Parameters:
queue - the queue to cache messages for
database - the database service
leases - the lease manager
connections - the connection manager
Throws:
javax.jms.JMSException - if the cache can't be initialised
Method Detail

addQueueListener

public void addQueueListener(QueueBrowserEndpoint listener)
A Queue can also hav a queue listener, which simply gets informed of all messages that arrive at this destination.
Parameters:
listener - - queue listener

removeQueueListener

public void removeQueueListener(QueueBrowserEndpoint listener)
Remove the queue listener associated with this cache
Parameters:
listener - - queue listener to remove

messageAdded

public void messageAdded(JmsDestination destination,
                         MessageImpl message)
                  throws javax.jms.JMSException
Invoked when the MessageMgr receives a non-persistent message.
Parameters:
destination - the message's destination
message - the message
Throws:
javax.jms.JMSException - if the listener fails to handle the message

persistentMessageAdded

public void persistentMessageAdded(JmsDestination destination,
                                   MessageImpl message)
                            throws javax.jms.JMSException,
                                   PersistenceException
Invoked when the MessageMgr receives a persistent message.
Parameters:
destination - the message's destination
message - the message
Throws:
javax.jms.JMSException - if the listener fails to handle the message
PersistenceException - if there is a persistence related problem

getMessage

public MessageHandle getMessage(Selector selector,
                                Condition cancel)
                         throws javax.jms.JMSException
Returns the first available message matching the supplied message selector.
Parameters:
selector - the message selector to use. May be null
cancel -  
Returns:
handle to the first message, or null if there are no messages, or none matching selector
Throws:
javax.jms.JMSException - for any error

playbackMessages

public void playbackMessages(QueueBrowserEndpoint browser)
                      throws javax.jms.JMSException
Playback all the messages in the cache to the specified QueueBrowserEndpoint.
Parameters:
browser - the queue browser
Throws:
javax.jms.JMSException - for any error

returnMessageHandle

public void returnMessageHandle(MessageHandle handle)
Return a message handle back to the cache, to recover unsent or unacknowledged messages.
Parameters:
handle - the message handle to return

hasConsumers

public boolean hasConsumers()
Determines if there are any registered consumers.
Overrides:
hasConsumers in class AbstractDestinationCache
Returns:
true if there are registered consumers

getMessageCount

public int getMessageCount()
Returns the number of messages in the cache.
Overrides:
getMessageCount in class AbstractDestinationCache
Returns:
the number of messages in the cache

canDestroy

public boolean canDestroy()
Determines if this cache can be destroyed. A QueueDestinationCache can be destroyed if there are no active consumers and:
Overrides:
canDestroy in class AbstractDestinationCache
Returns:
true if the cache can be destroyed, otherwise false

destroy

public void destroy()
Destroy this object.
Overrides:
destroy in class AbstractDestinationCache

init

protected void init()
             throws javax.jms.JMSException
Initialise the cache. This removes all the expired messages, and then retrieves all unacked messages from the database and stores them locally.
Throws:
javax.jms.JMSException - if the cache can't be initialised

addMessage

protected void addMessage(MessageRef reference,
                          MessageImpl message,
                          MessageHandle handle)
                   throws javax.jms.JMSException
Add a message, and notify any listeners.
Parameters:
reference - a reference to the message
message - the message
handle - the handle to add
Throws:
javax.jms.JMSException - for any error

notifyQueueListeners

protected void notifyQueueListeners(MessageHandle handle,
                                    MessageImpl message)
                             throws javax.jms.JMSException
Notify queue browsers that a message has arrived.
Parameters:
handle - a handle to the message
message - the message
Throws:
javax.jms.JMSException - if a browser fails to handle the message

messageExpired

protected void messageExpired(MessageRef reference)
                       throws javax.jms.JMSException
Remove an expired non-peristent message, and notify any listeners.
Overrides:
messageExpired in class AbstractDestinationCache
Parameters:
reference - the reference to the expired message
Throws:
javax.jms.JMSException - for any error

persistentMessageExpired

protected void persistentMessageExpired(MessageRef reference)
                                 throws javax.jms.JMSException,
                                        PersistenceException
Remove an expired persistent message, and notify any listeners.
Overrides:
persistentMessageExpired in class AbstractDestinationCache
Parameters:
reference - the reference to the expired message
Throws:
javax.jms.JMSException - if a listener fails to handle the expiration
PersistenceException - if there is a persistence related problem


Copyright © 1999-2007 The OpenJMS Group. All Rights Reserved.