Class AnnotatedEventHandler

java.lang.Object
dk.cloudcreate.essentials.reactive.AnnotatedEventHandler
All Implemented Interfaces:
EventHandler

public class AnnotatedEventHandler extends Object implements EventHandler
Extending this class will allow you to colocate multiple related Event handling methods inside the same class and use it together with the LocalEventBus
Each method must accept a single Event argument, return void and be annotated with the Handler annotation.
The method argument type is matched against the concrete event type using Class.isAssignableFrom(Class).
The method accessibility can be any combination of private, protected, public, etc.
Example:

 public class OrderEventsHandler extends AnnotatedEventHandler {

     @EventHandler
     void handle(OrderCreated event) {
     }

     @EventHandler
     void handle(OrderCancelled event) {
     }
 }

Example of registering the AnnotatedEventHandler with the LocalEventBus:

 LocalEventBus localEventBus    = new LocalEventBus("TestBus", 3, (failingSubscriber, event, exception) -> log.error("...."));
 localEventBus.addAsyncSubscriber(new OrderEventsHandler(...));
 localEventBus.addSyncSubscriber(new OrderEventsHandler(...));
 
  • Constructor Details

    • AnnotatedEventHandler

      public AnnotatedEventHandler(Object invokeEventHandlerMethodsOn)
      Create an AnnotatedEventHandler that can resolve and invoke event handler methods, i.e. methods annotated with @Handler, on another object
      Parameters:
      invokeEventHandlerMethodsOn - the object that contains the @Handler annotated methods
    • AnnotatedEventHandler

      public AnnotatedEventHandler()
      Create an AnnotatedEventHandler that can resolve and invoke event handler methods, i.e. methods annotated with @Handler, on this concrete subclass of AnnotatedEventHandler
  • Method Details