net.metanotion.util.observers
Class ConcurrentObserverManager<O,M extends Message<O>>

java.lang.Object
  extended by net.metanotion.util.observers.ConcurrentObserverManager<O,M>
All Implemented Interfaces:
java.lang.Runnable, ObserverManager<O,M>

public final class ConcurrentObserverManager<O,M extends Message<O>>
extends java.lang.Object
implements ObserverManager<O,M>, java.lang.Runnable

An ObserverManager that uses an ExecutorService for concurrent, asynchronous dispatching of events.


Constructor Summary
ConcurrentObserverManager(java.util.concurrent.ExecutorService es)
          This is equivalent to ConcurrentObserverManager(es, -1)
ConcurrentObserverManager(java.util.concurrent.ExecutorService es, int failureCountMax)
           
 
Method Summary
 boolean add(O observer)
          Register an Observer as a listener.
protected  void increment(O observer)
           
 boolean remove(O observer)
          Remove an Observer as a listener.
 void run()
           
 boolean send(M m)
          Broadcast a message to all registered observers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConcurrentObserverManager

public ConcurrentObserverManager(java.util.concurrent.ExecutorService es)
This is equivalent to ConcurrentObserverManager(es, -1)


ConcurrentObserverManager

public ConcurrentObserverManager(java.util.concurrent.ExecutorService es,
                                 int failureCountMax)
Parameters:
es - Thread pool to submit concurrent processing requests to.
failureCountMax - Max exceptions allowed before an observer is ejected from the pool, -1 implies never.
Method Detail

increment

protected void increment(O observer)

add

public boolean add(O observer)
Description copied from interface: ObserverManager
Register an Observer as a listener.

Specified by:
add in interface ObserverManager<O,M extends Message<O>>
Parameters:
observer - Observer to start receiving messages.
Returns:
True if the observer was successfully registered, false otherwise.

remove

public boolean remove(O observer)
Description copied from interface: ObserverManager
Remove an Observer as a listener.

Specified by:
remove in interface ObserverManager<O,M extends Message<O>>
Parameters:
observer - Observer to remove
Returns:
True if the observer was successfully removed, false otherwise.

send

public boolean send(M m)
Description copied from interface: ObserverManager
Broadcast a message to all registered observers.

Specified by:
send in interface ObserverManager<O,M extends Message<O>>
Parameters:
m - Message to send to observers.
Returns:
True if the message was queued, false otherwise

run

public void run()
Specified by:
run in interface java.lang.Runnable