com.j_spaces.jms
Class GSMessageConsumerImpl

java.lang.Object
  extended by com.j_spaces.jms.GSMessageConsumerImpl
All Implemented Interfaces:
MessageConsumer, QueueReceiver, TopicSubscriber
Direct Known Subclasses:
GSQueueReceiverImpl, GSTopicSubscriberImpl

public class GSMessageConsumerImpl
extends Object
implements MessageConsumer, QueueReceiver, TopicSubscriber

Implements the javax.jms.MessageConsumer interface. GigaSpaces implementation of the JMS MessageConsumer Interface and the Jini RemoteEventListener.

 - It holds MessageConsumer Destination, Topic or Queue
 - It creates the GigaSpaces OnMessageNotifyDelegator and the notify() calls
 the MessageListener.onMessage() method.
 - It supports both Synchronized and Asynchronized message consumption.
 One can use the method receive() for the Synchronized form,
 or use the NotifyDelegator together with a MessageListener
 implementation for the Asynchronized message receiving manner.
 


Field Summary
 String m_durableSubscriptionName
          The durable consumer subscription name.
 
Constructor Summary
GSMessageConsumerImpl(GSSessionImpl session, Destination dest, String consumerID, String subsriptionName, String selector, boolean noLocal, com.j_spaces.jdbc.ParserManager pManager)
          Constructs a message consumer.
 
Method Summary
 void close()
          Cancels the onMessage notify delegator, using its Lease.cancel() if it is an Asyc operation Also it removes the current consumer from the consumers list held by the session.
 String getConsumerID()
          Returns the consumer ID.
 Destination getDestination()
           
 MessageListener getMessageListener()
          API method.
 String getMessageSelector()
          API method.
 String getName()
          Return the durable subscription name
 boolean getNoLocal()
           
 Queue getQueue()
           
 Topic getTopic()
           
 boolean isClosed()
          Determines if the consumer is closed
 boolean isDurableSubscriber()
          Determines if the subscriber is durable
 Message receive()
          API method.
 Message receive(long timeout)
          API method.
 Message receiveNoWait()
          API method.
 void setMessageListener(MessageListener listener)
          This method is called by the JMS Client, it sets the MessageListener implementation and It creates a GigaSpaces NotifyDelegator for Asynchronic messaging.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_durableSubscriptionName

public String m_durableSubscriptionName
The durable consumer subscription name.

Constructor Detail

GSMessageConsumerImpl

public GSMessageConsumerImpl(GSSessionImpl session,
                             Destination dest,
                             String consumerID,
                             String subsriptionName,
                             String selector,
                             boolean noLocal,
                             com.j_spaces.jdbc.ParserManager pManager)
                      throws JMSException
Constructs a message consumer.

Parameters:
session - The m_session the consumer belongs to.
dest - The destination the consumer gets messages from.
consumerID -
subsriptionName - The m_durableSubscriber subscription's name, if any.
selector - Selector string for filtering messages.
Throws:
InvalidSelectorException - If the m_selector syntax is invalid.
IllegalStateException - If the connection is broken.
JMSException - If the creation fails for any other reason.
Method Detail

getMessageSelector

public String getMessageSelector()
                          throws JMSException
API method.

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

getMessageListener

public MessageListener getMessageListener()
                                   throws JMSException
API method.

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

setMessageListener

public void setMessageListener(MessageListener listener)
                        throws JMSException
This method is called by the JMS Client, it sets the MessageListener implementation and It creates a GigaSpaces NotifyDelegator for Asynchronic messaging. It also supports the case of a Durable Subscriber, in which accumulated messages in the GigaSpaces space while it was not up and listening. It performs a m_space.readMultiple() which gets all the pending entries, it calls then the MessageListener.onMessage(), same as the notify() does, but it also keeps the entries in the pendingEntriesHash so the notify() will check and wont execute duplicated entries. 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 MessageConsumer
Parameters:
listener -
Throws:
IllegalStateException - If the consumer is closed.
JMSException
See Also:
MessageConsumer.setMessageListener(javax.jms.MessageListener)

receive

public Message receive()
                throws JMSException
API method. Using default readTimeout which is Long.MAX_VALUE. This call blocks until a message arrives, the timeout expires, or this message consumer is m_closed.

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

receive

public Message receive(long timeout)
                throws JMSException
API method. It is a Synch receive implementation which reads ExternalEntry from space, then it checks if the ExternalEntry is still valid and did not expired. In case of a CLIENT_ACK then we prepare a JMSAckDataEntry to be later written to space, otherwise (if ACK is not necessary) if it is a Queue, we perform a space.clear() operation, which clears the entry from space, but if it is a Topic we leave it as is.

Specified by:
receive in interface MessageConsumer
Parameters:
timeout - This call blocks until a message arrives, the timeout expires, or this message consumer is closed. The jms client may select A timeout of zero, that means it never expires, and the call blocks indefinitely. It is the same as the Space timeout which its value to Long.MAX_VALUE Regarding the space timeout, it means how long the client is willing to wait for a transactionally proper matching entry. A timeout of IJSpace.NO_WAIT means to wait no time at all; this is equivalent to a wait of zero (in space only, not in jms).
Throws:
IllegalStateException - If the consumer is closed, or if the connection is broken.
JMSSecurityException - If the requester is not a READER on the destination.
JMSException - If the request fails for any other reason.

receiveNoWait

public Message receiveNoWait()
                      throws JMSException
API method.

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

isClosed

public boolean isClosed()
Determines if the consumer is closed

Returns:
true if the consumer is closed

close

public void close()
           throws JMSException
Cancels the onMessage notify delegator, using its Lease.cancel() if it is an Asyc operation Also it removes the current consumer from the consumers list held by the session.

Specified by:
close in interface MessageConsumer
Throws:
JMSException
See Also:
MessageConsumer.close()

toString

public String toString()
Overrides:
toString in class Object

getConsumerID

public String getConsumerID()
Returns the consumer ID.

Returns:
The consumer ID

getName

public String getName()
Return the durable subscription name

Returns:
the durable subscription name, or null if this is a non-durable subscriber

isDurableSubscriber

public boolean isDurableSubscriber()
Determines if the subscriber is durable

Returns:
true if the subscriber is durable

getQueue

public Queue getQueue()
               throws JMSException
Specified by:
getQueue in interface QueueReceiver
Throws:
JMSException
See Also:
QueueReceiver.getQueue()

getNoLocal

public boolean getNoLocal()
                   throws JMSException
Specified by:
getNoLocal in interface TopicSubscriber
Throws:
JMSException
See Also:
TopicSubscriber.getNoLocal()

getTopic

public Topic getTopic()
               throws JMSException
Specified by:
getTopic in interface TopicSubscriber
Throws:
JMSException
See Also:
TopicSubscriber.getTopic()

getDestination

public Destination getDestination()
                           throws JMSException
Throws:
JMSException