Class EventBase<T>

java.lang.Object
org.jgrapes.core.internal.EventBase<T>
Type Parameters:
T - the result type of the event. Use Void if handling the event does not produce a result
All Implemented Interfaces:
Future<T>, Associator, Eligible
Direct Known Subclasses:
Event

public abstract class EventBase<T> extends Object implements Eligible, Future<T>, Associator
Provides the implementations of methods to class Event that need access to classes or methods that are visible in the implementation package only.

The class is not intended to be used as base class for any other class.

  • Field Details

  • Constructor Details

  • Method Details

    • channels

      public abstract Channel[] channels()
      Returns:
      the channel[]
    • handled

      protected abstract void handled()
    • isStopped

      public abstract boolean isStopped()
    • currentResults

      protected abstract List<T> currentResults()
    • setRequiresResult

      protected EventBase<T> setRequiresResult(boolean value)
    • firstResultAssigned

      protected void firstResultAssigned()
    • enqueued

      protected boolean enqueued()
      Returns true if the event has been enqueued in a pipeline.
      Returns:
      the result
    • handlingError

      protected abstract void handlingError(EventPipeline eventProcessor, Throwable throwable)
      Invoked when an exception occurs while invoking a handler for an event.
      Parameters:
      eventProcessor - the manager that has invoked the handler
      throwable - the exception that has been thrown by the handler
    • processedBy

    • suspendHandling

      public void suspendHandling()
      Suspend the invocation of the remaining handlers for this event.

      May only be called in a handler for the event. Must be balanced by an invocation of resumeHandling().

    • suspendHandling

      public void suspendHandling(Runnable whenResumed)
      Suspend the invocation of the remaining handlers for this event.

      May only be called in a handler for the event. Must be balanced by an invocation of resumeHandling().

      Parameters:
      whenResumed - some function to be executed when handling is resumed
    • resumeHandling

      public void resumeHandling()
      Resume the invocation of handlers for this event.
      See Also:
    • disableTracking

      public Event<T> disableTracking()
      Disables tracking for this event and all events generated when handling it.
    • isTracked

      public boolean isTracked()
      Whether the event (and all events generated when handling it) is tracked.
      Returns:
      true if event is tracked
    • addCompletionEvent

      public abstract Event<T> addCompletionEvent(Event<?> completionEvent)
      Adds the given event to the events to be thrown when this event has completed (see Future.isDone()).

      Such an event is called a “completion event”.

      Completion events are considered to be caused by the event that caused the completed event. If an event e1 caused an event e2 which has a completion event e2c, e1 is only put in state completed when e2c has been handled.

      Completion events are handled by the same EventProcessor as the event that has been completed.

      Parameters:
      completionEvent - the completion event to add
      Returns:
      the object for easy chaining
      See Also:
    • onCompletion

      public static <T, E extends Event<T>> E onCompletion(E event, Consumer<E> consumer)
      Invokes the consumer when the event is completed.

      This is a shortcut for registering a CompletionEvent and providing a handler for the completion event that invokes the consumer.

      The static form is required because otherwise the compiler cannot infer the type of the consumer’s argument.

      Type Parameters:
      T - the result type of the event
      E - the type of the event
      Parameters:
      event - the event
      consumer - the consumer
      Returns:
      the event