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

java.lang.Object
  extended by org.ros.internal.node.CountDownRegistrantListener<Subscriber<T>>
      extended by org.ros.node.topic.CountDownSubscriberListener<T>
All Implemented Interfaces:
RegistrantListener<Subscriber<T>>, SubscriberListener<T>

public class CountDownSubscriberListener<T>
extends CountDownRegistrantListener<Subscriber<T>>
implements SubscriberListener<T>

A SubscriberListener which uses separate CountDownLatch instances for all messages.


Method Summary
 void awaitNewPublisher()
          Wait for the requested number of new publishers.
 boolean awaitNewPublisher(long timeout, java.util.concurrent.TimeUnit unit)
          Wait for the requested number of new publishers within the given time period.
 void awaitShutdown()
          Wait for shutdown.
 boolean awaitShutdown(long timeout, java.util.concurrent.TimeUnit unit)
          Wait for shutdown within the given time period.
static
<T> CountDownSubscriberListener<T>
newDefault()
          Construct a CountDownSubscriberListener with all counts set to 1.
static
<T> CountDownSubscriberListener<T>
newFromCounts(int masterRegistrationSuccessCount, int masterRegistrationFailureCount, int masterUnregistrationSuccessCount, int masterUnregistrationFailureCount, int newSubscriberCount)
           
 void onNewPublisher(Subscriber<T> subscriber, PublisherIdentifier publisherIdentifier)
          A new Publisher has connected to the Subscriber.
 void onShutdown(Subscriber<T> subscriber)
          The Subscriber 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> CountDownSubscriberListener<T> newDefault()
Construct a CountDownSubscriberListener with all counts set to 1.


newFromCounts

public static <T> CountDownSubscriberListener<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 counts to wait for for a new publisher

onNewPublisher

public void onNewPublisher(Subscriber<T> subscriber,
                           PublisherIdentifier publisherIdentifier)
Description copied from interface: SubscriberListener
A new Publisher has connected to the Subscriber.

Specified by:
onNewPublisher in interface SubscriberListener<T>
Parameters:
subscriber - the Subscriber that the Publisher connected to
publisherIdentifier - the PublisherIdentifier of the new Publisher

onShutdown

public void onShutdown(Subscriber<T> subscriber)
Description copied from interface: SubscriberListener
The Subscriber has been shut down.

Specified by:
onShutdown in interface SubscriberListener<T>
Parameters:
subscriber - the Subscriber that was shut down

awaitNewPublisher

public void awaitNewPublisher()
                       throws java.lang.InterruptedException
Wait for the requested number of new publishers.

Throws:
java.lang.InterruptedException

awaitNewPublisher

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

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

awaitShutdown

public void awaitShutdown()
                   throws java.lang.InterruptedException
Wait 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 time unit of the timeout argument
Returns:
true if the shutdowns happened within the time period, false otherwise
Throws:
java.lang.InterruptedException