Interface EventsNotifier<T>

All Known Implementing Classes:
EventsManager

public interface EventsNotifier<T>
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    action​(BeforeEvent<T> event, Runnable actionFunc)
    Embed action between events: "before" and "after".
    default <R> R
    action​(BeforeEvent<T> event, Supplier<R> actionFunc)
    Embed action between events: "before" and "after".
    default void
    action​(String name, Runnable actionFunc)
    Shorthand for action with null context and no params
    default <R> R
    action​(String name, Supplier<R> actionFunc)
    Shorthand for action with null context and no params
    void
    Notify all event listeners about ended event.
    void
    Notify all event listeners about failed event.
  • Method Details

    • notifyBefore

      void notifyBefore(BeforeEvent<T> e)
      Notify all event listeners about failed event.
      
       manager.notifyBefore(new BeforeEvent<>(null, "someAction"));
       // do someAction()
       
    • notifyAfter

      void notifyAfter(AfterEvent<T> e)
      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

      default void action(String name, Runnable actionFunc)
      Shorthand for action with null context and no params
    • action

      default <R> R action(String name, Supplier<R> actionFunc)
      Shorthand for action with null context and no params
    • action

      default void action(BeforeEvent<T> event, Runnable actionFunc)
      Embed action between events: "before" and "after". see action(BeforeEvent, Supplier) for more details / examples.
    • action

      default <R> R action(BeforeEvent<T> event, Supplier<R> actionFunc)
      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