Class NonBlockingFiniteStateMachine<S extends Enum<S>>
- java.lang.Object
-
- com.tangosol.util.fsm.NonBlockingFiniteStateMachine<S>
-
- All Implemented Interfaces:
ExecutionContext
,FiniteStateMachine<S>
public class NonBlockingFiniteStateMachine<S extends Enum<S>> extends Object implements FiniteStateMachine<S>, ExecutionContext
AnNonBlockingFiniteStateMachine
is a specializedFiniteStateMachine
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
Nested Classes Modifier and Type Class Description static 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
NonBlockingFiniteStateMachine.DefaultTaskDependencies
Implementation of Dependencies for Taskstatic class
NonBlockingFiniteStateMachine.DelayedTransitionTo<S extends Enum<S>>
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
NonBlockingFiniteStateMachine.ProcessEventLater<S extends Enum<S>>
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
NonBlockingFiniteStateMachine.Task
A PriorityTask implementation to process a requested event.static interface
NonBlockingFiniteStateMachine.TaskDependencies
Dependencies for Task.
-
Constructor Summary
Constructors Constructor Description NonBlockingFiniteStateMachine(String sName, Model<S> model, S stateInitial, com.tangosol.internal.util.DaemonPoolDependencies daemonPoolDeps, boolean fIgnoreExceptions, NonBlockingFiniteStateMachine.TaskDependencies deps)
Construct anNonBlockingFiniteStateMachine
given aModel
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(FiniteStateMachineListener<S> listener)
Add aFiniteStateMachineListener
to theFiniteStateMachine
.String
getName()
Obtains the name of theFiniteStateMachine
.S
getState()
Obtains the current state of theFiniteStateMachine
.long
getTransitionCount()
Obtains the number of transitions that have occurred in theFiniteStateMachine
.boolean
hasPendingEvents()
Determines if there are any pendingEvent
s for theFiniteStateMachine
to process.void
process(Event<S> event)
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
quiesceThenStop()
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.String
toString()
-
-
-
Constructor Detail
-
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 Detail
-
addListener
public void addListener(FiniteStateMachineListener<S> listener)
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
public void removeListener(FiniteStateMachineListener<S> listener)
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
public String 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
public S 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
-
process
public void process(Event<S> event)
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
public void processLater(Event<S> event)
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
public 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).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.
-
-