Package dev.comfast.events
Interface EventsNotifier<T>
- All Known Implementing Classes:
EventsManager
public interface EventsNotifier<T>
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidaction(BeforeEvent<T> event, Runnable actionFunc)Embed action between events: "before" and "after".default <R> Raction(BeforeEvent<T> event, Supplier<R> actionFunc)Embed action between events: "before" and "after".default voidShorthand for action with null context and no paramsdefault <R> RShorthand for action with null context and no paramsvoidnotifyAfter(AfterEvent<T> e)Notify all event listeners about ended event.voidnotifyBefore(BeforeEvent<T> e)Notify all event listeners about failed event.
-
Method Details
-
notifyBefore
Notify all event listeners about failed event.manager.notifyBefore(new BeforeEvent<>(null, "someAction")); // do someAction() -
notifyAfter
Notify all event listeners about ended event.var beforeEvent = new BeforeEvent<>(null, "someAction"); manager.notifyBefore(beforeEvent); var someResult = someAction(); manager.notifyAfter(beforeEvent.passed(someResult)); -
action
Shorthand for action with null context and no params -
action
Shorthand for action with null context and no params -
action
Embed action between events: "before" and "after". seeaction(BeforeEvent, Supplier)for more details / examples. -
action
Embed action between events: "before" and "after".Capture action result/Exception to be available in AfterEvent
e.g.// During this code all notifiers will be called: // notifyBefore(event) // <<run the action>> // notifyAfter(event) // or // notifyAfter(eventWithError) String context = null; // context is optional, will be available in listener by call event.context... String someParam = "abc"; //params are optional, only for additional information var actionResult = myManager.action(new BeforeEvent<>(context, "myAction", someParam), () -> { //do my action //can use someParam as well return "hello"; }) print(actionResult); // -> hello- Type Parameters:
R- type of action result- Parameters:
event- new instance of BeforeEvent. Create it just before action call.actionFunc- action to call- Returns:
- action result
-