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

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

public class DefaultPublisher<T>
extends DefaultTopicParticipant
implements Publisher<T>

Default implementation of a Publisher.


Constructor Summary
DefaultPublisher(NodeIdentifier nodeIdentifier, TopicDeclaration topicDeclaration, MessageSerializer<T> serializer, MessageFactory messageFactory, java.util.concurrent.ScheduledExecutorService executorService)
           
 
Method Summary
 void addListener(PublisherListener<T> listener)
          Add a new lifecycle listener to the Publisher.
 void addSubscriber(SubscriberIdentifier subscriberIdentifer, org.jboss.netty.channel.Channel channel)
          Add a Subscriber connection to this Publisher.
 org.jboss.netty.buffer.ChannelBuffer finishHandshake(java.util.Map<java.lang.String,java.lang.String> incomingHeader)
          Complete connection handshake on buffer.
 PublisherDeclaration getDeclaration()
           
 PublisherIdentifier getIdentifier()
           
 boolean getLatchMode()
           
 int getNumberOfSubscribers()
          Get the number of Subscribers currently connected to the Publisher.
 int getQueueLimit()
           
 boolean hasSubscribers()
           
 T newMessage()
          Create a new message.
 void publish(T message)
          Publishes a message.
 void removeListener(PublisherListener<T> listener)
          Remove a lifecycle listener from the Publisher.
 void setLatchMode(boolean enabled)
           
 void setQueueLimit(int limit)
           
 void shutdown()
          Shuts down and unregisters the Publisher using the default timeout for PublisherListener.onShutdown(Publisher) callbacks.
 void shutdown(long timeout, java.util.concurrent.TimeUnit unit)
          Shuts down and unregisters the Publisher.
 void signalOnMasterRegistrationFailure()
          Signal all PublisherListeners that the Publisher has failed to register with the master.
 void signalOnMasterRegistrationSuccess()
          Signal all PublisherListeners that the Publisher has successfully registered with the master.
 void signalOnMasterUnregistrationFailure()
          Signal all PublisherListeners that the Publisher has failed to unregister with the master.
 void signalOnMasterUnregistrationSuccess()
          Signal all PublisherListeners that the Publisher has successfully unregistered with the master.
 java.lang.String toString()
           
 
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
 

Constructor Detail

DefaultPublisher

public DefaultPublisher(NodeIdentifier nodeIdentifier,
                        TopicDeclaration topicDeclaration,
                        MessageSerializer<T> serializer,
                        MessageFactory messageFactory,
                        java.util.concurrent.ScheduledExecutorService executorService)
Method Detail

setLatchMode

public void setLatchMode(boolean enabled)
Specified by:
setLatchMode in interface Publisher<T>
Parameters:
enabled - true if published messages should be latched, false otherwise
See Also:
Publisher options documentation

getLatchMode

public boolean getLatchMode()
Specified by:
getLatchMode in interface Publisher<T>
Returns:
true if published messages will be latched, false otherwise
See Also:
Publisher options documentation

shutdown

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

PublisherListener.onShutdown(Publisher) callbacks are executed in separate threads.

Specified by:
shutdown in interface Publisher<T>

shutdown

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

PublisherListener.onShutdown(Publisher) callbacks are executed in separate threads.

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

getIdentifier

public PublisherIdentifier getIdentifier()

getDeclaration

public PublisherDeclaration getDeclaration()

hasSubscribers

public boolean hasSubscribers()
Specified by:
hasSubscribers in interface Publisher<T>
Returns:
true if getNumberOfSubscribers() > 0, false otherwise

getNumberOfSubscribers

public int getNumberOfSubscribers()
Description copied from interface: Publisher
Get the number of Subscribers currently connected to the Publisher.

This counts the number of Subscriber registered. If a Subscriber does not shutdown properly it will not be unregistered and thus will contribute to this count.

Specified by:
getNumberOfSubscribers in interface Publisher<T>
Returns:
the number of Subscribers currently connected to the Publisher

newMessage

public T newMessage()
Description copied from interface: Publisher
Create a new message.

Specified by:
newMessage in interface Publisher<T>
Returns:
a new message

publish

public void publish(T message)
Description copied from interface: Publisher
Publishes a message. This message will be available on the topic that this Publisher has been associated with.

Specified by:
publish in interface Publisher<T>
Parameters:
message - the message to publish

finishHandshake

public org.jboss.netty.buffer.ChannelBuffer finishHandshake(java.util.Map<java.lang.String,java.lang.String> incomingHeader)
Complete connection handshake on buffer. This generates the connection header for this publisher to send and also updates the connection state of this publisher.

Returns:
encoded connection header from subscriber

addSubscriber

public void addSubscriber(SubscriberIdentifier subscriberIdentifer,
                          org.jboss.netty.channel.Channel channel)
Add a Subscriber connection to this Publisher.

Parameters:
subscriberIdentifer - the SubscriberIdentifier of the new subscriber
channel - the communication Channel to the Subscriber

addListener

public void addListener(PublisherListener<T> listener)
Description copied from interface: Publisher
Add a new lifecycle listener to the Publisher.

Specified by:
addListener in interface Publisher<T>
Parameters:
listener - the PublisherListener to add

removeListener

public void removeListener(PublisherListener<T> listener)
Description copied from interface: Publisher
Remove a lifecycle listener from the Publisher.

Nothing will happen if the given listener is not registered.

Specified by:
removeListener in interface Publisher<T>
Parameters:
listener - the PublisherListener to remove

signalOnMasterRegistrationSuccess

public void signalOnMasterRegistrationSuccess()
Signal all PublisherListeners that the Publisher 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 PublisherListeners that the Publisher 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 PublisherListeners that the Publisher 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 PublisherListeners that the Publisher has failed to unregister with the master.

Each listener is called in a separate thread.

Specified by:
signalOnMasterUnregistrationFailure in class DefaultTopicParticipant

toString

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

setQueueLimit

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

getQueueLimit

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