org.ros.internal.node.topic
Class DefaultSubscriber<T>

java.lang.Object
  extended by org.ros.internal.node.topic.DefaultTopicParticipant
      extended by org.ros.internal.node.topic.DefaultSubscriber<T>
All Implemented Interfaces:
TopicParticipant, Subscriber<T>

public class DefaultSubscriber<T>
extends DefaultTopicParticipant
implements Subscriber<T>

Default implementation of a Subscriber.


Field Summary
 
Fields inherited from interface org.ros.node.topic.Subscriber
TOPIC_MESSAGE_TYPE_WILDCARD
 
Method Summary
 void addMessageListener(MessageListener<T> listener)
           
 void addPublisher(PublisherIdentifier publisherIdentifier, java.net.InetSocketAddress address)
           
 void addSubscriberListener(SubscriberListener<T> listener)
          Add a new lifecycle listener to the subscriber.
 boolean getLatchMode()
           
 int getQueueLimit()
           
 java.util.Collection<java.lang.String> getSupportedProtocols()
           
static
<S> DefaultSubscriber<S>
newDefault(NodeIdentifier nodeIdentifier, TopicDeclaration description, java.util.concurrent.ScheduledExecutorService executorService, MessageDeserializer<S> deserializer)
           
 void removeMessageListener(MessageListener<T> listener)
           
 void removeSubscriberListener(SubscriberListener<T> listener)
          Remove a lifecycle listener from the subscriber.
 void setQueueLimit(int limit)
           
 void shutdown()
          Shuts down and unregisters the Subscriber using the default timeout for SubscriberListener.onShutdown(Subscriber) callbacks.
 void shutdown(long timeout, java.util.concurrent.TimeUnit unit)
          Shuts down and unregisters the Subscriber.
 void signalOnMasterRegistrationFailure()
          Signal all SubscriberListeners that the Subscriber has failed to register with the master.
 void signalOnMasterRegistrationSuccess()
          Signal all SubscriberListeners that the Subscriber has successfully registered with the master.
 void signalOnMasterUnregistrationFailure()
          Signal all SubscriberListeners that the Subscriber has failed to unregister with the master.
 void signalOnMasterUnregistrationSuccess()
          Signal all SubscriberListeners that the Subscriber has successfully unregistered with the master.
 void signalOnNewPublisher(PublisherIdentifier publisherIdentifier)
          Signal all SubscriberListeners that a new Publisher has connected.
 SubscriberDeclaration toDefinition()
           
 SubscriberIdentifier toIdentifier()
           
 java.lang.String toString()
           
 void updatePublishers(java.util.Collection<PublisherIdentifier> publisherIdentifiers)
          Updates the list of Publishers for the topic that this Subscriber is interested in.
 
Methods inherited from class org.ros.internal.node.topic.DefaultTopicParticipant
getTopicDeclaration, getTopicDeclarationAsList, getTopicDeclarationHeader, getTopicMessageType, getTopicName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ros.internal.node.topic.TopicParticipant
getTopicMessageType, getTopicName
 

Method Detail

newDefault

public static <S> DefaultSubscriber<S> newDefault(NodeIdentifier nodeIdentifier,
                                                  TopicDeclaration description,
                                                  java.util.concurrent.ScheduledExecutorService executorService,
                                                  MessageDeserializer<S> deserializer)

toIdentifier

public SubscriberIdentifier toIdentifier()

toDefinition

public SubscriberDeclaration toDefinition()

getSupportedProtocols

public java.util.Collection<java.lang.String> getSupportedProtocols()

getLatchMode

public boolean getLatchMode()
Specified by:
getLatchMode in interface Subscriber<T>
Returns:
true if the Publisher of this Subscriber's topic is latched, false otherwise

addMessageListener

public void addMessageListener(MessageListener<T> listener)
Specified by:
addMessageListener in interface Subscriber<T>
Parameters:
listener - this MessageListener will be called for every new message received

removeMessageListener

public void removeMessageListener(MessageListener<T> listener)
Specified by:
removeMessageListener in interface Subscriber<T>
Parameters:
listener - the MessageListener to remove

addPublisher

public void addPublisher(PublisherIdentifier publisherIdentifier,
                         java.net.InetSocketAddress address)

updatePublishers

public void updatePublishers(java.util.Collection<PublisherIdentifier> publisherIdentifiers)
Updates the list of Publishers for the topic that this Subscriber is interested in.

Parameters:
publisherIdentifiers - Collection of PublisherIdentifiers for the subscribed topic

shutdown

public void shutdown(long timeout,
                     java.util.concurrent.TimeUnit unit)
Description copied from interface: Subscriber
Shuts down and unregisters the Subscriber. using the default timeout Shutdown is delayed by at most the specified timeout to allow SubscriberListener.onShutdown(Subscriber) callbacks to complete.

SubscriberListener.onShutdown(Subscriber) callbacks are executed in separate threads.

Specified by:
shutdown in interface Subscriber<T>

shutdown

public void shutdown()
Description copied from interface: Subscriber
Shuts down and unregisters the Subscriber using the default timeout for SubscriberListener.onShutdown(Subscriber) callbacks.

SubscriberListener.onShutdown(Subscriber) callbacks are executed in separate threads.

Specified by:
shutdown in interface Subscriber<T>
See Also:
Subscriber.shutdown(long, TimeUnit)

addSubscriberListener

public void addSubscriberListener(SubscriberListener<T> listener)
Description copied from interface: Subscriber
Add a new lifecycle listener to the subscriber.

Specified by:
addSubscriberListener in interface Subscriber<T>
Parameters:
listener - The listener to add.

removeSubscriberListener

public void removeSubscriberListener(SubscriberListener<T> listener)
Description copied from interface: Subscriber
Remove a lifecycle listener from the subscriber.

Nothing will happen if the given listener is not registered.

Specified by:
removeSubscriberListener in interface Subscriber<T>
Parameters:
listener - The listener to remove.

signalOnMasterRegistrationSuccess

public void signalOnMasterRegistrationSuccess()
Signal all SubscriberListeners that the Subscriber has successfully registered with the master.

Each listener is called in a separate thread.

Specified by:
signalOnMasterRegistrationSuccess in class DefaultTopicParticipant

signalOnMasterRegistrationFailure

public void signalOnMasterRegistrationFailure()
Signal all SubscriberListeners that the Subscriber has failed to register with the master.

Each listener is called in a separate thread.

Specified by:
signalOnMasterRegistrationFailure in class DefaultTopicParticipant

signalOnMasterUnregistrationSuccess

public void signalOnMasterUnregistrationSuccess()
Signal all SubscriberListeners that the Subscriber has successfully unregistered with the master.

Each listener is called in a separate thread.

Specified by:
signalOnMasterUnregistrationSuccess in class DefaultTopicParticipant

signalOnMasterUnregistrationFailure

public void signalOnMasterUnregistrationFailure()
Signal all SubscriberListeners that the Subscriber has failed to unregister with the master.

Each listener is called in a separate thread.

Specified by:
signalOnMasterUnregistrationFailure in class DefaultTopicParticipant

signalOnNewPublisher

public void signalOnNewPublisher(PublisherIdentifier publisherIdentifier)
Signal all SubscriberListeners that a new Publisher has connected.

Each listener is called in a separate thread.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setQueueLimit

public void setQueueLimit(int limit)
Specified by:
setQueueLimit in interface Subscriber<T>
Parameters:
limit - the maximum number of incoming messages to queue (i.e. buffer)

getQueueLimit

public int getQueueLimit()
Specified by:
getQueueLimit in interface Subscriber<T>
Returns:
the maximum number of incoming messages to queue (i.e. buffer)