org.objectweb.joram.client.jms
Class MessageConsumer

java.lang.Object
  extended by org.objectweb.joram.client.jms.MessageConsumer
All Implemented Interfaces:
javax.jms.MessageConsumer
Direct Known Subclasses:
QueueReceiver, TopicSubscriber

public class MessageConsumer
extends java.lang.Object
implements javax.jms.MessageConsumer

Implements the javax.jms.MessageConsumer interface.

A client uses a MessageConsumer object to receive messages from a destination. A MessageConsumer object is created by calling the createConsumer method on a session object. A message consumer is normally dedicated to a unique destination.
A message consumer can be created with a message selector. A message selector allows the client to restrict the messages delivered to the message consumer to those that match the selector.
A client may either synchronously receive a message consumer's messages or have the consumer asynchronously deliver them as they arrive:


Nested Class Summary
(package private)  class MessageConsumer.Closer
          This class synchronizes the close.
private static class MessageConsumer.Status
          Status of the message consumer.
 
Field Summary
private  MessageConsumer.Closer closer
          Used to synchronize the method close()
protected  Destination dest
          The destination the consumer gets its messages from.
private  boolean durableSubscriber
          true for a durable subscriber.
private static org.objectweb.util.monolog.api.Logger logger
           
private  MessageConsumerListener mcl
          Message listener context (null if no message listener).
protected  boolean noLocal
          true if the subscriber does not wish to consume messages produced by its connection.
(package private)  boolean queueMode
          true if the consumer is a queue consumer.
(package private)  java.lang.String selector
          The selector for filtering messages.
protected  Session sess
          The session the consumer belongs to.
private  int status
          Status of the message consumer OPEN, CLOSE
(package private)  java.lang.String targetName
          The consumer server side target is either a queue or a subscription on its proxy.
 
Constructor Summary
MessageConsumer(Session sess, Destination dest, java.lang.String selector)
          Constructs a consumer.
MessageConsumer(Session sess, Destination dest, java.lang.String selector, java.lang.String subName, boolean noLocal)
          Constructs a consumer.
 
Method Summary
(package private)  void activateMessageInput()
           
protected  void checkClosed()
           
 void close()
          API method.
(package private)  void doClose()
           
 javax.jms.MessageListener getMessageListener()
          Gets the message consumer's MessageListener.
 java.lang.String getMessageSelector()
          Gets this message consumer's message selector expression.
 boolean getQueueMode()
           
 java.lang.String getTargetName()
           
(package private)  void passivateMessageInput()
           
 javax.jms.Message receive()
          Receives the next message produced for this message consumer.
 javax.jms.Message receive(long timeOut)
          Receives the next message that arrives before the specified timeout.
 javax.jms.Message receiveNoWait()
          Receives the next message if one is immediately available.
 void setMessageListener(javax.jms.MessageListener messageListener)
          Sets the message consumer's MessageListener.
private  void setStatus(int status)
           
 java.lang.String toString()
          Returns a string view of this consumer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static org.objectweb.util.monolog.api.Logger logger

selector

java.lang.String selector
The selector for filtering messages.


durableSubscriber

private boolean durableSubscriber
true for a durable subscriber.


dest

protected Destination dest
The destination the consumer gets its messages from.


noLocal

protected boolean noLocal
true if the subscriber does not wish to consume messages produced by its connection.


sess

protected Session sess
The session the consumer belongs to.


targetName

java.lang.String targetName
The consumer server side target is either a queue or a subscription on its proxy.


queueMode

boolean queueMode
true if the consumer is a queue consumer.


mcl

private MessageConsumerListener mcl
Message listener context (null if no message listener).


status

private int status
Status of the message consumer OPEN, CLOSE


closer

private MessageConsumer.Closer closer
Used to synchronize the method close()

Constructor Detail

MessageConsumer

MessageConsumer(Session sess,
                Destination dest,
                java.lang.String selector,
                java.lang.String subName,
                boolean noLocal)
          throws javax.jms.JMSException
Constructs a consumer.

Parameters:
sess - The session the consumer belongs to.
dest - The destination the consumer gets messages from.
selector - Selector for filtering messages.
subName - The durableSubscriber subscription's name, if any.
noLocal - true for a subscriber not wishing to consume messages produced by its connection.
Throws:
javax.jms.InvalidDestinationException - if an invalid destination is specified.
javax.jms.InvalidSelectorException - If the selector syntax is invalid.
javax.jms.IllegalStateException - If the connection is broken, or if the subscription is durable and already activated.
javax.jms.JMSException - Generic exception.

MessageConsumer

MessageConsumer(Session sess,
                Destination dest,
                java.lang.String selector)
          throws javax.jms.JMSException
Constructs a consumer.

Parameters:
sess - The session the consumer belongs to.
dest - The destination the consumer gets messages from.
selector - Selector for filtering messages.
Throws:
javax.jms.InvalidDestinationException - if an invalid destination is specified.
javax.jms.InvalidSelectorException - If the selector syntax is invalid.
javax.jms.IllegalStateException - If the connection is broken, or if the subscription is durable and already activated.
javax.jms.JMSException - Generic exception.
Method Detail

setStatus

private void setStatus(int status)

getTargetName

public final java.lang.String getTargetName()

getQueueMode

public final boolean getQueueMode()

checkClosed

protected void checkClosed()
                    throws javax.jms.IllegalStateException
Throws:
javax.jms.IllegalStateException

toString

public java.lang.String toString()
Returns a string view of this consumer.

Overrides:
toString in class java.lang.Object

setMessageListener

public void setMessageListener(javax.jms.MessageListener messageListener)
                        throws javax.jms.JMSException
Sets the message consumer's MessageListener. API method.

This method must not be called if the connection the consumer belongs to is started, because the session would then be accessed by the thread calling this method and by the thread controlling asynchronous deliveries. This situation is clearly forbidden by the single threaded nature of sessions. Moreover, unsetting a message listener without stopping the connection may lead to the situation where asynchronous deliveries would arrive on the connection, the session or the consumer without being able to reach their target listener!

Specified by:
setMessageListener in interface javax.jms.MessageConsumer
Throws:
javax.jms.IllegalStateException - If the consumer is closed, or if the connection is broken.
javax.jms.JMSException - If the request fails for any other reason.

getMessageListener

public javax.jms.MessageListener getMessageListener()
                                             throws javax.jms.JMSException
Gets the message consumer's MessageListener. API method.

Specified by:
getMessageListener in interface javax.jms.MessageConsumer
Throws:
javax.jms.IllegalStateException - If the consumer is closed.
javax.jms.JMSException

getMessageSelector

public final java.lang.String getMessageSelector()
                                          throws javax.jms.JMSException
Gets this message consumer's message selector expression. API method.

Specified by:
getMessageSelector in interface javax.jms.MessageConsumer
Throws:
javax.jms.IllegalStateException - If the consumer is closed.
javax.jms.JMSException

receive

public javax.jms.Message receive(long timeOut)
                          throws javax.jms.JMSException
Receives the next message that arrives before the specified timeout. API method.

Specified by:
receive in interface javax.jms.MessageConsumer
Throws:
javax.jms.IllegalStateException - If the consumer is closed, or if the connection is broken.
javax.jms.JMSSecurityException - If the requester is not a READER on the destination.
javax.jms.JMSException - If the request fails for any other reason.

receive

public javax.jms.Message receive()
                          throws javax.jms.JMSException
Receives the next message produced for this message consumer. API method.

Specified by:
receive in interface javax.jms.MessageConsumer
Throws:
javax.jms.IllegalStateException - If the consumer is closed, or if the connection is broken.
javax.jms.JMSSecurityException - If the requester is not a READER on the destination.
javax.jms.JMSException - If the request fails for any other reason.

receiveNoWait

public javax.jms.Message receiveNoWait()
                                throws javax.jms.JMSException
Receives the next message if one is immediately available. API method.

Specified by:
receiveNoWait in interface javax.jms.MessageConsumer
Throws:
javax.jms.IllegalStateException - If the consumer is closed, or if the connection is broken.
javax.jms.JMSSecurityException - If the requester is not a READER on the destination.
javax.jms.JMSException - If the request fails for any other reason.

close

public void close()
           throws javax.jms.JMSException
API method.

Specified by:
close in interface javax.jms.MessageConsumer
Throws:
javax.jms.JMSException

doClose

void doClose()
       throws javax.jms.JMSException
Throws:
javax.jms.JMSException

activateMessageInput

void activateMessageInput()
                    throws javax.jms.JMSException
Throws:
javax.jms.JMSException

passivateMessageInput

void passivateMessageInput()
                     throws javax.jms.JMSException
Throws:
javax.jms.JMSException


Copyright © 2010 ScalAgent D.T.. All Rights Reserved.