Package org.ros.internal.node.topic
Class DefaultPublisher<T>
java.lang.Object
org.ros.internal.node.topic.DefaultTopicParticipant
org.ros.internal.node.topic.DefaultPublisher<T>
- All Implemented Interfaces:
TopicParticipant,Publisher<T>
Default implementation of a
Publisher.- Author:
- damonkohler@google.com (Damon Kohler)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultPublisher(NodeIdentifier nodeIdentifier, TopicDeclaration topicDeclaration, org.ros.message.MessageSerializer<T> serializer, org.ros.message.MessageFactory messageFactory, ScheduledExecutorService executorService) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(PublisherListener<T> listener) Add a new lifecycle listener to thePublisher.voidaddSubscriber(SubscriberIdentifier subscriberIdentifer, org.jboss.netty.channel.Channel channel) Add aSubscriberconnection to thisPublisher.org.jboss.netty.buffer.ChannelBufferfinishHandshake(ConnectionHeader incomingHeader) Complete connection handshake on buffer.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.voidSends shutdown signals and awaits for them to be received bysignalOnMasterUnregistrationSuccess()orsignalOnMasterUnregistrationFailure()before continuing shutdownvoidSignal allPublisherListeners that thePublisherhas failed to register with the master.voidSignal allPublisherListeners that thePublisherhas successfully registered with the master.voidSignal allPublisherListeners that thePublisherhas failed to unregister with the master.voidSignal allPublisherListeners that thePublisherhas successfully unregistered with the master.toString()Methods inherited from class org.ros.internal.node.topic.DefaultTopicParticipant
getTopicDeclaration, getTopicDeclarationAsList, getTopicDeclarationHeader, getTopicMessageType, getTopicNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.ros.internal.node.topic.TopicParticipant
getTopicMessageType, getTopicName
-
Constructor Details
-
DefaultPublisher
public DefaultPublisher(NodeIdentifier nodeIdentifier, TopicDeclaration topicDeclaration, org.ros.message.MessageSerializer<T> serializer, org.ros.message.MessageFactory messageFactory, ScheduledExecutorService executorService)
-
-
Method Details
-
setLatchMode
public void setLatchMode(boolean enabled) - Specified by:
setLatchModein interfacePublisher<T>- Parameters:
enabled-trueif published messages should be latched,falseotherwise- See Also:
-
getLatchMode
public boolean getLatchMode()- Specified by:
getLatchModein interfacePublisher<T>- Returns:
trueif published messages will be latched,falseotherwise- See Also:
-
shutdown
Sends shutdown signals and awaits for them to be received bysignalOnMasterUnregistrationSuccess()orsignalOnMasterUnregistrationFailure()before continuing shutdown -
shutdown
public void shutdown()Description copied from interface:PublisherShuts down and unregisters thePublisherusing the default timeout forPublisherListener.onShutdown(Publisher)callbacks.PublisherListener.onShutdown(Publisher)callbacks are executed in separate threads. -
getIdentifier
-
toDeclaration
-
hasSubscribers
public boolean hasSubscribers()- Specified by:
hasSubscribersin interfacePublisher<T>- Returns:
trueifgetNumberOfSubscribers() > 0,falseotherwise
-
getNumberOfSubscribers
public int getNumberOfSubscribers()Description copied from interface:PublisherGet 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.- Specified by:
getNumberOfSubscribersin interfacePublisher<T>- Returns:
- the number of
Subscribers currently connected to thePublisher
-
newMessage
Description copied from interface:PublisherCreate a new message.- Specified by:
newMessagein interfacePublisher<T>- Returns:
- a new message
-
publish
Description copied from interface:PublisherPublishes a message. This message will be available on the topic that thisPublisherhas been associated with. -
finishHandshake
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 aSubscriberconnection to thisPublisher.- Parameters:
subscriberIdentifer- theSubscriberIdentifierof the new subscriberchannel- the communicationChannelto theSubscriber
-
addListener
Description copied from interface:PublisherAdd a new lifecycle listener to thePublisher.- Specified by:
addListenerin interfacePublisher<T>- Parameters:
listener- thePublisherListenerto add
-
signalOnMasterRegistrationSuccess
public void signalOnMasterRegistrationSuccess()Signal allPublisherListeners that thePublisherhas successfully registered with the master.Each listener is called in a separate thread.
- Specified by:
signalOnMasterRegistrationSuccessin classDefaultTopicParticipant
-
signalOnMasterRegistrationFailure
public void signalOnMasterRegistrationFailure()Signal allPublisherListeners that thePublisherhas failed to register with the master.Each listener is called in a separate thread.
- Specified by:
signalOnMasterRegistrationFailurein classDefaultTopicParticipant
-
signalOnMasterUnregistrationSuccess
public void signalOnMasterUnregistrationSuccess()Signal allPublisherListeners that thePublisherhas successfully unregistered with the master.Each listener is called in a separate thread.
- Specified by:
signalOnMasterUnregistrationSuccessin classDefaultTopicParticipant
-
signalOnMasterUnregistrationFailure
public void signalOnMasterUnregistrationFailure()Signal allPublisherListeners that thePublisherhas failed to unregister with the master.Each listener is called in a separate thread.
- Specified by:
signalOnMasterUnregistrationFailurein classDefaultTopicParticipant
-
toString
-