Class EventBase<T>
- Type Parameters:
T- the result type of the event. UseVoidif handling the event does not produce a result
- All Implemented Interfaces:
Future<T>,Associator,Eligible
- Direct Known Subclasses:
Event
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanSet when the event has been completed.The events to be fired upon completion.protected ChannelTemporarily set when invoking a handler, only to be used byhandlingError(EventPipeline, Throwable). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddCompletionEvent(Event<?> completionEvent) Adds the given event to the events to be thrown when this event has completed (seeFuture.isDone()).abstract Channel[]channels()SeeEvent.channels().Disables tracking for this event and all events generated when handling it.protected booleanenqueued()Returnstrueif the event has been enqueued in a pipeline.protected voidprotected abstract voidhandled()SeeEvent.handled().protected abstract voidhandlingError(EventPipeline eventProcessor, Throwable throwable) Invoked when an exception occurs while invoking a handler for an event.abstract booleanSeeEvent.isStopped().booleanWhether the event (and all events generated when handling it) is tracked.static <T,E extends Event<T>>
EonCompletion(E event, Consumer<E> consumer) Invokes the consumer when the event is completed.voidResume the invocation of handlers for this event.setRequiresResult(boolean value) voidSuspend the invocation of the remaining handlers for this event.voidsuspendHandling(Runnable whenResumed) Suspend the invocation of the remaining handlers for this event.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jgrapes.core.Associator
associated, associated, associated, associated, associatedGet, setAssociatedMethods inherited from interface org.jgrapes.core.Eligible
defaultCriterion, isEligibleForMethods inherited from interface java.util.concurrent.Future
cancel, exceptionNow, get, get, isCancelled, isDone, resultNow, state
-
Field Details
-
completionEvents
The events to be fired upon completion.Using this attribute provides a slightly faster access than invoking
Event.completionEvents(), which wraps the result in an unmodifiable set. -
invokedFor
Temporarily set when invoking a handler, only to be used byhandlingError(EventPipeline, Throwable). -
completed
Set when the event has been completed.
-
-
Constructor Details
-
EventBase
public EventBase()
-
-
Method Details
-
channels
SeeEvent.channels().- Returns:
- the channel[]
-
handled
SeeEvent.handled(). -
isStopped
SeeEvent.isStopped(). -
currentResults
-
setRequiresResult
-
firstResultAssigned
-
enqueued
Returnstrueif the event has been enqueued in a pipeline.- Returns:
- the result
-
handlingError
Invoked when an exception occurs while invoking a handler for an event.- Parameters:
eventProcessor- the manager that has invoked the handlerthrowable- the exception that has been thrown by the handler
-
processedBy
-
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
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
Resume the invocation of handlers for this event.- See Also:
-
disableTracking
Disables tracking for this event and all events generated when handling it. -
isTracked
Whether the event (and all events generated when handling it) is tracked.- Returns:
trueif event is tracked
-
addCompletionEvent
Adds the given event to the events to be thrown when this event has completed (seeFuture.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
EventProcessoras the event that has been completed.- Parameters:
completionEvent- the completion event to add- Returns:
- the object for easy chaining
- See Also:
-
onCompletion
Invokes the consumer when the event is completed.This is a shortcut for registering a
CompletionEventand 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 eventE- the type of the event- Parameters:
event- the eventconsumer- the consumer- Returns:
- the event
-