Class AnnotatedEventHandler
java.lang.Object
dk.cloudcreate.essentials.reactive.AnnotatedEventHandler
- All Implemented Interfaces:
EventHandler
Extending this class will allow you to colocate multiple related Event handling methods inside the same class and use it together with the
Each method must accept a single Event argument, return void and be annotated with the
The method argument type is matched against the concrete event type using
The method accessibility can be any combination of private, protected, public, etc.
Example:
Example of registering the
LocalEventBusEach 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 Summary
ConstructorsConstructorDescriptionCreate anAnnotatedEventHandlerthat can resolve and invoke event handler methods, i.e. methods annotated with @Handler, on this concrete subclass ofAnnotatedEventHandlerAnnotatedEventHandler(Object invokeEventHandlerMethodsOn) Create anAnnotatedEventHandlerthat can resolve and invoke event handler methods, i.e. methods annotated with @Handler, on another object -
Method Summary
-
Constructor Details
-
AnnotatedEventHandler
Create anAnnotatedEventHandlerthat 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 anAnnotatedEventHandlerthat can resolve and invoke event handler methods, i.e. methods annotated with @Handler, on this concrete subclass ofAnnotatedEventHandler
-
-
Method Details
-
handle
- Specified by:
handlein interfaceEventHandler
-