org.ros.node.topic
Interface Publisher<T>

Type Parameters:
T - the Publisher may only publish messages of this type
All Superinterfaces:
TopicParticipant
All Known Implementing Classes:
DefaultPublisher

public interface Publisher<T>
extends TopicParticipant

Publishes messages of a given type on a given ROS topic.


Method Summary
 void addListener(PublisherListener<T> listener)
          Add a new lifecycle listener to the Publisher.
 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.
 
Methods inherited from interface org.ros.internal.node.topic.TopicParticipant
getTopicMessageType, getTopicName
 

Method Detail

setLatchMode

void setLatchMode(boolean enabled)
Parameters:
enabled - true if published messages should be latched, false otherwise
See Also:
Publisher options documentation

getLatchMode

boolean getLatchMode()
Returns:
true if published messages will be latched, false otherwise
See Also:
Publisher options documentation

newMessage

T newMessage()
Create a new message.

Returns:
a new message

publish

void publish(T message)
Publishes a message. This message will be available on the topic that this Publisher has been associated with.

Parameters:
message - the message to publish

hasSubscribers

boolean hasSubscribers()
Returns:
true if getNumberOfSubscribers() > 0, false otherwise

getNumberOfSubscribers

int getNumberOfSubscribers()
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.

Returns:
the number of Subscribers currently connected to the Publisher

shutdown

void shutdown(long timeout,
              java.util.concurrent.TimeUnit unit)
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.


shutdown

void shutdown()
Shuts down and unregisters the Publisher using the default timeout for PublisherListener.onShutdown(Publisher) callbacks.

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

See Also:
shutdown(long, TimeUnit)

addListener

void addListener(PublisherListener<T> listener)
Add a new lifecycle listener to the Publisher.

Parameters:
listener - the PublisherListener to add

removeListener

void removeListener(PublisherListener<T> listener)
Remove a lifecycle listener from the Publisher.

Nothing will happen if the given listener is not registered.

Parameters:
listener - the PublisherListener to remove

setQueueLimit

void setQueueLimit(int limit)
Parameters:
limit - the maximum number of messages to queue (i.e. buffer) for sending

getQueueLimit

int getQueueLimit()
Returns:
the maximum number of messages to queue (i.e. buffer) for sending