jrun.jms.core.messagemgr
Class MessageManagerService

jrunx.kernel.ServiceAdapter
  |
  +--jrunx.kernel.ServicePartition
        |
        +--jrun.jms.core.util.JMSServicePartition
              |
              +--jrun.jms.core.messagemgr.MessageManagerService
All Implemented Interfaces:
GarbageCollectable, JMSService, JMSServicePartitionMBean, MessageManager, MessageManagerServiceMBean, QueueWorker, javax.naming.Referenceable, java.io.Serializable, Service, ServiceMBean, ServicePartitionMBean

public class MessageManagerService
extends JMSServicePartition
implements MessageManager, GarbageCollectable, QueueWorker

See Also:
Serialized Form

Field Summary
static java.lang.String OBJECT_NAME
           
 
Fields inherited from class jrunx.kernel.ServicePartition
sortedServices
 
Fields inherited from class jrunx.kernel.ServiceAdapter
DEFAULT_DEACTIVATED, DEFAULT_DOMAIN, DOMAIN_NAME_SEPARATOR, DOMAIN_NAME_SUFFIX, domainName, jndiBindable, LOGGER_CACHE_TIME, SCHEDULER_SERVICE, SECURITY_MANAGER, server, status, TRANSACTION_MANAGER
 
Fields inherited from interface jrunx.kernel.Service
INITIALIZED, STARTED, STARTING, STOPPED, STOPPING, UNINITIALIZED
 
Constructor Summary
MessageManagerService()
           
 
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(MessageImpl message)
          This method is used to process persistent messages.
 void collectGarbage()
          Perform any garbage collection on this resource.
 void execute(java.lang.Object object)
          This is called to complete the processing of incoming messages.
 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 getGarbageCollectionEvent()
          Returns garbage collection event type
 int getMaximumSize()
          Return the maximum size of the cache
 javax.jms.Message getMessage(MessageHandle handle)
          Resolve the message for the specified handle.
 int getOutstanding(JmsDestination destination)
          Returns the number of outstanding messages for this destination.
 boolean hasMessages(ConsumerEndpoint consumer)
          Returns true if there are any messages for the specified consumer
 void init()
           This method may only be invoked once.
static MessageManagerService instance()
           
 void removeDestination(JmsDestination destination)
          Remove this destination and all attached consumers.
 void removeEventListener(JmsDestination destination, MessageManagerEventListener listener)
          Remove the listener for the specified destination.
 javax.jms.Message removeMessage(MessageId id)
          Remove the specified message from the system.
 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()
          Run the MessageMgr.
 void setStopped(ConsumerEndpoint consumer, boolean stop)
          Stop/start a consumer.
 void start()
          Start the MessageMgr.
 void stop()
          Stop the MessageMgr.
 boolean validateDestination(JmsDestination dest)
           
 
Methods inherited from class jrun.jms.core.util.JMSServicePartition
restart, resume, suspend
 
Methods inherited from class jrunx.kernel.ServicePartition
addService, addService, getServices, invokeChain, iterator, removeService, removeService
 
Methods inherited from class jrunx.kernel.ServiceAdapter
bind, destroy, findObjectInstance, findObjectInstance, findObjectInstance, getBindToJNDI, getDeactivated, getDomainName, getDomainSearchPath, getJRunService, getLogger, getName, getParentService, getReference, getResourceManager, getServerName, getServerProperties, getStatus, invokeMethod, isInPartition, isPartition, lookup, postDeregister, postRegister, preDeregister, preRegister, requestServer, scheduleRunnable, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, toString, unbind, unscheduleRunnable, updateStatus
 
Methods inherited from interface jrunx.kernel.ServicePartitionMBean
addService, addService, iterator, removeService, removeService
 
Methods inherited from interface jrunx.kernel.ServiceMBean
bind, getBindToJNDI, getDeactivated, getDomainName, getJRunService, getLogger, getName, getParentService, getServerName, requestServer, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, unbind
 
Methods inherited from interface jrunx.kernel.Service
destroy, getStatus, updateStatus
 

Field Detail

OBJECT_NAME

public static final java.lang.String OBJECT_NAME
Constructor Detail

MessageManagerService

public MessageManagerService()
Method Detail

instance

public static MessageManagerService instance()

init

public void init()
          throws java.lang.Exception

This method may only be invoked once. Subsequent calls will throw a JMSException, unless the MessageMgr is stopped via stop().

Specified by:
init in interface Service
Overrides:
init in class ServiceAdapter
Returns:
MessageMgr the singleton instance
Throws:
JMSException - if initialisation fails or the instance is already initialised

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 desitnation.

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

Specified by:
addDestination in interface MessageManager
Parameters:
destination - - create this destination
Throws:
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.
Specified by:
removeDestination in interface MessageManager
Parameters:
destination - - the destination to remove
Throws:
JMSException -  

exists

public boolean exists(JmsDestination destination)
Return true if the specified destination exists.
Specified by:
exists in interface MessageManager
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, dos not exist then create it. destinations

Specified by:
add in interface MessageManager
Parameters:
message - the message to add
Throws:
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:
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:
JMSException - - if the message cannot be processed

execute

public void execute(java.lang.Object object)
This is called to complete the processing of incoming messages. During this phase the messages filter through the system. When each message is processed the processed flag is set to for the message.
Specified by:
execute in interface QueueWorker
Parameters:
object - - the message to process

getOutstanding

public int getOutstanding(JmsDestination destination)
                   throws javax.jms.JMSException
Returns the number of outstanding messages for this destination. This is only relevant to JMSQueue destination objects. If a client supplied a <@link JMSTopic} destination then a JMSException exception will be raised.
Specified by:
getOutstanding in interface MessageManager
Parameters:
destination - - the destination to query
Returns:
int - the number of outstanding messages
Throws:
JMSException - - if destination is null or of type JMSQueue

hasMessages

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

validateDestination

public boolean validateDestination(JmsDestination dest)

getDestinations

public java.util.Iterator getDestinations()
Returns a list of active destinations
Specified by:
getDestinations in interface MessageManager
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
Specified by:
getConsumers in interface MessageManager
Returns:
Iterator - iterator of Consumer objects.
Throws:
JMSException -  

resolve

public JmsDestination resolve(java.lang.String name)
Resolves a destination given its name
Specified by:
resolve in interface MessageManager
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.
Specified by:
resolveConsumer in interface MessageManager
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

run

public void run()
Run the MessageMgr. This starts the scheduler for dispatching messages to registered consumers.

start

public void start()
           throws java.lang.Exception
Start the MessageMgr.

This invokes run

Specified by:
start in interface Service
Overrides:
start in class ServiceAdapter
Throws:
JMSException - if stop fails

stop

public void stop()
          throws java.lang.Exception
Stop the MessageMgr.

This stops the scheduler, stops and removes all dispatchers, and clears the singleton instance.

Specified by:
stop in interface Service
Overrides:
stop in class ServiceAdapter
Throws:
JMSException - if stop fails

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.

getMessage

public javax.jms.Message getMessage(MessageHandle handle)
Resolve the message for the specified handle. If the handle is a PersistentMessageHandle then we need to also attempt to resolve it from the persistent store.
Specified by:
getMessage in interface MessageManager
Parameters:
id - - message identity
Returns:
Message - messaage corresponding to id or null

removeMessage

public javax.jms.Message removeMessage(MessageId id)
Remove the specified message from the system. This will remove the message from the cache and inform any message listeners of the event
Specified by:
removeMessage in interface MessageManager
Parameters:
id - - identity of the message
Returns:
Message - removed message

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.

Specified by:
addEventListener in interface MessageManager
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.
Specified by:
removeEventListener in interface MessageManager
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

getGarbageCollectionEvent

public int getGarbageCollectionEvent()
Description copied from interface: GarbageCollectable
Returns garbage collection event type
Specified by:
getGarbageCollectionEvent in interface GarbageCollectable

collectGarbage

public void collectGarbage()
Description copied from interface: GarbageCollectable
Perform any garbage collection on this resource. This will have the effect of releasing system resources.
Specified by:
collectGarbage in interface GarbageCollectable


Copyright � 2002 Macromedia Corporation. All Rights Reserved.