S - The type of the ListenerStore this provider uses.public class SequentialEventProvider<S extends ListenerStore> extends AbstractEventProvider<S>
EventProvider implementation which is always ready for dispatching
and simply runs all listeners within the current thread.
Sometimes, during dispatching an Event of type X, it might happen that a
cascaded dispatch action for the same type, or for another type Y is
triggered. If you want to prevent cascaded events, you may register listener
classes to be prevented on the event to dispatch. For this purpose, instead
of extending Event, your events must extend SequentialEvent.
For example: public class UserEvent extends
SequentialEvent<UserManager, UserListener> ...
UserEvent e = new UserEvent(this, user); // While dispatching 'e', no UIRefreshEvents shall be dispatched. e.preventCascade(UIRefreshEvent.class); eventProvider.dispatch(e, UserListener::userAdded);
With SequentialEvent.preventCascade() comes a convenience method to
prevent cascaded events of the same type. During dispatch, all events which
have been suppressed using the prevention mechanism, are collected and can be
retrieved with SequentialEvent.getSuppressedEvents(). This allows
you to inspect or re-dispatch them afterwards:
UserEvent e = new UserEvent(this, user);
// While dispatching 'e', no UIRefreshEvents shall be dispatched.
e.preventCascade(UIRefreshEvent.class);
eventProvider.dispatch(e, UserListener::userAdded);
// Dispatch all suppressed UIRefreshEvents
e.getSuppressedEvents().stream()
.filter(suppressed -> suppressed.getListenerClass() == UIRefreshListener.class)
.forEach(suppressed -> suppressed.redispatch(eventProvider));
SequentialEventdefaultHandler, exceptionHandler| Constructor and Description |
|---|
SequentialEventProvider(S store)
Creates a new SynchronousEventProvider.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canDispatch()
Gets whether this EventProvider is ready for dispatching.
|
EventStack |
getEventStack()
Gets the current event stack.
|
protected boolean |
isImplementationSequential()
Whether this EventProvider implementation is sequential.
|
protected <L extends Listener,E extends Event<?,L>> |
notifyListeners(E event,
BiConsumer<L,E> bc,
ExceptionCallback ec)
Notifies all listeners registered for the provided class with the
provided event.
|
checkDispatchArgs, close, createInvocation, dispatch, dispatch, dispatch, isSequential, listeners, notifySingle, setExceptionCallback, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitconfigure, createDefault, dispatch, dispatch, dispatchpublic SequentialEventProvider(S store)
store - Responsible for storing and retrieving listeners of this
provider.protected <L extends Listener,E extends Event<?,L>> void notifyListeners(E event, BiConsumer<L,E> bc, ExceptionCallback ec)
AbstractEventProviderExceptionCallback.
This method does not check whether this provider is ready for dispatching and might thus throw an exception when trying to dispatch an event while the provider is not ready.
notifyListeners 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 event to pass to each listener.bc - The method of the listener to call.ec - The callback which gets notified about exceptions.public EventStack getEventStack()
public boolean canDispatch()
EventProviderdispatchprotected 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.