org.ros.node.topic
Class CountDownPublisherListener<T>

java.lang.Object
  extended by org.ros.internal.node.CountDownRegistrantListener<Publisher<T>>
      extended by org.ros.node.topic.CountDownPublisherListener<T>
All Implemented Interfaces:
RegistrantListener<Publisher<T>>, PublisherListener<T>

public class CountDownPublisherListener<T>
extends CountDownRegistrantListener<Publisher<T>>
implements PublisherListener<T>

A PublisherListener which uses separate CountDownLatch instances for all signals.


Method Summary
 void awaitNewSubscriber()
          Wait for the requested number of shutdowns.
 boolean awaitNewSubscriber(long timeout, java.util.concurrent.TimeUnit unit)
          Wait for the requested number of new subscribers within the given time period.
 void awaitShutdown()
          Wait for for shutdown.
 boolean awaitShutdown(long timeout, java.util.concurrent.TimeUnit unit)
          Wait for shutdown within the given time period.
static
<T> CountDownPublisherListener<T>
newDefault()
           
static
<T> CountDownPublisherListener<T>
newFromCounts(int masterRegistrationSuccessCount, int masterRegistrationFailureCount, int masterUnregistrationSuccessCount, int masterUnregistrationFailureCount, int newSubscriberCount)
           
 void onNewSubscriber(Publisher<T> publisher, SubscriberIdentifier subscriberIdentifier)
          A Subscriber has connected to the Publisher.
 void onShutdown(Publisher<T> publisher)
          The Publisher has been shut down.
 
Methods inherited from class org.ros.internal.node.CountDownRegistrantListener
awaitMasterRegistrationFailure, awaitMasterRegistrationFailure, awaitMasterRegistrationSuccess, awaitMasterRegistrationSuccess, awaitMasterUnregistrationFailure, awaitMasterUnregistrationFailure, awaitMasterUnregistrationSuccess, awaitMasterUnregistrationSuccess, onMasterRegistrationFailure, onMasterRegistrationSuccess, onMasterUnregistrationFailure, onMasterUnregistrationSuccess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.ros.internal.node.RegistrantListener
onMasterRegistrationFailure, onMasterRegistrationSuccess, onMasterUnregistrationFailure, onMasterUnregistrationSuccess
 

Method Detail

newDefault

public static <T> CountDownPublisherListener<T> newDefault()

newFromCounts

public static <T> CountDownPublisherListener<T> newFromCounts(int masterRegistrationSuccessCount,
                                                              int masterRegistrationFailureCount,
                                                              int masterUnregistrationSuccessCount,
                                                              int masterUnregistrationFailureCount,
                                                              int newSubscriberCount)
Parameters:
masterRegistrationSuccessCount - the number of successful master registrations to wait for
masterRegistrationFailureCount - the number of failing master registrations to wait for
masterUnregistrationSuccessCount - the number of successful master unregistrations to wait for
masterUnregistrationFailureCount - the number of failing master unregistrations to wait for
newSubscriberCount - the number of new subscribers to wait for

onNewSubscriber

public void onNewSubscriber(Publisher<T> publisher,
                            SubscriberIdentifier subscriberIdentifier)
Description copied from interface: PublisherListener
A Subscriber has connected to the Publisher.

Specified by:
onNewSubscriber in interface PublisherListener<T>
Parameters:
publisher - the Publisher that the Subscriber connected to
subscriberIdentifier - the SubscriberIdentifier of the new Subscriber

onShutdown

public void onShutdown(Publisher<T> publisher)
Description copied from interface: PublisherListener
The Publisher has been shut down.

Specified by:
onShutdown in interface PublisherListener<T>
Parameters:
publisher - the Publisher that was shut down

awaitNewSubscriber

public void awaitNewSubscriber()
                        throws java.lang.InterruptedException
Wait for the requested number of shutdowns.

Throws:
java.lang.InterruptedException

awaitNewSubscriber

public boolean awaitNewSubscriber(long timeout,
                                  java.util.concurrent.TimeUnit unit)
                           throws java.lang.InterruptedException
Wait for the requested number of new subscribers within the given time period.

Parameters:
timeout - the maximum time to wait
unit - the TimeUnit of the timeout argument
Returns:
true if the requested number of new subscribers connect within the time period false otherwise.
Throws:
java.lang.InterruptedException

awaitShutdown

public void awaitShutdown()
                   throws java.lang.InterruptedException
Wait for for shutdown.

Throws:
java.lang.InterruptedException

awaitShutdown

public boolean awaitShutdown(long timeout,
                             java.util.concurrent.TimeUnit unit)
                      throws java.lang.InterruptedException
Wait for shutdown within the given time period.

Parameters:
timeout - the maximum time to wait
unit - the TimeUnit of the timeout argument
Returns:
true if shutdown happened within the time period, false otherwise
Throws:
java.lang.InterruptedException