org.exolab.jms.messagemgr
Class AbstractDestinationCache

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

public abstract class AbstractDestinationCache
extends java.lang.Object
implements DestinationCache, LeaseEventListenerIfc

Abstract implementation of the DestinationCache interface.

Version:
$Revision: 1.4 $ $Date: 2007/01/24 12:00:28 $
Author:
Tim Anderson

Constructor Summary
AbstractDestinationCache(JmsDestination destination, DatabaseService database, LeaseManager leases)
          Construct a new AbstractDestinationCache.
 
Method Summary
 boolean addConsumer(ConsumerEndpoint consumer)
          Register a consumer with this cache.
protected  void addMessage(MessageRef reference, MessageImpl message)
          Add a message reference and its corresponding message to the cache
 boolean canDestroy()
          Determines if this cache can be destroyed.
protected  void checkMessageExpiry(MessageRef reference, long expiryTime)
          Check to see if the message has a TTL.
protected  void checkMessageExpiry(MessageRef reference, MessageImpl message)
          Check to see if the message has a TTL.
 void collectGarbage(boolean aggressive)
          Perform any garbage collection on this resource.
 void destroy()
          Destroy this cache.
protected  ConsumerEndpoint[] getConsumerArray()
          Helper to return the consumers as an array.
protected  ConsumerEndpoint getConsumerEndpoint(long consumerId)
          Returns a consumer endpoint, given its id.
 JmsDestination getDestination()
          Returns the destination that messages are being cached for.
protected  org.exolab.jms.messagemgr.DefaultMessageCache getMessageCache()
          Returns the message cache.
 int getMessageCount()
          Returns the number of messages in the cache.
 boolean hasConsumers()
          Determines if the cache has any consumers.
protected  void messageExpired(MessageRef reference)
          Remove an expired non-peristent message, and notify any listeners.
 void onLeaseExpired(java.lang.Object object)
          Invoked when a message lease has expired.
protected  void persistentMessageExpired(MessageRef reference)
          Remove an expired persistent message, and notify any listeners.
 void removeConsumer(ConsumerEndpoint consumer)
          Remove the consumer for the list of registered consumers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.exolab.jms.messagemgr.DestinationCache
returnMessageHandle
 
Methods inherited from interface org.exolab.jms.messagemgr.MessageManagerEventListener
messageAdded, persistentMessageAdded
 

Constructor Detail

AbstractDestinationCache

public AbstractDestinationCache(JmsDestination destination,
                                DatabaseService database,
                                LeaseManager leases)
Construct a new AbstractDestinationCache.
Parameters:
destination - the destination to cache messages for
database - the database service
leases - the lease manager
Method Detail

getDestination

public JmsDestination getDestination()
Returns the destination that messages are being cached for.
Specified by:
getDestination in interface DestinationCache
Returns:
the destination that messages are being cached for

addConsumer

public boolean addConsumer(ConsumerEndpoint consumer)
Register a consumer with this cache.
Specified by:
addConsumer in interface DestinationCache
Parameters:
consumer - the message consumer for this destination
Returns:
true if registered; otherwise false

removeConsumer

public void removeConsumer(ConsumerEndpoint consumer)
Remove the consumer for the list of registered consumers.
Specified by:
removeConsumer in interface DestinationCache
Parameters:
consumer - the consumer to remove

hasConsumers

public boolean hasConsumers()
Determines if the cache has any consumers.
Specified by:
hasConsumers in interface DestinationCache
Returns:
true if the cache has consumers; otherwise false

getMessageCount

public int getMessageCount()
Returns the number of messages in the cache.
Specified by:
getMessageCount in interface DestinationCache
Returns:
the number of messages in the cache

canDestroy

public boolean canDestroy()
Determines if this cache can be destroyed. This implementation returns true if there are no active consumers.
Specified by:
canDestroy in interface DestinationCache
Returns:
true if the cache can be destroyed, otherwise false

destroy

public void destroy()
Destroy this cache.
Specified by:
destroy in interface DestinationCache

onLeaseExpired

public void onLeaseExpired(java.lang.Object object)
Invoked when a message lease has expired.
Specified by:
onLeaseExpired in interface LeaseEventListenerIfc
Parameters:
object - an instance of MessageRef

collectGarbage

public void collectGarbage(boolean aggressive)
Description copied from interface: GarbageCollectable
Perform any garbage collection on this resource. This will have the effect of releasing system resources. If the 'aggressive' flag is set to true then the garbage collection should do more to release memory related resources since it is called when the application memory is low.
Specified by:
collectGarbage in interface GarbageCollectable
Following copied from interface: org.exolab.jms.gc.GarbageCollectable
Parameters:
aggressive - true for aggressive garbage collection

addMessage

protected void addMessage(MessageRef reference,
                          MessageImpl message)
Add a message reference and its corresponding message to the cache
Parameters:
reference - the reference to the message
message - the message

getMessageCache

protected org.exolab.jms.messagemgr.DefaultMessageCache getMessageCache()
Returns the message cache.
Returns:
the message cache

getConsumerEndpoint

protected ConsumerEndpoint getConsumerEndpoint(long consumerId)
Returns a consumer endpoint, given its id.
Parameters:
consumerId - the consumer identity
Returns:
the consumer corresponding to id, or null if none is registered

getConsumerArray

protected ConsumerEndpoint[] getConsumerArray()
Helper to return the consumers as an array.
Returns:
the consumers of this cache

messageExpired

protected void messageExpired(MessageRef reference)
                       throws javax.jms.JMSException
Remove an expired non-peristent message, and notify any listeners.
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.
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

checkMessageExpiry

protected void checkMessageExpiry(MessageRef reference,
                                  MessageImpl message)
                           throws javax.jms.JMSException
Check to see if the message has a TTL. If so then set up a lease for it. An expiry time of 0 means that the message never expires
Parameters:
reference - a reference to the message
message - the message
Throws:
javax.jms.JMSException - if the JMSExpiration property can't be accessed

checkMessageExpiry

protected void checkMessageExpiry(MessageRef reference,
                                  long expiryTime)
Check to see if the message has a TTL. If so then set up a lease for it. An expiry time of 0 means that the message never expires
Parameters:
reference - a reference to the message
expiryTime - the time when the message expires


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