Annotation Interface EventHandler


@Retention(RUNTIME) @Target(METHOD) public @interface EventHandler
Marks a method within a bean as an event handler. Methods annotated with @EventHandler will be registered to receive events that match the type of their first parameter. The event dispatching mechanism will look for public methods with this annotation and a single parameter (the event object).
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    Defines the priority of the event handler.
    Optional type parameter filter for generic events.
  • Element Details

    • priority

      int priority
      Defines the priority of the event handler. Handlers with higher priority values (e.g., 100) are generally executed before handlers with lower priority values (e.g., 1). The default priority is 0. The exact behavior of priority-based ordering can depend on the event bus implementation.
      Returns:
      the priority of the event handler.
      Default:
      0
    • typeParameter

      Class<?> typeParameter
      Optional type parameter filter for generic events. When set, the handler will only receive events where the generic type parameter of the event (if the event is a GenericEvent or similar construct) matches this specified class. For example, for events like Event<String> or Event<Integer>, this setting allows the handler to specify it's only interested in String.class as the generic type.

      If the event is not generic or if this is set to void.class (the default), this filter is not applied based on the generic type parameter.

      Returns:
      the class of the generic type parameter to filter on, or void.class if no specific filtering by the generic type is needed.
      Default:
      void.class