Package org.gcube.common.events.impl
Class Observer
java.lang.Object
org.gcube.common.events.impl.Observer
Used internally to wrap arbitrary objects subscribed as observers.
- Author:
- Fabio Simeoni, Luca Frosini (ISTI-CNR)
-
Method Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()org.gcube.common.events.impl.Keykey()Returns the key that identifies the event type and qualifiers this observer listens to.kind()Returns the kind of this observer (critical, safe, or resilient).Extracts all methods annotated with @Observes from the given object.observersFor(Object object, ExecutorService service) Creates observer wrappers for all @Observes methods in the given object.voidHandles an event by either processing it immediately or accumulating it for delayed processing.voidonEventDelayed(Object event) Accumulates an event for delayed processing according to the configured delay.voidonEventImmediate(Object event) Processes an event immediately by invoking the observer method.
-
Method Details
-
observersFor
Creates observer wrappers for all @Observes methods in the given object.- Parameters:
object- the object containing observer methodsservice- the executor service for asynchronous execution- Returns:
- list of observer wrappers
- Throws:
IllegalArgumentException- if the object has no valid observer methods
-
kind
Returns the kind of this observer (critical, safe, or resilient).- Returns:
- the observer kind
-
onEvent
Handles an event by either processing it immediately or accumulating it for delayed processing.- Parameters:
event- the event to handle
-
onEventImmediate
Processes an event immediately by invoking the observer method.- Parameters:
event- the event to process
-
onEventDelayed
Accumulates an event for delayed processing according to the configured delay. Events are collected and processed as a batch after the delay period.- Parameters:
event- the event to accumulate
-
key
public org.gcube.common.events.impl.Key key()Returns the key that identifies the event type and qualifiers this observer listens to.- Returns:
- the observer key
-
hashCode
public int hashCode() -
equals
-
observerMethodsOf
Extracts all methods annotated with @Observes from the given object.- Parameters:
o- the object to analyze- Returns:
- list of observer methods
-