Interface EventListener
public interface EventListener
Event listeners are
Event
consumers. E.g. a listener can send email with notification or
dump the event to an auditing database.- Author:
- K. Benedyczak
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetId()
int
boolean
handleEvent
(Event event) Called only on events of a proper category, for which isWanted returned true.default void
init()
Called beforeEventListener
is being added toEventProcessor
boolean
This method should return whether async processing is allowed.boolean
boolean
This method should perform a fast filtering of uninteresting events.
-
Field Details
-
DEFAULT_MAX_FAILURES
static final int DEFAULT_MAX_FAILURES- See Also:
-
-
Method Details
-
isLightweight
boolean isLightweight()- Returns:
- if true is returned then the listener's handle method will be invoked without persisting the event into database first. Therefore it is assumed that handler is going to perform an operation which nearly always succeeds. Otherwise the event is stored in DB first and if the handle method fails or throws an exception then the handling will be repeated after some time.
-
isWanted
This method should perform a fast filtering of uninteresting events.- Returns:
- true if the event should be handled by this listener
-
isAsync
This method should return whether async processing is allowed. Otherwise processing is done immediately.- Returns:
- true if the event should be handled in async mode.
-
handleEvent
Called only on events of a proper category, for which isWanted returned true.- Parameters:
event
-- Returns:
- true if the event was processed successfully. Returning false is relevant only for the heavy-weight listeners.
-
getId
String getId()- Returns:
- system unique and constant ID of the listener instance. It is suggested to form it from the full class name concatenated with listener name if it can have many instances.
-
getMaxFailures
int getMaxFailures()- Returns:
- after how many failures the system should give up sending the event. It is suggested
to return
DEFAULT_MAX_FAILURES
-
init
default void init()Called beforeEventListener
is being added toEventProcessor
-