Class NonBlockingFiniteStateMachine.CoalescedEvent<S extends Enum<S>>
- java.lang.Object
-
- com.tangosol.util.fsm.NonBlockingFiniteStateMachine.CoalescedEvent<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>>
public static class NonBlockingFiniteStateMachine.CoalescedEvent<S extends Enum<S>> extends Object implements LifecycleAwareEvent<S>
ANonBlockingFiniteStateMachine.CoalescedEvent
is aLifecycleAwareEvent
that coalesces other (wrapped)Event
s with the same discriminator so that only oneEvent
actually executes.For example: Given 10
Event
s submitted to aNonBlockingFiniteStateMachine
with the same discriminator, only one of the saidEvent
s will be processed. All others will be discarded. Once theNonBlockingFiniteStateMachine.CoalescedEvent
has been processed, a new batch may be created when anotherNonBlockingFiniteStateMachine.CoalescedEvent
of the same discriminator is submitted.The actual
Event
processed depends on the mode of coalescing required. The firstNonBlockingFiniteStateMachine.CoalescedEvent
submitted to aNonBlockingFiniteStateMachine
for a specific discriminator effectively starts the coalescing ofEvent
s for the said discriminator. When the mode is set toNonBlockingFiniteStateMachine.CoalescedEvent.Process.FIRST
, then the firstEvent
(starting the coalescing) will be processed and others will be discarded. When the mode is set ofNonBlockingFiniteStateMachine.CoalescedEvent.Process.MOST_RECENT
then the most recently submittedEvent
will be processed and likewise, all others for the same discriminator will be discarded.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NonBlockingFiniteStateMachine.CoalescedEvent.Discriminator
ANonBlockingFiniteStateMachine.CoalescedEvent.Discriminator
is an object that is used to uniquely differentiate events to be coalesced, scoped by aNonBlockingFiniteStateMachine
.static class
NonBlockingFiniteStateMachine.CoalescedEvent.Process
TheNonBlockingFiniteStateMachine.CoalescedEvent
to process.
-
Constructor Summary
Constructors Constructor Description CoalescedEvent(Event<S> event)
Constructs aNonBlockingFiniteStateMachine.CoalescedEvent
of the specifiedEvent
type usingNonBlockingFiniteStateMachine.CoalescedEvent.Process.FIRST
.CoalescedEvent(Event<S> event, NonBlockingFiniteStateMachine.CoalescedEvent.Process mode)
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description S
getDesiredState(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.String
toString()
-
-
-
Constructor Detail
-
CoalescedEvent
public CoalescedEvent(Event<S> event)
Constructs aNonBlockingFiniteStateMachine.CoalescedEvent
of the specifiedEvent
type usingNonBlockingFiniteStateMachine.CoalescedEvent.Process.FIRST
.- Parameters:
event
- theEvent
to be executed when coalesced
-
CoalescedEvent
public CoalescedEvent(Event<S> event, NonBlockingFiniteStateMachine.CoalescedEvent.Process mode)
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 Detail
-
getDesiredState
public S getDesiredState(S state, ExecutionContext context)
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
public boolean onAccept(ExecutionContext context)
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
public void onProcessed(ExecutionContext context)
Called by aFiniteStateMachine
when theLifecycleAwareEvent
has been processed.- Specified by:
onProcessed
in interfaceLifecycleAwareEvent<S extends Enum<S>>
- Parameters:
context
- theExecutionContext
for theEvent
-
onProcessing
public void onProcessing(ExecutionContext context)
Called by aFiniteStateMachine
when theLifecycleAwareEvent
is about to be processed.- Specified by:
onProcessing
in interfaceLifecycleAwareEvent<S extends Enum<S>>
- Parameters:
context
- theExecutionContext
for theEvent
-
-