org.exolab.jms.messagemgr
Class AbstractConsumerEndpoint

java.lang.Object
  |
  +--org.exolab.jms.messagemgr.AbstractConsumerEndpoint
All Implemented Interfaces:
ConsumerEndpoint, org.exolab.jms.messagemgr.DestinationCacheEventListener
Direct Known Subclasses:
org.exolab.jms.messagemgr.AbstractTopicConsumerEndpoint, QueueBrowserEndpoint, QueueConsumerEndpoint

public abstract class AbstractConsumerEndpoint
extends java.lang.Object
implements ConsumerEndpoint

Abstract implementation of the ConsumerEndpoint interface.

Version:
$Revision: 1.3 $ $Date: 2005/08/30 06:25:47 $
Author:
Jim Alateras, Tim Anderson

Constructor Summary
AbstractConsumerEndpoint(long consumerId, JmsDestination destination, java.lang.String selector, boolean noLocal)
          Construct a new ConsumerEndpoint.
 
Method Summary
 boolean canConsume(JmsDestination destination)
          Determines if this consumer can consume messages from the specified destination.
 void close()
          Close this endpoint.
protected abstract  void doClose()
          Closes the endpoint.
protected abstract  MessageHandle doReceive(Condition cancel)
          Return the next available message to the client.
 JmsDestination getDestination()
          Return the destination that this consumer is accessing.
 long getId()
          Returns the identity of this consumer.
 boolean getNoLocal()
          Returns if locally produced messages are being inhibited.
 java.lang.String getPersistentId()
          Returns the persistent identifier for this consumer.
 Selector getSelector()
          Returns the message selector.
 boolean isAsynchronous()
          Determines if this is an asynchronous consumer.
 boolean isClosed()
          Determines if this consumer is closed, or in the process of being closed.
 boolean isPersistent()
          Determines if this is a persistent or non-persistent consumer.
 boolean isWaitingForMessage()
          Determines if the client is currently waiting for a message.
protected  void notifyMessageAvailable()
          Notify the listener that a message is available for this consumer.
 MessageHandle receive(Condition cancel)
          Return the next available message to the client.
 boolean selects(MessageImpl message)
          Determines if a message is selected by the consumer.
 void setAsynchronous(boolean asynchronous)
          Indicates if this is an asynchronous consumer.
 void setListener(ConsumerEndpointListener listener)
          Set the listener for this consumer.
protected  void setNoLocal(boolean noLocal)
          Determines if locally produced messages are being inhibited.
protected  void setSelector(java.lang.String selector)
          Sets the message selector.
 void setWaitingForMessage(Condition condition)
          Indicates that the client is currently waiting for a message.
 java.lang.String toString()
          Returns a stringified version of the consumer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.exolab.jms.messagemgr.ConsumerEndpoint
getMessageCount, messageAdded, messageRemoved, persistentMessageAdded, persistentMessageRemoved
 

Constructor Detail

AbstractConsumerEndpoint

public AbstractConsumerEndpoint(long consumerId,
                                JmsDestination destination,
                                java.lang.String selector,
                                boolean noLocal)
                         throws javax.jms.InvalidSelectorException
Construct a new ConsumerEndpoint.

The destination and selector determine where it will be sourcing its messages from, and scheduler is used to asynchronously deliver messages to the consumer.

Parameters:
consumerId - the identity of this consumer
destination - the destination to access
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.
Throws:
javax.jms.InvalidSelectorException - if the selector is not well formed
Method Detail

getId

public long getId()
Returns the identity of this consumer.
Specified by:
getId in interface ConsumerEndpoint
Returns:
the identity of this consumer

isPersistent

public boolean isPersistent()
Determines if this is a persistent or non-persistent consumer.

If persistent, then the consumer is persistent accross subscriptions and server restarts, and getPersistentId() returns a non-null value.

Specified by:
isPersistent in interface ConsumerEndpoint
Returns:
false

getPersistentId

public java.lang.String getPersistentId()
Returns the persistent identifier for this consumer. This is the identity of the consumer which is persistent across subscriptions and server restarts.
Specified by:
getPersistentId in interface ConsumerEndpoint
Returns:
null

getDestination

public JmsDestination getDestination()
Return the destination that this consumer is accessing.
Specified by:
getDestination in interface ConsumerEndpoint
Returns:
the destination that this consumer is accessing

canConsume

public boolean canConsume(JmsDestination destination)
Determines if this consumer can consume messages from the specified destination.
Specified by:
canConsume in interface ConsumerEndpoint
Parameters:
destination - the destination
Returns:
true if the consumer can consume messages from destination; otherwise false

getSelector

public Selector getSelector()
Returns the message selector.
Specified by:
getSelector in interface ConsumerEndpoint
Returns:
the message selector, or null if none was specified by the client

selects

public boolean selects(MessageImpl message)
Determines if a message is selected by the consumer.
Specified by:
selects in interface ConsumerEndpoint
Parameters:
message - the message to check
Returns:
true if the message is selected; otherwise false

getNoLocal

public boolean getNoLocal()
Returns if locally produced messages are being inhibited.
Specified by:
getNoLocal in interface ConsumerEndpoint
Returns:
true if locally published messages are being inhibited.

receive

public final MessageHandle receive(Condition cancel)
                            throws javax.jms.JMSException
Return the next available message to the client.
Specified by:
receive in interface ConsumerEndpoint
Parameters:
cancel -  
Returns:
the next message, or null if none is available
Throws:
javax.jms.JMSException - for any error

setAsynchronous

public void setAsynchronous(boolean asynchronous)
Indicates if this is an asynchronous consumer.

An asynchronous consumer has a client MessageConsumer with an associated MessageListener.

Specified by:
setAsynchronous in interface ConsumerEndpoint
Parameters:
asynchronous - if true marks this as an asynchronous consumer

isAsynchronous

public boolean isAsynchronous()
Determines if this is an asynchronous consumer.
Specified by:
isAsynchronous in interface ConsumerEndpoint
Returns:
true if this is an asynchronous consumer; otherwise false

setWaitingForMessage

public void setWaitingForMessage(Condition condition)
Indicates that the client is currently waiting for a message.
Specified by:
setWaitingForMessage in interface ConsumerEndpoint
Parameters:
condition - the condition to evaluate to determine if the client is waiting for message. May be null.

isWaitingForMessage

public boolean isWaitingForMessage()
Determines if the client is currently waiting for a message.
Specified by:
isWaitingForMessage in interface ConsumerEndpoint
Returns:
true if the client is waiting for messages; otherwise false

setListener

public void setListener(ConsumerEndpointListener listener)
Set the listener for this consumer. If a listener is set, it is notified when messages become available.
Specified by:
setListener in interface ConsumerEndpoint
Parameters:
listener - the listener to add, or null to remove an existing listener

isClosed

public final boolean isClosed()
Determines if this consumer is closed, or in the process of being closed.
Specified by:
isClosed in interface ConsumerEndpoint
Returns:
true if this consumer is closed; otherwise false

close

public final void close()
Close this endpoint.
Specified by:
close in interface ConsumerEndpoint

toString

public java.lang.String toString()
Returns a stringified version of the consumer.
Overrides:
toString in class java.lang.Object
Returns:
a stringified version of the consumer

doReceive

protected abstract MessageHandle doReceive(Condition cancel)
                                    throws javax.jms.JMSException
Return the next available message to the client.

This method will not be invoked if the consumer is being closed, however it is possible for close() to be invoked while this method is in progress. Implementations should therefore invoke isClosed() to determine if the consumer is in the process of being closed, and if so, return null.

Parameters:
cancel -  
Returns:
the next message, or null if none is available
Throws:
javax.jms.JMSException - for any error

doClose

protected abstract void doClose()
Closes the endpoint.

notifyMessageAvailable

protected void notifyMessageAvailable()
Notify the listener that a message is available for this consumer.

setSelector

protected void setSelector(java.lang.String selector)
                    throws javax.jms.InvalidSelectorException
Sets the message selector.
Parameters:
selector - the message selector. May be null
Throws:
javax.jms.InvalidSelectorException - if the selector is not well formed

setNoLocal

protected void setNoLocal(boolean noLocal)
Determines if locally produced messages are being inhibited.
Parameters:
noLocal - if true, locally published messages are inhibited.


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