org.exolab.jms.messagemgr
Class DestinationManagerImpl

java.lang.Object
  |
  +--org.exolab.jms.service.Service
        |
        +--org.exolab.jms.messagemgr.DestinationManagerImpl
All Implemented Interfaces:
DestinationManager, GarbageCollectable, MessageManagerEventListener, Serviceable

public class DestinationManagerImpl
extends Service
implements DestinationManager

The destination manager is responsible for creating and managing the lifecycle of DestinationCache objects. The destination manager is also responsible for managing messages, that are received by the message manager, which do not have any registered DestinationCache.

Version:
$Revision: 1.2 $ $Date: 2005/11/12 10:49:48 $
Author:
Jim Alateras, Tim Anderson

Constructor Summary
DestinationManagerImpl(MessageManager messages, DestinationCacheFactory factory, DatabaseService database, GarbageCollectionService collector)
          Construct a new DestinationManagerImpl.
 
Method Summary
 void addDestinationEventListener(DestinationEventListener listener)
          Register an event listener to be notified when destinations are created and destroyed.
 void collectGarbage(boolean aggressive)
          Perform any garbage collection on this resource.
 void createDestination(JmsDestination destination)
          Create a destination.
protected  void destroyDestinationCache(DestinationCache cache)
          Delete the specfied destination.
protected  void destroyDestinationCache(JmsDestination dest)
          Delete the specfied destination.
protected  void doStart()
          Start the service.
protected  void doStop()
          Stop the service.
protected  boolean exists(java.lang.String name)
          Determines if a destination exists.
 JmsDestination getDestination(java.lang.String name)
          Returns a destination given its name.
 DestinationCache getDestinationCache(JmsDestination destination)
          Returns the cache for the supplied destination.
 java.util.List getDestinations()
          Returns all destinations.
 java.util.Map getTopicDestinationCaches(JmsTopic topic)
          Returns a map of all destinations that match the specified topic.
protected  void init()
          Initialises the destination manager.
 void messageAdded(JmsDestination destination, MessageImpl message)
          Invoked when the MessageManager receives a non-persistent message.
 void persistentMessageAdded(JmsDestination destination, MessageImpl message)
          Invoked when the MessageManager receives a persistent message.
 void removeDestination(JmsDestination destination)
          Remove a destination.
 void removeDestinationEventListener(DestinationEventListener listener)
          Remove an event listener.
 void setConsumerManager(ConsumerManager consumers)
          Sets the consumer manager.
 
Methods inherited from class org.exolab.jms.service.Service
getName, isStarted, restart, start, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DestinationManagerImpl

public DestinationManagerImpl(MessageManager messages,
                              DestinationCacheFactory factory,
                              DatabaseService database,
                              GarbageCollectionService collector)
Construct a new DestinationManagerImpl.
Parameters:
messages - the message manager
factory - the destination cache factory
database - the database service
collector - the garbage collection service
Method Detail

setConsumerManager

public void setConsumerManager(ConsumerManager consumers)
Sets the consumer manager.
Parameters:
consumers - the consumer manager

getDestinationCache

public DestinationCache getDestinationCache(JmsDestination destination)
                                     throws javax.jms.JMSException
Returns the cache for the supplied destination.

If the cache doesn't exist, it will be created, and any registered DestinationEventListeners will be notified.

Specified by:
getDestinationCache in interface DestinationManager
Parameters:
destination - the destination of the cache to return
Returns:
the cache associated with destination
Throws:
javax.jms.InvalidDestinationException - if destination doesn't exist
javax.jms.JMSException - if the cache can't be created

getDestination

public JmsDestination getDestination(java.lang.String name)
Returns a destination given its name.
Specified by:
getDestination in interface DestinationManager
Parameters:
name - the name of the destination
Returns:
the destination corresponding to name or null if none exists

addDestinationEventListener

public void addDestinationEventListener(DestinationEventListener listener)
Register an event listener to be notified when destinations are created and destroyed.
Specified by:
addDestinationEventListener in interface DestinationManager
Parameters:
listener - the listener to add

removeDestinationEventListener

public void removeDestinationEventListener(DestinationEventListener listener)
Remove an event listener.
Specified by:
removeDestinationEventListener in interface DestinationManager
Parameters:
listener - the listener to remove

createDestination

public void createDestination(JmsDestination destination)
                       throws javax.jms.JMSException
Create a destination.

Any registered DestinationEventListeners will be notified.

Specified by:
createDestination in interface DestinationManager
Parameters:
destination - the destination to create
Throws:
javax.jms.InvalidDestinationException - if the destination already exists or is a wildcard destination
javax.jms.JMSException - if the destination can't be created

removeDestination

public void removeDestination(JmsDestination destination)
                       throws javax.jms.JMSException
Remove a destination.

All messages and durable consumers will be removed. Any registered DestinationEventListeners will be notified.

Specified by:
removeDestination in interface DestinationManager
Parameters:
destination - the destination to remove
Throws:
javax.jms.InvalidDestinationException - if the destination is invalid
javax.jms.JMSException - if the destination can't be removed

messageAdded

public void messageAdded(JmsDestination destination,
                         MessageImpl message)
                  throws javax.jms.JMSException
Invoked when the MessageManager receives a non-persistent message.
Specified by:
messageAdded in interface MessageManagerEventListener
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 MessageManager receives a persistent message.
Specified by:
persistentMessageAdded in interface MessageManagerEventListener
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

getDestinations

public java.util.List getDestinations()
                               throws javax.jms.JMSException
Returns all destinations.
Specified by:
getDestinations in interface DestinationManager
Returns:
a list of JmsDestination instances.
Throws:
javax.jms.JMSException - for any JMS error

getTopicDestinationCaches

public java.util.Map getTopicDestinationCaches(JmsTopic topic)
Returns a map of all destinations that match the specified topic.

If the topic represents a wildcard then it may match none, one or more destinations.

Specified by:
getTopicDestinationCaches in interface DestinationManager
Parameters:
topic - the topic
Returns:
a map of topics to DestinationCache instances

collectGarbage

public void collectGarbage(boolean aggressive)
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
Parameters:
aggressive - true for aggressive garbage collection

doStart

protected void doStart()
                throws ServiceException
Start the service.
Overrides:
doStart in class Service
Throws:
ServiceException - if the service fails to start

doStop

protected void doStop()
               throws ServiceException
Stop the service.
Overrides:
doStop in class Service
Throws:
ServiceException - if the service fails to stop

init

protected void init()
             throws ServiceException
Initialises the destination manager.
Throws:
ServiceException - if the service cannot be initialised

exists

protected boolean exists(java.lang.String name)
Determines if a destination exists.
Parameters:
name - the destination name
Returns:
true if the destination exists, otherwise false

destroyDestinationCache

protected void destroyDestinationCache(DestinationCache cache)
Delete the specfied destination.
Parameters:
cache - the destination to destroy

destroyDestinationCache

protected void destroyDestinationCache(JmsDestination dest)
Delete the specfied destination.
Parameters:
dest - the destination to destroy


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