org.exolab.jms.messagemgr
Class ConsumerManagerImpl

java.lang.Object
  |
  +--org.exolab.jms.service.Service
        |
        +--org.exolab.jms.messagemgr.ConsumerManagerImpl
All Implemented Interfaces:
ConsumerManager, Serviceable

public class ConsumerManagerImpl
extends Service
implements ConsumerManager

The consumer manager is responsible for creating and managing the lifecycle of consumers. The consumer manager maintains a list of all active consumers.

Version:
$Revision: 1.3 $ $Date: 2005/12/23 12:17:25 $
Author:
Jim Alateras, Tim Anderson

Constructor Summary
ConsumerManagerImpl(DestinationManager destinations, DatabaseService database)
          Construct a new ConsumerManager.
 
Method Summary
 void closeConsumer(ConsumerEndpoint consumer)
          Close a consumer.
 ConsumerEndpoint createConsumer(JmsDestination destination, long connectionId, java.lang.String selector, boolean noLocal)
          Create a transient consumer for the specified destination.
 DurableConsumerEndpoint createDurableConsumer(JmsTopic topic, java.lang.String name, java.lang.String clientID, long connectionId, boolean noLocal, java.lang.String selector)
          Create a durable consumer.
 ConsumerEndpoint createQueueBrowser(JmsQueue queue, java.lang.String selector)
          Create a browser for the specified destination and the selector.
protected  void doStart()
          Start the service.
protected  void doStop()
          Stop the service.
 ConsumerEndpoint getConsumerEndpoint(long consumerId)
          Return the consumer with the specified identity.
 ConsumerEndpoint getConsumerEndpoint(java.lang.String persistentId)
          Return the consumer with the specified persistent identity.
 boolean hasActiveConsumers(JmsDestination destination)
          Determines if there are any active consumers for a destination.
 void subscribe(JmsTopic topic, java.lang.String name, java.lang.String clientID)
          Create a new durable subscription.
 void unsubscribe(JmsTopic topic)
          Remove all durable subscriptions for a destination.
 void unsubscribe(java.lang.String name, java.lang.String clientID)
          Remove a durable subscription.
 
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

ConsumerManagerImpl

public ConsumerManagerImpl(DestinationManager destinations,
                           DatabaseService database)
Construct a new ConsumerManager.
Parameters:
destinations - the destination manager
database - the database service
Method Detail

subscribe

public void subscribe(JmsTopic topic,
                      java.lang.String name,
                      java.lang.String clientID)
               throws javax.jms.JMSException
Create a new durable subscription.

A client can change an existing durable subscription by creating a new subscription with the same name and a new topic. Changing a durable subscriber is equivalent to unsubscribing the old one and creating a new one.

Specified by:
subscribe in interface ConsumerManager
Parameters:
topic - the topic to subscribe to
name - the subscription name
clientID - the client identifier. May be null
Throws:
javax.jms.InvalidDestinationException - if topic is not a persistent destination, or name is an invalid subscription name
javax.jms.JMSException - if the durable consumer can't be created

unsubscribe

public void unsubscribe(java.lang.String name,
                        java.lang.String clientID)
                 throws javax.jms.JMSException
Remove a durable subscription.

A subscription may only be removed if the associated DurableConsumerEndpoint is inactive.

Specified by:
unsubscribe in interface ConsumerManager
Parameters:
name - the subscription name
clientID - the client identifier. May be null
Throws:
javax.jms.InvalidDestinationException - if an invalid subscription name is specified.
javax.jms.JMSException - if the durable consumer is active, or cannot be removed

unsubscribe

public void unsubscribe(JmsTopic topic)
                 throws javax.jms.JMSException
Remove all durable subscriptions for a destination.

Subscriptions may only be removed if the associated ConsumerEndpoints are inactive.

Specified by:
unsubscribe in interface ConsumerManager
Parameters:
topic - the topic to remove consumers for
Throws:
javax.jms.JMSException - if the subscriptions can't be removed

createConsumer

public ConsumerEndpoint createConsumer(JmsDestination destination,
                                       long connectionId,
                                       java.lang.String selector,
                                       boolean noLocal)
                                throws javax.jms.JMSException,
                                       javax.jms.InvalidSelectorException
Create a transient consumer for the specified destination.
Specified by:
createConsumer in interface ConsumerManager
Parameters:
destination - the destination to consume messages from
connectionId - the identity of the connection that owns this consumer
selector - the message selector. May be null
noLocal - if true, and the destination is a topic, inhibits the delivery of messages published by its own connection. The behavior for noLocal is not specified if the destination is a queue.
Returns:
a new transient consumer

createDurableConsumer

public DurableConsumerEndpoint createDurableConsumer(JmsTopic topic,
                                                     java.lang.String name,
                                                     java.lang.String clientID,
                                                     long connectionId,
                                                     boolean noLocal,
                                                     java.lang.String selector)
                                              throws javax.jms.JMSException
Create a durable consumer.
Specified by:
createDurableConsumer in interface ConsumerManager
Parameters:
topic - the topic to subscribe to
name - the subscription name
clientID - the client identifier. May be null.
connectionId - the identity of the connection that owns this consumer
noLocal - if true, and the destination is a topic, inhibits the delivery of messages published by its own connection.
selector - the message selector. May be null
Returns:
the durable consumer endpoint
Throws:
javax.jms.InvalidDestinationException - if topic is not a persistent destination
javax.jms.InvalidSelectorException - if the selector is not well formed
javax.jms.JMSException - if a durable consumer is already active with the same name

createQueueBrowser

public ConsumerEndpoint createQueueBrowser(JmsQueue queue,
                                           java.lang.String selector)
                                    throws javax.jms.JMSException
Create a browser for the specified destination and the selector. A browser is responsible for passing all messages back to the client that reside on the queue
Specified by:
createQueueBrowser in interface ConsumerManager
Parameters:
queue - the queue to browse
selector - the message selector. May be null
Returns:
the queue browser endpoint
Throws:
javax.jms.JMSException - if the browser can't be created

closeConsumer

public void closeConsumer(ConsumerEndpoint consumer)
Close a consumer.
Specified by:
closeConsumer in interface ConsumerManager
Parameters:
consumer - the consumer to close

getConsumerEndpoint

public ConsumerEndpoint getConsumerEndpoint(long consumerId)
Return the consumer with the specified identity.
Specified by:
getConsumerEndpoint in interface ConsumerManager
Parameters:
consumerId - the identity of the consumer
Returns:
the associated consumer, or null if none exists

getConsumerEndpoint

public ConsumerEndpoint getConsumerEndpoint(java.lang.String persistentId)
Return the consumer with the specified persistent identity.
Specified by:
getConsumerEndpoint in interface ConsumerManager
Parameters:
persistentId - the persistent identity of the consumer
Returns:
the associated consumer, or null if none exists

hasActiveConsumers

public boolean hasActiveConsumers(JmsDestination destination)
Determines if there are any active consumers for a destination.
Specified by:
hasActiveConsumers in interface ConsumerManager
Parameters:
destination - the destination
Returns:
true if there is at least one consumer

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()
Stop the service.
Overrides:
doStop in class Service
Following copied from class: org.exolab.jms.service.Service
Throws:
ServiceException - if the service fails to stop


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