Class GenericEvent<O>

java.lang.Object
overit.geocall.bl.GenericEvent<O>
Type Parameters:
O - the type of the object contained into the output journal
Direct Known Subclasses:
BusinessEvent, SystemEvent

public abstract class GenericEvent<O> extends Object
The root class from which all event objects shall be derived. All Events are constructed with a reference to the input and a journal of output, that is logically deemed to be the object that contains the list of the output snapshots modified through side effect by the BusinessTask.
GCApi:
event
No Reactors
No Spouts
  • Field Details

  • Constructor Details

    • GenericEvent

      public GenericEvent()
  • Method Details

    • register

      public static <O> void register(Class c)
      Utility method that can be used to register a task to an event.In this way, when the event will be launched the BusinessTask.body(Object, PoolKit) task's method will be called. The order depends on the number on the order param (lower number will be called first)
      Type Parameters:
      O - the type of the object contained into the output journal
      Parameters:
      c - class of the event on which to register
    • getSpouts

      public List<String> getSpouts()
      Returns the list of spout names associated with the current event, or an empty list if no spouts are associated.
      Returns:
      the list of spout names associated with the current event, or an empty list if no spouts are associated.
    • isInternal

      public boolean isInternal()
      Determines if this event should be handled internally only (not published externally). Subclasses can override this method to specify whether the event should be published to external spouts.
      Returns:
      true if the event should be handled internally only; false if it should be published externally. Default implementation returns false.
    • registerSpouts

      public static void registerSpouts(Class<?> c)
      Utility method that can be used to register a stub to an event.
      Parameters:
      c - class of the event on which to register
    • clearEvents

      public static void clearEvents()
      Utility method that unregister all the previous registered events. This method is called during the startup process and should never be called anymore.
    • getJournal

      public Journal<O> getJournal()
      The journal containing the event outputs.
      Returns:
      The journal containing the event outputs.
    • getStreamJournal

      public Journal<SpoutResult> getStreamJournal()
      The journal containing the SpoutResult produced by the event streaming phase.
      Returns:
      The journal containing the SpoutResult produced by the event streaming phase.
    • launch

      public O launch() throws DAValidateException, DAException
      Launch the event using the identity that will be passed to the registered tasks. This method will use a new database connection, therefore if you have another PoolKit yet, please use the launch(PoolKit) instead.
      Returns:
      The journal containing the event outputs.
      Throws:
      DAValidateException - in case of database validation error
      DAException - in case of database error
    • launchAsync

      public Future<O> launchAsync()

      Launch the event asynchronously providing the current identity to the registered tasks.

      This method will use a new database connection, therefore if you have another PoolKit yet, please use the launchAsync(PoolKit) instead.

      Returns a Future through which to get the journal containing the pending results of the task.
      Returns:
      a Future through which to get the journal containing the pending results of the task.
    • launchAsync

      public Future<O> launchAsync(PoolKit pk)

      Launch the event asynchronously providing the current identity to the registered tasks.

      This method will use the provided database connection (PoolKit).

      Returns a Future through which to get the journal containing the pending results of the event.
      Parameters:
      pk - The PoolKit used to connect to the database; it can't be null
      Returns:
      a Future through which to get the journal containing the pending results of the event.
    • launch

      public O launch(PoolKit pk) throws DAValidateException, DAException
      Launch the event using the identity that will be passed to the registered tasks and get the object returned by the first event's handler. This method will re-use the PoolKit passed by argument, therefore this method doesn't open a brand new database connection.
      Parameters:
      pk - the poolkit containing the reference to the database connection that can be used
      Returns:
      the last event output before the interruption
      Throws:
      DAValidateException - in case of database validation error
      DAException - in case of database error
    • getResult

      public O getResult()
      Returns the event result, taken from the Journal, as defined via the method defineResult() (defaults to the last object added to the journal).
      Returns:
      the event result
    • doLaunch

      protected abstract void doLaunch(PoolKit pk, Predicate<Journal<O>> interruptor) throws DAValidateException, DAException
      Throws:
      DAValidateException
      DAException
    • defineResult

      protected Function<Journal<O>,O> defineResult()
      Function used to define which Object should be considered as the event result from the ones contained into the Journal. By default the last object added to the journal will be considered as the result.
      Returns:
      the function used to define which Object should be considered as the event result from the ones contained into the Journal.
    • defineInterruptor

      protected Predicate<Journal<O>> defineInterruptor()
      Predicate to define an interruption over the event binded tasks elaboration. By defaultthe seuqnence of tasks is not interrupted.
      Returns:
      the predicate used to decide if the elaboration sequence must be interrupted