S - The type of the ListenerStore this provider uses.public class ParallelEventProvider<S extends ListenerStore> extends AbstractEventProvider<S> implements ExecutorAware
ExecutorService to notify
each listener within a dedicated thread. This implementation is thereby
not sequential.
Instances of this class can be obtained using the static factory methods of
the EventProvider interface.
defaultHandler, exceptionHandler| Constructor and Description |
|---|
ParallelEventProvider(S store)
Creates a new ParallelEventProvider using the provided store.
|
ParallelEventProvider(S store,
ExecutorService executor)
Creates a new ParallelEventPRovider.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canDispatch()
Gets whether this EventProvider is ready for dispatching.
|
void |
close()
Closes this EventProvider and its
ListenerStore (thus, removes
all registered Listeners from the store). |
<L extends Listener,E extends Event<?,L>> |
dispatch(E event,
BiConsumer<L,E> bc,
ExceptionCallback ec)
Notifies all listeners of a certain kind about an occurred event with
explicit error handling.
|
protected boolean |
isImplementationSequential()
Whether this EventProvider implementation is sequential.
|
void |
setExecutorService(ExecutorService executor)
Sets the
ExecutorService to use. |
checkDispatchArgs, createInvocation, dispatch, dispatch, isSequential, listeners, notifyListeners, notifySingle, setExceptionCallback, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitconfigure, createDefault, dispatch, dispatch, dispatchpublic ParallelEventProvider(S store)
store - Responsible for storing and retrieving listeners of this
provider.public ParallelEventProvider(S store, ExecutorService executor)
store - Responsible for storing and retrieving listeners of this
provider.executor - The executor to use.public void setExecutorService(ExecutorService executor)
ExecutorAwareExecutorService to use.setExecutorService in interface ExecutorAwareexecutor - The executor service.public <L extends Listener,E extends Event<?,L>> void dispatch(E event, BiConsumer<L,E> bc, ExceptionCallback ec)
EventProviderEventProvider.canDispatch(), this method returns immediately
without doing anything. This method will stop notifying further listeners
if the passed event has been marked 'handled' using
Event.setHandled(boolean).
Consider an UserListener interface:
public interface UserListener extends Listener {
public void userAdded(UserEvent e);
public void userDeleted(UserEvent e);
}
Notifying all registered UserListeners about an added user is as easy as
calling
final ExceptionCallback callBack = new EceptionCallback() { ... };
eventProvider.dispatchEvent(event, UserListener::userAdded, callBack);
The ExceptionCallback gets notified when any of the listeners
throws an unexpected exception. If the exception handler itself throws an
exception, it will be ignored. The callback provided to this method takes
precedence over the global callback provided by
EventProvider.setExceptionCallback(ExceptionCallback).
Note on concurrency: This method operates on a copy of the list of targeted listeners. This allows you to add/remove listeners from within a listening method.
Please note that neither parameter to this method must be null.
dispatch in interface EventProvider<S extends ListenerStore>dispatch in class AbstractEventProvider<S extends ListenerStore>L - Type of the listeners which will be notified.E - Type of the event which will be passed to a listener.event - The occurred event which shall be passed to each listener.bc - Function to delegate the event to the specific callback method
of the listener.ec - Callback to be notified when any of the listeners throws an
exception.public boolean canDispatch()
EventProvidercanDispatch in interface EventProvider<S extends ListenerStore>dispatchpublic void close()
EventProviderListenerStore (thus, removes
all registered Listeners from the store). Depending on the actual
implementation, the EventProvider might not be able to dispatch further
events after closing. On some implementations closing might have no
additional effect.close in interface EventProvider<S extends ListenerStore>close in class AbstractEventProvider<S extends ListenerStore>protected boolean isImplementationSequential()
AbstractEventProviderAbstractEventProvider.isSequential() method considers the result of this method and
the result of the current ListenerStore's
isSequential method for determining
whether dispatch events of this provider are sequential.isImplementationSequential in class AbstractEventProvider<S extends ListenerStore>Copyright © 2014–2015. All rights reserved.