Class NonBlockingFiniteStateMachine<S extends Enum<S>>
- All Implemented Interfaces:
ExecutionContext
,FiniteStateMachine<S>
NonBlockingFiniteStateMachine
is a specialized FiniteStateMachine
implementation that performs transitions
asynchronously to the threads that request state changes. That is,
threads that request state transitions are never blocked. Instead their
requests are queued for a single thread to later perform the appropriate
transition to the requested state.- Since:
- Coherence 12.2.1
- Author:
- Brian Oliver
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
NonBlockingFiniteStateMachine.CoalescedEvent<S extends Enum<S>>
ANonBlockingFiniteStateMachine.CoalescedEvent
is aLifecycleAwareEvent
that coalesces other (wrapped)Event
s with the same discriminator so that only oneEvent
actually executes.static class
Implementation of Dependencies for Taskstatic class
ANonBlockingFiniteStateMachine.DelayedTransitionTo
is a specializedInstruction
forNonBlockingFiniteStateMachine
s that enables aStateEntryAction
to request a delayed transition to another state, unlike aInstruction.TransitionTo
Instruction
which occurs immediately.static class
A specializedInstruction
forNonBlockingFiniteStateMachine
s that enables aStateEntryAction
to request anEvent
to be processed at some point in the future.static class
NonBlockingFiniteStateMachine.SubsequentEvent<S extends Enum<S>>
ANonBlockingFiniteStateMachine.SubsequentEvent
is anEvent
that ensures that another (wrapped)Event
to occur if an only if theFiniteStateMachine
is at a certain transition count.protected class
A PriorityTask implementation to process a requested event.static interface
Dependencies for Task. -
Constructor Summary
ConstructorDescriptionNonBlockingFiniteStateMachine
(String sName, Model<S> model, S stateInitial, com.tangosol.internal.util.DaemonPoolDependencies daemonPoolDeps, boolean fIgnoreExceptions, NonBlockingFiniteStateMachine.TaskDependencies deps) Construct anNonBlockingFiniteStateMachine
given aModel
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(FiniteStateMachineListener<S> listener) Add aFiniteStateMachineListener
to theFiniteStateMachine
.getName()
Obtains the name of theFiniteStateMachine
.getState()
Obtains the current state of theFiniteStateMachine
.long
Obtains the number of transitions that have occurred in theFiniteStateMachine
.boolean
Determines if there are any pendingEvent
s for theFiniteStateMachine
to process.void
Request theFiniteStateMachine
to process the specifiedEvent
.void
processLater
(Event<S> event) Request theFiniteStateMachine
to process the specifiedEvent
as soon as possible.void
processLater
(Event<S> event, long duration, TimeUnit timeUnit) Request theFiniteStateMachine
to process the specifiedEvent
at some point in the future (represented as a duration to wait from the moment the method is called).boolean
Requests theFiniteStateMachine
to stop accepting newEvent
s to process, wait for any existing queuedEvent
s to be processed and then stop.void
removeListener
(FiniteStateMachineListener<S> listener) Remove aFiniteStateMachineListener
from theFiniteStateMachine
.boolean
start()
Start theFiniteStateMachine
and enter the initial state.boolean
stop()
Stops theFiniteStateMachine
as soon as possible.toString()
-
Constructor Details
-
NonBlockingFiniteStateMachine
public NonBlockingFiniteStateMachine(String sName, Model<S> model, S stateInitial, com.tangosol.internal.util.DaemonPoolDependencies daemonPoolDeps, boolean fIgnoreExceptions, NonBlockingFiniteStateMachine.TaskDependencies deps) Construct anNonBlockingFiniteStateMachine
given aModel
.- Parameters:
sName
- the name of theNonBlockingFiniteStateMachine
model
- theModel
of theNonBlockingFiniteStateMachine
stateInitial
- the initial statedaemonPoolDeps
- OptionalDaemonPoolDependencies
for Daemon Pool that will be used for schedulingTransition
sfIgnoreExceptions
- whentrue
RuntimeException
s will be ignored, whenfalse
RuntimeException
s will immediately stop theNonBlockingFiniteStateMachine
deps
- theNonBlockingFiniteStateMachine.TaskDependencies
specifies the event processing configs.
-
-
Method Details
-
addListener
Add aFiniteStateMachineListener
to theFiniteStateMachine
.Note that unique instances of FiniteStateMachineListener are identified via their
equals
andhashCode
implementations.- Specified by:
addListener
in interfaceFiniteStateMachine<S extends Enum<S>>
- Parameters:
listener
- the listener to be added
-
removeListener
Remove aFiniteStateMachineListener
from theFiniteStateMachine
.Note that unique instances of FiniteStateMachineListener are identified via their
equals
andhashCode
implementations.- Specified by:
removeListener
in interfaceFiniteStateMachine<S extends Enum<S>>
- Parameters:
listener
- the listener to be removed
-
getName
Obtains the name of theFiniteStateMachine
. This is primarily used for display/logging/monitoring purposes.- Specified by:
getName
in interfaceExecutionContext
- Specified by:
getName
in interfaceFiniteStateMachine<S extends Enum<S>>
- Returns:
- the name of the
FiniteStateMachine
-
getState
Obtains the current state of theFiniteStateMachine
.Note: After returning the current state there's no guarantee that the state will be the same because a
Transition
may be executing asynchronously in the background on another thread.- Specified by:
getState
in interfaceFiniteStateMachine<S extends Enum<S>>
- Returns:
- the current state of the
FiniteStateMachine
-
getTransitionCount
public long getTransitionCount()Obtains the number of transitions that have occurred in theFiniteStateMachine
.Note: After returning the count there's no guarantee that the count will be the same on the next request because a
Transition
may be executing asynchronously in the background on another thread.- Specified by:
getTransitionCount
in interfaceExecutionContext
- Specified by:
getTransitionCount
in interfaceFiniteStateMachine<S extends Enum<S>>
- Returns:
- the number of transitions that have occurred in the
FiniteStateMachine
-
start
public boolean start()Start theFiniteStateMachine
and enter the initial state.Note: Once stopped a
FiniteStateMachine
can't be restarted; instead a newFiniteStateMachine
should be created.- Specified by:
start
in interfaceFiniteStateMachine<S extends Enum<S>>
- Returns:
true
if the start was successful or the FiniteStateMachine is already stated,false
if it has been stopped
-
stop
public boolean stop()Stops theFiniteStateMachine
as soon as possible.Note: Once stopped a
FiniteStateMachine
can't be restarted; instead a newFiniteStateMachine
should be created.- Specified by:
stop
in interfaceFiniteStateMachine<S extends Enum<S>>
- Returns:
true
if the stop was successful,false
if it's already stopped
-
quiesceThenStop
public boolean quiesceThenStop()Requests theFiniteStateMachine
to stop accepting newEvent
s to process, wait for any existing queuedEvent
s to be processed and then stop.Note: Once stopped a
FiniteStateMachine
can't be restarted. Instead a newFiniteStateMachine
should be created.- Returns:
true
if theFiniteStateMachine
was stopped orfalse
if it was already stopped- Throws:
IllegalStateException
- if the FiniteStateMachine was never started
-
toString
-
process
Request theFiniteStateMachine
to process the specifiedEvent
.Note: There's no guarantee that the
Event
will be processed because:- the
Transition
to be performed for theEvent
is invalid as theFiniteStateMachine
is not in the required starting state. - the
FiniteStateMachine
may have been stopped.
- Specified by:
process
in interfaceFiniteStateMachine<S extends Enum<S>>
- Parameters:
event
- theEvent
for theFiniteStateMachine
to process
- the
-
processLater
Request theFiniteStateMachine
to process the specifiedEvent
as soon as possible.Note: This method is semantically equivalent to
process(Event)
.- Parameters:
event
- theEvent
for theFiniteStateMachine
to process
-
processLater
Request theFiniteStateMachine
to process the specifiedEvent
at some point in the future (represented as a duration to wait from the moment the method is called).Note: There's no guarantee that the
Event
will processed because:- the
Transition
to be performed for theEvent
is invalid as theFiniteStateMachine
is not in the required starting state. - the
FiniteStateMachine
may have been stopped.
- Parameters:
event
- theEvent
for theFiniteStateMachine
to processduration
- the amount of theTimeUnit
to wait before theEvent
is processedtimeUnit
- theTimeUnit
- the
-
hasPendingEvents
public boolean hasPendingEvents()Determines if there are any pendingEvent
s for theFiniteStateMachine
to process.Note: If the
FiniteStateMachine
can no longer processEvent
s false will be returned.
-