jrun.jms.core.messagemgr
Class TopicConsumerEndpoint

java.lang.Object
  |
  +--jrun.jms.core.messagemgr.ConsumerEndpoint
        |
        +--jrun.jms.core.messagemgr.TopicConsumerEndpoint
All Implemented Interfaces:
DestinationCacheEventListener, DestinationEventListener, Identifiable, java.lang.Runnable, java.io.Serializable
Direct Known Subclasses:
DurableConsumerEndpoint

public class TopicConsumerEndpoint
extends ConsumerEndpoint
implements DestinationEventListener

The topic destination cache is specific to a consumer that subscribes to a Topic destination. It extends ConsumerEndpoint and includes behaviour specific

Version:
$Revision: 1.21 $ $Date: 2001/09/24 22:39:30 $
Author:
Jim Alateras
See Also:
Serialized Form

Field Summary
protected  java.util.HashMap _caches
          Maintains a list of TopicDestinationCache that this endpoint subscribes too.
protected  JmsTopic _topic
          Cache the destination that this endpoint subscribes too
 
Fields inherited from class jrun.jms.core.messagemgr.ConsumerEndpoint
_ackMode, _connectionId, _destroyed, _listener, _messages, _nolocal, _scheduled, _scheduler, _selector, _session, _size, _stopped, _transacted
 
Method Summary
 boolean canGarbageCollect(MessageHandle handle)
          Check if this message is referenced by this endpoint.
protected  void clearMessages()
          Clear all messages in the cache, regardless of whether they are persistent or non-persistent
 void destinationAdded(JmsDestination destination, DestinationCache cache)
          This method is called when a new destination is added to the DestinationManager
 void destinationRemoved(JmsDestination destination, DestinationCache cache)
          This method is called when a new destination is removed from the DestinationManager
 void destroy()
          Destroy this object
 JmsDestination getDestination()
          Return the destination that this consumer is subscribed too
 int getUnprocessedMessageCount()
          Return the number of unsent and unacked messages for this consumer
 boolean messageRemoved(MessageImpl message)
          This event is called when a message is removed from the DestinationCache.
 boolean persistentMessageRemoved(MessageImpl message)
          This event is called when a message is removed from the DestinationCache.
 MessageHandle receiveMessage()
          Return the next message to the client.
 void recover()
          This message will return all unacked messages to the queue and allow them to be resent to the consumer with the redelivery flag on.
 void returnMessage(MessageHandle handle, boolean recover)
          Return the specified message to the cache.
 void run()
          The run method is used to asynchronously deliver the messages in the cache to the consumer.
 void setLastMessageProcessed(long id)
           
 void setMessageListener(InternalMessageListener listener)
          Set the message listener for this consmer.
 void stopMessageDelivery()
          Stop delivering messages to the registered listener
 void unregister()
          Unregister this consumer for the specified destination cache, so that it will stop receiving messages from it.
 
Methods inherited from class jrun.jms.core.messagemgr.ConsumerEndpoint
getAckMode, getClientId, getConnectionId, getId, getIdAsString, getLogger, getMaximumSize, getMessageCount, getNoLocal, getSelector, getSession, getTransacted, getUnsentMessages, hashCode, messageAdded, persistentMessageAdded, schedule, setAckMode, setCacheEvictionPolicy, setClientId, setConnectionId, setMaximumSize, setNoLocal, setSelector, setStopped, setTransacted, shutdown, startMessageDelivery, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_caches

protected java.util.HashMap _caches
Maintains a list of TopicDestinationCache that this endpoint subscribes too. A wildcard subscription may point to more than one.

_topic

protected JmsTopic _topic
Cache the destination that this endpoint subscribes too
Method Detail

run

public void run()
The run method is used to asynchronously deliver the messages in the cache to the consumer. It is scheduler by the Scheduler.

The thread, assigned by the scheduler, will attempt to deliver all the messages in the cache and then terminate. In addition this method must be prepared to be interrupted.


receiveMessage

public MessageHandle receiveMessage()
Description copied from class: ConsumerEndpoint
Return the next message to the client. This will also mark the message as sent and move it to the sent queue
Overrides:
receiveMessage in class ConsumerEndpoint
Following copied from class: jrun.jms.core.messagemgr.ConsumerEndpoint
Returns:
MessageHandle - handle to the next message in the list

messageRemoved

public boolean messageRemoved(MessageImpl message)
Description copied from interface: DestinationCacheEventListener
This event is called when a message is removed from the DestinationCache.
Overrides:
messageRemoved in class ConsumerEndpoint
Following copied from interface: jrun.jms.core.messagemgr.DestinationCacheEventListener
Parameters:
message - - message removed from cache

persistentMessageRemoved

public boolean persistentMessageRemoved(MessageImpl message)
                                 throws PersistenceException
Description copied from interface: DestinationCacheEventListener
This event is called when a message is removed from the DestinationCache.
Overrides:
persistentMessageRemoved in class ConsumerEndpoint
Following copied from interface: jrun.jms.core.messagemgr.DestinationCacheEventListener
Parameters:
connection - - the database connection
message - - message to remove from cache
Throws:
PersistenceException - - if there is a persistence related problem

canGarbageCollect

public boolean canGarbageCollect(MessageHandle handle)
Check if this message is referenced by this endpoint. If it is then the message cannot be garbage collected.
Overrides:
canGarbageCollect in class ConsumerEndpoint
Parameters:
handle - - message to check
Returns:
boolean - true if we can garbage collect

getDestination

public JmsDestination getDestination()
Description copied from class: ConsumerEndpoint
Return the destination that this consumer is subscribed too
Overrides:
getDestination in class ConsumerEndpoint
Following copied from class: jrun.jms.core.messagemgr.ConsumerEndpoint
Returns:
JmsDestination

unregister

public void unregister()
Description copied from class: ConsumerEndpoint
Unregister this consumer for the specified destination cache, so that it will stop receiving messages from it.
Overrides:
unregister in class ConsumerEndpoint

recover

public void recover()
Description copied from class: ConsumerEndpoint
This message will return all unacked messages to the queue and allow them to be resent to the consumer with the redelivery flag on.
Overrides:
recover in class ConsumerEndpoint

returnMessage

public void returnMessage(MessageHandle handle,
                          boolean recover)
Return the specified message to the cache.
Parameters:
handle - - handle to return
recover - - flag to reschedule endpoint

destroy

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

getUnprocessedMessageCount

public int getUnprocessedMessageCount()
Description copied from class: ConsumerEndpoint
Return the number of unsent and unacked messages for this consumer
Overrides:
getUnprocessedMessageCount in class ConsumerEndpoint
Following copied from class: jrun.jms.core.messagemgr.ConsumerEndpoint
Returns:
int - number of unacked or unsent messages

stopMessageDelivery

public void stopMessageDelivery()
Description copied from class: ConsumerEndpoint
Stop delivering messages to the registered listener
Overrides:
stopMessageDelivery in class ConsumerEndpoint

destinationAdded

public void destinationAdded(JmsDestination destination,
                             DestinationCache cache)
Description copied from interface: DestinationEventListener
This method is called when a new destination is added to the DestinationManager
Specified by:
destinationAdded in interface DestinationEventListener
Following copied from interface: jrun.jms.core.messagemgr.DestinationEventListener
Parameters:
destination - - destination that was added
cache - - the corresponding cache

destinationRemoved

public void destinationRemoved(JmsDestination destination,
                               DestinationCache cache)
Description copied from interface: DestinationEventListener
This method is called when a new destination is removed from the DestinationManager
Specified by:
destinationRemoved in interface DestinationEventListener
Following copied from interface: jrun.jms.core.messagemgr.DestinationEventListener
Parameters:
destination - - destination that was removed
cache - - the corresponding cache

setMessageListener

public void setMessageListener(InternalMessageListener listener)
Description copied from class: ConsumerEndpoint
Set the message listener for this consmer. If a message listener is set then messages will be scheduled to be sent to it when they are available

Each consumer cache can only have a single message listener. To remove the message listener call this method with null argument

Overrides:
setMessageListener in class ConsumerEndpoint
Following copied from class: jrun.jms.core.messagemgr.ConsumerEndpoint
Parameters:
listener - - the message listener to add.

setLastMessageProcessed

public void setLastMessageProcessed(long id)

clearMessages

protected void clearMessages()
Clear all messages in the cache, regardless of whether they are persistent or non-persistent
Overrides:
clearMessages in class ConsumerEndpoint


Copyright � 2002 Macromedia Corporation. All Rights Reserved.