Class AbstractObservable<O,EV>

java.lang.Object
org.refcodes.observer.AbstractObservable<O,EV>
Type Parameters:
O - The observer's (event listeners) to be managed by the Observable.
EV - The base event to be fired by this Observable.
All Implemented Interfaces:
org.refcodes.mixin.Disposable, Observable<O>

public abstract class AbstractObservable<O,EV> extends Object implements Observable<O>, org.refcodes.mixin.Disposable
This abstract class provides functionality to implement default refcodes Observable behavior. The fireEvent(Object, Object, ExecutionStrategy) is to be overwritten to invoke the according event lister'#s method for a given event to be distributed. The doHandleEventListenerException(Exception, Object, Object, ExecutionStrategy) method can be overwritten to handle any exceptions thrown by the fireEvent(Object, Object, ExecutionStrategy) method. Depending on the ExecutionStrategy, distribution of the events is handled differently: ExecutionStrategy.SEQUENTIAL: You determine that each event listener is signaled one after the other and not in parallel. In case you want to restrict thread generation, this sequential event distribution is the one to go for: Each event listener is invoked after the other one after the other. The execution chain of invoking the event listeners can be aborted by a boolean flag returned by an invoked event listener method or by a VetoException thrown by an invoked event listener method. In sequential event distribution, you can also take care of exceptions thrown or return vales passed to you by the event listeners to affect the execution of the chain of event listeners. As soon as the execution chain of invoking event listeners terminates, then this method terminates. ExecutionStrategy.PARALLEL: You determine that each event listener is signaled in parallel. In case you want to prevent that one event listener can cause the succeeding event listeners to be delayed for signaling, then the parallel mode is the one to go for. As soon as all event listeners have their own thread, this method exits. You cannot affect the execution of event listeners as all of them are invoked ignoring any exceptions or return values of the other invoked event listeners. Here as we do not collect any exceptions or any results from each invoked event listener, there are no means provided to evaluate them during or after event distribution. ExecutionStrategy.JOIN: Similar to ExecutionStrategy.PARALLEL with the difference, that all threads are joined and the method terminates as soon as the latest thread terminates. As of this, a VetoException as well as a return value can be evaluated though still no influence can be taken upon the execution of the invocation of the event listeners. In case any of the listeners returns false, then this event distribution mode will cause to return false, in case any event listener throws a VetoException, then the first detected VetoException is thrown when executing with this event distribution mode. No matter of the exceptions or return values, as of the ExecutionStrategy.PARALLEL event distribution mode, all event listeners are invoked.