Class Observer

java.lang.Object
org.gcube.common.events.impl.Observer

public class Observer extends Object
Used internally to wrap arbitrary objects subscribed as observers.
Author:
Fabio Simeoni, Luca Frosini (ISTI-CNR)
  • Method Details

    • observersFor

      public static List<Observer> observersFor(Object object, ExecutorService service)
      Creates observer wrappers for all @Observes methods in the given object.
      Parameters:
      object - the object containing observer methods
      service - the executor service for asynchronous execution
      Returns:
      list of observer wrappers
      Throws:
      IllegalArgumentException - if the object has no valid observer methods
    • kind

      public Observes.Kind kind()
      Returns the kind of this observer (critical, safe, or resilient).
      Returns:
      the observer kind
    • onEvent

      public void onEvent(Object event)
      Handles an event by either processing it immediately or accumulating it for delayed processing.
      Parameters:
      event - the event to handle
    • onEventImmediate

      public void onEventImmediate(Object event)
      Processes an event immediately by invoking the observer method.
      Parameters:
      event - the event to process
    • onEventDelayed

      public void onEventDelayed(Object event)
      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()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • observerMethodsOf

      public static List<Method> observerMethodsOf(Object o)
      Extracts all methods annotated with @Observes from the given object.
      Parameters:
      o - the object to analyze
      Returns:
      list of observer methods