com.j_spaces.jms
Class GSTopicSubscriberImpl

java.lang.Object
  extended by com.j_spaces.jms.GSMessageConsumerImpl
      extended by com.j_spaces.jms.GSTopicSubscriberImpl
All Implemented Interfaces:
MessageConsumer, TopicSubscriber

public class GSTopicSubscriberImpl
extends GSMessageConsumerImpl
implements TopicSubscriber

GigaSpaces implementation of the javax.jms.TopicSubscriber interface. A client uses a TopicSubscriber object to receive messages that have been published to a topic. A TopicSubscriber object is the publish/subscribe form of a message consumer. A MessageConsumer can be created by using Session.createConsumer.

A TopicSession allows the creation of multiple TopicSubscriber objects per topic. It will deliver each message for a topic to each subscriber eligible to receive it. Each copy of the message is treated as a completely separate message. Work done on one copy has no effect on the others; acknowledging one does not acknowledge the others; one message may be delivered immediately, while another waits for its subscriber to process messages ahead of it.

Regular TopicSubscriber objects are not durable. They receive only messages that are published while they are active.

Messages filtered out by a subscriber's message selector will never be delivered to the subscriber. From the subscriber's perspective, they do not exist.

In some cases, a connection may both publish and subscribe to a topic. The subscriber NoLocal attribute allows a subscriber to inhibit the delivery of messages published by its own connection.

If a client needs to receive all the messages published on a topic, including the ones published while the subscriber is inactive, it uses a durable TopicSubscriber. The JMS provider retains a record of this durable subscription and insures that all messages from the topic's publishers are retained until they are acknowledged by this durable subscriber or they have expired.

Sessions with durable subscribers must always provide the same client identifier. In addition, each client must specify a name that uniquely identifies (within client identifier) each durable subscription it creates. Only one session at a time can have a TopicSubscriber for a particular durable subscription.

A client can change an existing durable subscription by creating a durable TopicSubscriber with the same name and a new topic and/or message selector. Changing a durable subscription is equivalent to unsubscribing (deleting) the old one and creating a new one.

The unsubscribe method is used to delete a durable subscription. The unsubscribe method can be used at the Session or TopicSession level. This method deletes the state being maintained on behalf of the subscriber by its provider.

Creating a MessageConsumer provides the same features as creating a TopicSubscriber. To create a durable subscriber, use of Session.CreateDurableSubscriber is recommended. The TopicSubscriber is provided to support existing code.

See Also:
Session.createConsumer(javax.jms.Destination), Session.createDurableSubscriber(javax.jms.Topic, java.lang.String), TopicSession, TopicSession.createSubscriber(javax.jms.Topic), MessageConsumer

Field Summary
 
Fields inherited from class com.j_spaces.jms.GSMessageConsumerImpl
m_durableSubscriptionName
 
Constructor Summary
GSTopicSubscriberImpl(GSSessionImpl sess, GSTopicImpl topic, String consumerKey, String subName, String selector, boolean noLocal, com.j_spaces.jdbc.ParserManager pManager)
          Constructs a Topic subscriber.
 
Method Summary
 void close()
          Close the subscriber.
 String getName()
          Return the durable subscription name
 boolean getNoLocal()
          API method Gets the NoLocal attribute for this subscriber.
 Topic getTopic()
          API method.
 boolean isDurableSubscriber()
          Determines if the subscriber is durable
 
Methods inherited from class com.j_spaces.jms.GSMessageConsumerImpl
getConsumerID, getMessageListener, getMessageSelector, isClosed, receive, receive, receiveNoWait, setMessageListener, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.jms.MessageConsumer
getMessageListener, getMessageSelector, receive, receive, receiveNoWait, setMessageListener
 

Constructor Detail

GSTopicSubscriberImpl

public GSTopicSubscriberImpl(GSSessionImpl sess,
                             GSTopicImpl topic,
                             String consumerKey,
                             String subName,
                             String selector,
                             boolean noLocal,
                             com.j_spaces.jdbc.ParserManager pManager)
                      throws JMSException
Constructs a Topic subscriber.

Parameters:
sess - The session the subscriber belongs to.
topic - The topic the subscriber subscribes to.
consumerKey -
subName - The subscription name, for durable subs only.
selector - The selector for filtering messages.
noLocal - true if the subscriber does not wish to consume messages published through the same connection.
pManager - ParserManager used for the selector support
Throws:
IllegalStateException - If the connection is broken.
JMSException - If the creation fails for any other reason.
Method Detail

getTopic

public Topic getTopic()
               throws JMSException
API method. Gets the GSTopicImpl associated with this subscriber.

Specified by:
getTopic in interface TopicSubscriber
Returns:
this subscriber's GSTopicImp
Throws:
JMSException - if the JMS provider fails to get the topic for this topic subscriber due to some internal error.
IllegalStateException - If the subscriber is m_closed.

getNoLocal

public boolean getNoLocal()
                   throws JMSException
API method Gets the NoLocal attribute for this subscriber. The default value for this attribute is false.

Specified by:
getNoLocal in interface TopicSubscriber
Returns:
noLocal true if locally published messages are being inhibited
Throws:
JMSException - if the JMS provider fails to get the NoLocal attribute for this topic subscriber due to some internal error.
IllegalStateException - If the subscriber is m_closed.

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

close

public void close()
           throws JMSException
Close the subscriber. This call blocks until a receive or message listener in progress has completed. A blocked subscriber receive call returns null when this subscriber is m_closed.

Specified by:
close in interface MessageConsumer
Overrides:
close in class GSMessageConsumerImpl
Throws:
JMSException - if this subscriber can't be m_closed
See Also:
MessageConsumer.close()