jrun.jms.core.messagemgr
Class DestinationCache

java.lang.Object
  |
  +--jrun.jms.core.messagemgr.DestinationCache
All Implemented Interfaces:
Identifiable, MessageManagerEventListener, SchedulableEventListener, java.io.Serializable
Direct Known Subclasses:
QueueDestinationCache, TopicDestinationCache

public abstract class DestinationCache
extends java.lang.Object
implements MessageManagerEventListener, Identifiable, SchedulableEventListener

A DestinationCache, as the name implies, is used to cache messages for a particular #Destination object. It is also a #MessageHandleListener that subscribes to the registers with a #DestinationCache to receive messages for a particular {@Destination}.

In all instances this class doesn't deal with {@link #Message} objects directly, but instead uses their corresponding {@link #MessageHandle}, which is far more lightwieght.

A two level cache is used to facilitate quick seeding of registered consumers and quick per-consumer-acknowledgment strategy. The two level cache includes this, the DestinationCache, at the highest level and then {@link #ConsumerCache} at the lowest level.

In addition to registering {@link ConsumerEndpoint} objects the cache also supports {@link MessageHandleListener}s. A listener will be notified when messages are added to the cache but do not actually consume messages. A cache canb have one or more registered listeners. This feature is predominately used by browsers or iterators of destinations.

Clients can also become lifecycle listeners for this object to get notified during initialization and shutdwon.

This cache is ordered on priority.

Version:
$Revision: 1.15 $ $Date: 2001/09/25 05:57:18 $
Author:
Jim Alateras
See Also:
Serialized Form

Field Summary
protected  java.util.List _consumers
          This is the list of consumers that have subscribed to this cache.
protected  MessageLeaseHelper _leaseHelper
          The message lease helper is used to manage leases for messages cached by the destination
protected  MessageQueue _messages
          Transient cache of all messages sent to this destination
protected static PersistentAdapter m_persistentAdapter
           
 
Method Summary
 java.util.Iterator getConsumers()
          Return an enmeration of all consumers attached to this cache.
abstract  JmsDestination getDestination()
          Return a reference to the underlying destination
 java.lang.String getDestinationByName()
          Return the string form of the destination
 long getId()
          Return the identity of the object as a long
 java.lang.String getIdAsString()
          Return the identity of the object as a string
protected  Logger getLogger()
          Return a reference to the logger
 int getMaximumSize()
          Return the cache's maximum size
abstract  int getMessageCount()
          Return the number of messages currently active for this destination
abstract  boolean messageAdded(JmsDestination destination, MessageImpl message)
          This method is called when the #MessageManager adds a message for this destination to the cache
abstract  void messageRemoved(JmsDestination destination, MessageImpl message)
          This method is called when the {@l;ink #MessageManager} removes a message from the cache.
 void onLeaseExpired(java.lang.Object leasedObject)
          This method is called whenever a lease expires.
 void onSchedulableEvent(java.lang.Object context, int type)
          This method is called whenever a schedulableEvent gets fired.
abstract  void persistentMessageRemoved(JmsDestination destination, MessageImpl message)
          This method is called when the {@l;ink #MessageManager} removes a persistent message from the cache.
 boolean registerConsumer(ConsumerEndpoint consumer)
          Register a consumer with this cache.
 void setCacheEvictionPolicy(CacheEvictionPolicy policy)
          Set the #CacheEvictionPolicy for this object.
 void setMaximumSize(int size)
          Set the maximum size of the cache.
 void shutdown()
          Close the cache and unregister all the consumers.
 void unregisterConsumer(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 jrun.jms.core.messagemgr.MessageManagerEventListener
persistentMessageAdded
 

Field Detail

m_persistentAdapter

protected static PersistentAdapter m_persistentAdapter

_messages

protected MessageQueue _messages
Transient cache of all messages sent to this destination

_consumers

protected java.util.List _consumers
This is the list of consumers that have subscribed to this cache. It hosts both durable and transient subscribers

_leaseHelper

protected MessageLeaseHelper _leaseHelper
The message lease helper is used to manage leases for messages cached by the destination
Method Detail

setMaximumSize

public void setMaximumSize(int size)
Set the maximum size of the cache. If there are more than this number of messages in the cache the CacheEvictionPolicy is enforced to remove messages.
Parameters:
size - - maximum number of messages a destination can hold

getMaximumSize

public int getMaximumSize()
Return the cache's maximum size
Returns:
int - size of cache

getDestination

public abstract JmsDestination getDestination()
Return a reference to the underlying destination
Returns:
JmsDestination

getDestinationByName

public java.lang.String getDestinationByName()
Return the string form of the destination
Returns:
String

setCacheEvictionPolicy

public void setCacheEvictionPolicy(CacheEvictionPolicy policy)
Set the #CacheEvictionPolicy for this object. This determines how messages are removed when the cache's upper limit is reached. If no policy is specified then the default #LifoEvictionPolicy is applied.
Parameters:
policy - - cache's eviction policy

registerConsumer

public boolean registerConsumer(ConsumerEndpoint consumer)
Register a consumer with this cache. Part of the registration process will be to seed the #ConsumerEndpoint with an initial list of messages that it needs to consume and then feed messages to it through the specified listener object.

Messages are subsequently passed down to the consumer's through the listener, as they enter the DestinationCache.

Parameters:
consumer - - message consumer for this destination
Returns:
boolean - true if registered and false otherwise

unregisterConsumer

public void unregisterConsumer(ConsumerEndpoint consumer)
Remove the consumer for the list of registered consumers. If the consumer does not exist then the call fails silently.
Parameters:
consumer - - consumer to remove.

getConsumers

public java.util.Iterator getConsumers()
Return an enmeration of all consumers attached to this cache.
Returns:
Iterator - list of registered consumers

messageAdded

public abstract boolean messageAdded(JmsDestination destination,
                                     MessageImpl message)
This method is called when the #MessageManager adds a message for this destination to the cache
Specified by:
messageAdded in interface MessageManagerEventListener
Parameters:
message - - message added to cache

messageRemoved

public abstract void messageRemoved(JmsDestination destination,
                                    MessageImpl message)
This method is called when the {@l;ink #MessageManager} removes a message from the cache.
Specified by:
messageRemoved in interface MessageManagerEventListener
Parameters:
message - - message removed from cache

persistentMessageRemoved

public abstract void persistentMessageRemoved(JmsDestination destination,
                                              MessageImpl message)
                                       throws PersistenceException
This method is called when the {@l;ink #MessageManager} removes a persistent message from the cache.
Specified by:
persistentMessageRemoved in interface MessageManagerEventListener
Parameters:
message - - message removed from cache

getMessageCount

public abstract int getMessageCount()
Return the number of messages currently active for this destination
Returns:
int - number of active messages

onSchedulableEvent

public void onSchedulableEvent(java.lang.Object context,
                               int type)
Description copied from interface: SchedulableEventListener
This method is called whenever a schedulableEvent gets fired. It passes the object associated with event.
Specified by:
onSchedulableEvent in interface SchedulableEventListener

onLeaseExpired

public void onLeaseExpired(java.lang.Object leasedObject)
This method is called whenever a lease expires. It passes the object that has expired.
Parameters:
leasedObject - reference to the leased object

shutdown

public void shutdown()
Close the cache and unregister all the consumers. Notify any and all DestinationCacheLifecycleListeners.

Once the cache is closed it will no longger receive messages for this destination.


getLogger

protected Logger getLogger()
Return a reference to the logger
Returns:
Logger

getId

public long getId()
Description copied from interface: Identifiable
Return the identity of the object as a long
Specified by:
getId in interface Identifiable
Following copied from interface: jrun.jms.core.Identifiable
Returns:
long - the object identity

getIdAsString

public java.lang.String getIdAsString()
Description copied from interface: Identifiable
Return the identity of the object as a string
Specified by:
getIdAsString in interface Identifiable
Following copied from interface: jrun.jms.core.Identifiable
Returns:
String - the identity


Copyright � 2002 Macromedia Corporation. All Rights Reserved.