org.exolab.jms.messagemgr
Class MessageMgr

java.lang.Object
  |
  +--org.exolab.core.service.Service
        |
        +--org.exolab.core.service.BasicService
              |
              +--org.exolab.jms.messagemgr.MessageMgr
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable, org.exolab.core.service.Serviceable

public class MessageMgr
extends org.exolab.core.service.BasicService

This is the active message handling component within the JMS server. Messages are passed in and added to the appropriate dispatchers for delivery to the clients.

Version:
$Revision: 1.93 $ $Date: 2003/08/17 01:32:24 $
Author:
Jim Mourikis, Tim Anderson
See Also:
Serialized Form

Method Summary
 void add(MessageImpl message)
          Add a message to the message manager for the specified destination.
 void addDestination(JmsDestination destination)
          Create the specified destination.
 void addEventListener(JmsDestination destination, MessageManagerEventListener listener)
          Add a message listener for a specific destination to be informed when messages, for the destination are added or removed from the queue.
protected  void addNonPersistentMessage(MessageImpl message)
          This method is used to process non-persistent messages.
protected  void addPersistentMessage(java.sql.Connection connection, MessageImpl message)
          This method is used to process persistent messages published through the resource manager.
protected  void addPersistentMessage(MessageImpl message)
          This method is used to process persistent messages.
static MessageMgr createInstance()
          Create and return an instance of the singleton.
 boolean exists(JmsDestination destination)
          Return true if the specified destination exists.
 java.util.Iterator getConsumers(JmsDestination destination)
          Returns an iterator of active consumers registered to a given destination
 java.util.Iterator getDestinations()
          Returns a list of active destinations
 int getMaximumSize()
          Return the maximum size of the cache
 void handleDestroyed(MessageHandle handle)
          Notify the destruction of a handle.
 boolean hasMessages(ConsumerEndpoint consumer)
          Returns true if there are any messages for the specified consumer
static MessageMgr instance()
          Return an instance to the MessageMgr singleton.
 void removeDestination(JmsDestination destination)
          Remove this destination and all attached consumers.
 void removeEventListener(JmsDestination destination, MessageManagerEventListener listener)
          Remove the listener for the specified destination.
 JmsDestination resolve(java.lang.String name)
          Resolves a destination given its name
 ConsumerEndpoint resolveConsumer(JmsDestination destination, java.lang.String id)
          Resolves a consumer given its destination and an identity.
 void run()
           
 void setStopped(ConsumerEndpoint consumer, boolean stop)
          Stop/start a consumer.
 void start()
           
 void stop()
           
 
Methods inherited from class org.exolab.core.service.BasicService
toString
 
Methods inherited from class org.exolab.core.service.Service
getName, getState, restart, setState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

createInstance

public static MessageMgr createInstance()
                                 throws MessageMgrException
Create and return an instance of the singleton. If the singleton already exists then simply return it. If there is a problem creating the singleton then throw an exception
Returns:
MessageMgr - the singleton instance
Throws:
MessageMgrException -  

instance

public static MessageMgr instance()
Return an instance to the MessageMgr singleton. This method assumes that the singleton has already been created with a call to createInstance()
Returns:
MessageMgr

start

public void start()
           throws org.exolab.core.service.ServiceException
Overrides:
start in class org.exolab.core.service.BasicService

run

public void run()
Overrides:
run in class org.exolab.core.service.BasicService

stop

public void stop()
          throws org.exolab.core.service.ServiceException
Overrides:
stop in class org.exolab.core.service.BasicService

addDestination

public void addDestination(JmsDestination destination)
                    throws javax.jms.JMSException
Create the specified destination. The destination is a container for messages and consumers. Consumers listen for messages posted on a particular destination.

This can be called multiple times without any side effects. If the destination is null then it throws a JMSException

Parameters:
destination - - create this destination
Throws:
javax.jms.JMSException - - if the params is null

removeDestination

public void removeDestination(JmsDestination destination)
                       throws javax.jms.JMSException
Remove this destination and all attached consumers. If the destination is null then throw an exception.
Parameters:
destination - - the destination to remove
Throws:
javax.jms.JMSException -  

exists

public boolean exists(JmsDestination destination)
Return true if the specified destination exists.
Parameters:
destination - - destination to check
Returns:
boolean - true if a it exists

add

public void add(MessageImpl message)
         throws javax.jms.JMSException
Add a message to the message manager for the specified destination. If the message or the destination are null then throw a JMSException

If the destination, specified in the message, does not exist then create it. destinations

Parameters:
message - the message to add
Throws:
javax.jms.JMSException - if the message cannot be added

addNonPersistentMessage

protected void addNonPersistentMessage(MessageImpl message)
                                throws javax.jms.JMSException
This method is used to process non-persistent messages.
Parameters:
message - - the message to process
Throws:
javax.jms.JMSException - - if the message cannot be processed

addPersistentMessage

protected void addPersistentMessage(MessageImpl message)
                             throws javax.jms.JMSException
This method is used to process persistent messages.
Parameters:
message - - the message to process
Throws:
javax.jms.JMSException - - if the message cannot be processed

addPersistentMessage

protected void addPersistentMessage(java.sql.Connection connection,
                                    MessageImpl message)
                             throws javax.jms.JMSException
This method is used to process persistent messages published through the resource manager.
Parameters:
connection - - the database connection to use.
message - - the message to process
Throws:
javax.jms.JMSException - - if the message cannot be processed

hasMessages

public boolean hasMessages(ConsumerEndpoint consumer)
                    throws javax.jms.JMSException
Returns true if there are any messages for the specified consumer
Parameters:
consumer - - the consumer to check
Returns:
boolean - true if messages are queued
Throws:
javax.jms.JMSException - - if the consumer can't be checked

getDestinations

public java.util.Iterator getDestinations()
Returns a list of active destinations
Returns:
List a list of JmsDestination objects

getConsumers

public java.util.Iterator getConsumers(JmsDestination destination)
                                throws javax.jms.JMSException
Returns an iterator of active consumers registered to a given destination
Returns:
Iterator - iterator of ConsumerEndpoint objects.
Throws:
javax.jms.JMSException -  

resolve

public JmsDestination resolve(java.lang.String name)
Resolves a destination given its name
Parameters:
name - the name of the destination
Returns:
JmsDestination if an active destination exists for the given name, else it returns null

resolveConsumer

public ConsumerEndpoint resolveConsumer(JmsDestination destination,
                                        java.lang.String id)
Resolves a consumer given its destination and an identity. Should look removing t from here.
Parameters:
destination - the destination
name - the name of the consumer
Returns:
ConsumerIfc if an active consumer exists for the given name, else it returns null

setStopped

public void setStopped(ConsumerEndpoint consumer,
                       boolean stop)
                throws javax.jms.JMSException
Stop/start a consumer. When stopped, the consumer will not receive messages until the consumer is re-started. This is invoked when the underlying connection is stopped or started
Parameters:
consumer - the consumer to stop/start
stop - when true stop the consumer else start it.

addEventListener

public void addEventListener(JmsDestination destination,
                             MessageManagerEventListener listener)
Add a message listener for a specific destination to be informed when messages, for the destination are added or removed from the queue. More than one listener can be registered per desitnation and the same listener can be registered for multiple destinations.

If a listener is already registered for a particuler destination then it fails silently.

Parameters:
destination - - what messgaes to listen for
listener - - a JmsMessageListener instance

removeEventListener

public void removeEventListener(JmsDestination destination,
                                MessageManagerEventListener listener)
Remove the listener for the specified destination. If one is not registered then ignore it.
Parameters:
destination - - destination that it listens for
listener - - listener for that destination.

getMaximumSize

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

handleDestroyed

public void handleDestroyed(MessageHandle handle)
Notify the destruction of a handle.

If the handle has been destroyed then we need to do the following 1. if the handle is for a queue then we can remove the message from the cache 2. if the handle is for a topic then we need to see whether we can garbage collect it

Parameters:
handle - a TransientMessageHandle


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