org.ros.concurrent
Class ListenerCollection<T>

java.lang.Object
  extended by org.ros.concurrent.ListenerCollection<T>

public class ListenerCollection<T>
extends java.lang.Object

Manages a collection of listeners and makes it easy to execute a listener callback on the entire collection.


Nested Class Summary
static interface ListenerCollection.SignalRunnable<U>
           
 
Constructor Summary
ListenerCollection(java.util.Collection<T> listeners, java.util.concurrent.ExecutorService executorService)
           
ListenerCollection(java.util.concurrent.ExecutorService executorService)
           
 
Method Summary
 void add(T listener)
           
 void addAll(java.util.Collection<T> listeners)
           
 void clear()
          Removes all listeners from the collection.
 boolean remove(T listener)
           
 void signal(ListenerCollection.SignalRunnable<T> signalRunnable)
          Signal all listeners.
 void signal(ListenerCollection.SignalRunnable<T> signalRunnable, long timeout, java.util.concurrent.TimeUnit unit)
          Signal all listeners and wait for the all ListenerCollection.SignalRunnables to return.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListenerCollection

public ListenerCollection(java.util.concurrent.ExecutorService executorService)
Parameters:
executorService - the ScheduledExecutorService to use when executing listener callbacks

ListenerCollection

public ListenerCollection(java.util.Collection<T> listeners,
                          java.util.concurrent.ExecutorService executorService)
Parameters:
listeners - an initial Collection of listeners to add
executorService - the ExecutorService to use when executing listener callbacks
Method Detail

add

public void add(T listener)
Parameters:
listener - the listener to add

addAll

public void addAll(java.util.Collection<T> listeners)
Parameters:
listeners - a Collection of listeners to add

remove

public boolean remove(T listener)
Parameters:
listener - the listener to remove
Returns:
true if the listener was removed, false otherwise

clear

public void clear()
Removes all listeners from the collection.


size

public int size()
Returns:
the number of listeners in the collection

signal

public void signal(ListenerCollection.SignalRunnable<T> signalRunnable)
Signal all listeners.

Each ListenerCollection.SignalRunnable is executed in a separate thread.


signal

public void signal(ListenerCollection.SignalRunnable<T> signalRunnable,
                   long timeout,
                   java.util.concurrent.TimeUnit unit)
            throws java.lang.InterruptedException
Signal all listeners and wait for the all ListenerCollection.SignalRunnables to return.

Each ListenerCollection.SignalRunnable is executed in a separate thread.

Throws:
java.lang.InterruptedException