Package org.ros.node.topic
Interface Publisher<T>
- Type Parameters:
T- thePublishermay only publish messages of this type
- All Superinterfaces:
TopicParticipant
- All Known Implementing Classes:
DefaultPublisher
Publishes messages of a given type on a given ROS topic.
- Author:
- ethan.rublee@gmail.com (Ethan Rublee), damonkohler@google.com (Damon Kohler)
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(PublisherListener<T> listener) Add a new lifecycle listener to thePublisher.booleanintGet the number ofSubscribers currently connected to thePublisher.booleanCreate a new message.voidPublishes a message.voidsetLatchMode(boolean enabled) voidshutdown()Shuts down and unregisters thePublisherusing the default timeout forPublisherListener.onShutdown(Publisher)callbacks.voidShuts down and unregisters thePublisher.Methods inherited from interface org.ros.internal.node.topic.TopicParticipant
getTopicMessageType, getTopicName
-
Method Details
-
setLatchMode
void setLatchMode(boolean enabled) - Parameters:
enabled-trueif published messages should be latched,falseotherwise- See Also:
-
getLatchMode
boolean getLatchMode()- Returns:
trueif published messages will be latched,falseotherwise- See Also:
-
newMessage
T newMessage()Create a new message.- Returns:
- a new message
-
publish
Publishes a message. This message will be available on the topic that thisPublisherhas been associated with.- Parameters:
message- the message to publish
-
hasSubscribers
boolean hasSubscribers()- Returns:
trueifgetNumberOfSubscribers() > 0,falseotherwise
-
getNumberOfSubscribers
int getNumberOfSubscribers()Get the number ofSubscribers currently connected to thePublisher.This counts the number of
Subscriberregistered. If aSubscriberdoes not shutdown properly it will not be unregistered and thus will contribute to this count.- Returns:
- the number of
Subscribers currently connected to thePublisher
-
shutdown
Shuts down and unregisters thePublisher. Shutdown is delayed by at most the specified timeout to allowPublisherListener.onShutdown(Publisher)callbacks to complete.PublisherListener.onShutdown(Publisher)callbacks are executed in separate threads. -
shutdown
void shutdown()Shuts down and unregisters thePublisherusing the default timeout forPublisherListener.onShutdown(Publisher)callbacks.PublisherListener.onShutdown(Publisher)callbacks are executed in separate threads.- See Also:
-
addListener
Add a new lifecycle listener to thePublisher.- Parameters:
listener- thePublisherListenerto add
-