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) Event
s with the same discriminator
so that only one Event
actually executes.
For example: Given 10 Event
s submitted to a NonBlockingFiniteStateMachine
with the same discriminator, only one
of the said Event
s 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 Event
s 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
Modifier and TypeClassDescriptionstatic class
ANonBlockingFiniteStateMachine.CoalescedEvent.Discriminator
is an object that is used to uniquely differentiate events to be coalesced, scoped by aNonBlockingFiniteStateMachine
.static enum
TheNonBlockingFiniteStateMachine.CoalescedEvent
to process. -
Constructor Summary
ConstructorDescriptionCoalescedEvent
(Event<S> event) Constructs aNonBlockingFiniteStateMachine.CoalescedEvent
of the specifiedEvent
type usingNonBlockingFiniteStateMachine.CoalescedEvent.Process.FIRST
.Constructs aNonBlockingFiniteStateMachine.CoalescedEvent
of the specifiedEvent
type.CoalescedEvent
(Event<S> event, NonBlockingFiniteStateMachine.CoalescedEvent.Process mode, Object discriminator) Constructs aNonBlockingFiniteStateMachine.CoalescedEvent
with the specified discriminator andEvent
. -
Method Summary
Modifier and TypeMethodDescriptiongetDesiredState
(S state, ExecutionContext context) Determines the desired state of theFiniteStateMachine
for theEvent
given the current state of theFiniteStateMachine
.boolean
onAccept
(ExecutionContext context) Called by aFiniteStateMachine
when theLifecycleAwareEvent
is initially about to be accepted for processing.void
onProcessed
(ExecutionContext context) Called by aFiniteStateMachine
when theLifecycleAwareEvent
has been processed.void
onProcessing
(ExecutionContext context) Called by aFiniteStateMachine
when theLifecycleAwareEvent
is about to be processed.toString()
-
Constructor Details
-
CoalescedEvent
Constructs aNonBlockingFiniteStateMachine.CoalescedEvent
of the specifiedEvent
type usingNonBlockingFiniteStateMachine.CoalescedEvent.Process.FIRST
.- Parameters:
event
- theEvent
to be executed when coalesced
-
CoalescedEvent
Constructs aNonBlockingFiniteStateMachine.CoalescedEvent
of the specifiedEvent
type.- Parameters:
event
- theEvent
to be coalescedmode
- whichNonBlockingFiniteStateMachine.CoalescedEvent
s to process
-
CoalescedEvent
public CoalescedEvent(Event<S> event, NonBlockingFiniteStateMachine.CoalescedEvent.Process mode, Object discriminator) Constructs aNonBlockingFiniteStateMachine.CoalescedEvent
with the specified discriminator andEvent
.- Parameters:
event
- theEvent
to be coalescedmode
- whichNonBlockingFiniteStateMachine.CoalescedEvent
s to processdiscriminator
- the descriminator used to uniquely coalesce theEvent
-
-
Method Details
-
getDesiredState
Determines the desired state of theFiniteStateMachine
for theEvent
given the current state of theFiniteStateMachine
.- Specified by:
getDesiredState
in interfaceEvent<S extends Enum<S>>
- Parameters:
state
- the current state of theFiniteStateMachine
context
- theExecutionContext
for theEvent
- Returns:
- the desired state of the
FiniteStateMachine
ornull
if no transition is required
-
onAccept
Called by aFiniteStateMachine
when theLifecycleAwareEvent
is initially about to be accepted for processing.- Specified by:
onAccept
in interfaceLifecycleAwareEvent<S extends Enum<S>>
- Parameters:
context
- theExecutionContext
for theEvent
- Returns:
true
if theEvent
should be accepted, orfalse
if theFiniteStateMachine
should ignore theLifecycleAwareEvent
-
onProcessed
Called by aFiniteStateMachine
when theLifecycleAwareEvent
has been processed.- Specified by:
onProcessed
in interfaceLifecycleAwareEvent<S extends Enum<S>>
- Parameters:
context
- theExecutionContext
for theEvent
-
onProcessing
Called by aFiniteStateMachine
when theLifecycleAwareEvent
is about to be processed.- Specified by:
onProcessing
in interfaceLifecycleAwareEvent<S extends Enum<S>>
- Parameters:
context
- theExecutionContext
for theEvent
-
toString
-