Class NonBlockingFiniteStateMachine.CoalescedEvent<S extends Enum<S>>
- Type Parameters:
S- the type of the state for theFiniteStateMachine
- All Implemented Interfaces:
Event<S>,LifecycleAwareEvent<S>
- Enclosing class:
NonBlockingFiniteStateMachine<S extends Enum<S>>
NonBlockingFiniteStateMachine.CoalescedEvent is a LifecycleAwareEvent that
coalesces other (wrapped) Events with the same discriminator
so that only one Event actually executes.
For example: Given 10 Events submitted to a NonBlockingFiniteStateMachine with the same discriminator, only one
of the said Events will be processed. All others will be
discarded. Once the NonBlockingFiniteStateMachine.CoalescedEvent has been processed, a new
batch may be created when another NonBlockingFiniteStateMachine.CoalescedEvent of the same
discriminator is submitted.
The actual Event processed depends on the mode of coalescing
required. The first NonBlockingFiniteStateMachine.CoalescedEvent submitted to a NonBlockingFiniteStateMachine for a specific discriminator
effectively starts the coalescing of Events for the said
discriminator. When the mode is set to NonBlockingFiniteStateMachine.CoalescedEvent.Process.FIRST, then
the first Event (starting the coalescing) will be processed
and others will be discarded. When the mode is set of NonBlockingFiniteStateMachine.CoalescedEvent.Process.MOST_RECENT then the most recently submitted Event
will be processed and likewise, all others for the same discriminator
will be discarded.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classANonBlockingFiniteStateMachine.CoalescedEvent.Discriminatoris an object that is used to uniquely differentiate events to be coalesced, scoped by aNonBlockingFiniteStateMachine.static enumTheNonBlockingFiniteStateMachine.CoalescedEventto process. -
Constructor Summary
ConstructorsConstructorDescriptionCoalescedEvent(Event<S> event) Constructs aNonBlockingFiniteStateMachine.CoalescedEventof the specifiedEventtype usingNonBlockingFiniteStateMachine.CoalescedEvent.Process.FIRST.Constructs aNonBlockingFiniteStateMachine.CoalescedEventof the specifiedEventtype.CoalescedEvent(Event<S> event, NonBlockingFiniteStateMachine.CoalescedEvent.Process mode, Object discriminator) Constructs aNonBlockingFiniteStateMachine.CoalescedEventwith the specified discriminator andEvent. -
Method Summary
Modifier and TypeMethodDescriptiongetDesiredState(S state, ExecutionContext context) Determines the desired state of theFiniteStateMachinefor theEventgiven the current state of theFiniteStateMachine.booleanonAccept(ExecutionContext context) Called by aFiniteStateMachinewhen theLifecycleAwareEventis initially about to be accepted for processing.voidonProcessed(ExecutionContext context) Called by aFiniteStateMachinewhen theLifecycleAwareEventhas been processed.voidonProcessing(ExecutionContext context) Called by aFiniteStateMachinewhen theLifecycleAwareEventis about to be processed.toString()
-
Constructor Details
-
CoalescedEvent
Constructs aNonBlockingFiniteStateMachine.CoalescedEventof the specifiedEventtype usingNonBlockingFiniteStateMachine.CoalescedEvent.Process.FIRST.- Parameters:
event- theEventto be executed when coalesced
-
CoalescedEvent
Constructs aNonBlockingFiniteStateMachine.CoalescedEventof the specifiedEventtype.- Parameters:
event- theEventto be coalescedmode- whichNonBlockingFiniteStateMachine.CoalescedEvents to process
-
CoalescedEvent
public CoalescedEvent(Event<S> event, NonBlockingFiniteStateMachine.CoalescedEvent.Process mode, Object discriminator) Constructs aNonBlockingFiniteStateMachine.CoalescedEventwith the specified discriminator andEvent.- Parameters:
event- theEventto be coalescedmode- whichNonBlockingFiniteStateMachine.CoalescedEvents to processdiscriminator- the descriminator used to uniquely coalesce theEvent
-
-
Method Details
-
getDesiredState
Determines the desired state of theFiniteStateMachinefor theEventgiven the current state of theFiniteStateMachine.- Specified by:
getDesiredStatein interfaceEvent<S extends Enum<S>>- Parameters:
state- the current state of theFiniteStateMachinecontext- theExecutionContextfor theEvent- Returns:
- the desired state of the
FiniteStateMachineornullif no transition is required
-
onAccept
Called by aFiniteStateMachinewhen theLifecycleAwareEventis initially about to be accepted for processing.- Specified by:
onAcceptin interfaceLifecycleAwareEvent<S extends Enum<S>>- Parameters:
context- theExecutionContextfor theEvent- Returns:
trueif theEventshould be accepted, orfalseif theFiniteStateMachineshould ignore theLifecycleAwareEvent
-
onProcessed
Called by aFiniteStateMachinewhen theLifecycleAwareEventhas been processed.- Specified by:
onProcessedin interfaceLifecycleAwareEvent<S extends Enum<S>>- Parameters:
context- theExecutionContextfor theEvent
-
onProcessing
Called by aFiniteStateMachinewhen theLifecycleAwareEventis about to be processed.- Specified by:
onProcessingin interfaceLifecycleAwareEvent<S extends Enum<S>>- Parameters:
context- theExecutionContextfor theEvent
-
toString
-