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
Nested ClassesModifier and TypeClassDescriptionstatic classNonBlockingFiniteStateMachine.CoalescedEvent<S extends Enum<S>>ANonBlockingFiniteStateMachine.CoalescedEventis aLifecycleAwareEventthat coalesces other (wrapped)Events with the same discriminator so that only oneEventactually executes.static classImplementation of Dependencies for Taskstatic classANonBlockingFiniteStateMachine.DelayedTransitionTois a specializedInstructionforNonBlockingFiniteStateMachines that enables aStateEntryActionto request a delayed transition to another state, unlike aInstruction.TransitionToInstructionwhich occurs immediately.static classA specializedInstructionforNonBlockingFiniteStateMachines that enables aStateEntryActionto request anEventto be processed at some point in the future.static classNonBlockingFiniteStateMachine.SubsequentEvent<S extends Enum<S>>ANonBlockingFiniteStateMachine.SubsequentEventis anEventthat ensures that another (wrapped)Eventto occur if an only if theFiniteStateMachineis at a certain transition count.protected classA PriorityTask implementation to process a requested event.static interfaceDependencies for Task. -
Constructor Summary
ConstructorsConstructorDescriptionNonBlockingFiniteStateMachine(String sName, Model<S> model, S stateInitial, com.tangosol.internal.util.DaemonPoolDependencies daemonPoolDeps, boolean fIgnoreExceptions, NonBlockingFiniteStateMachine.TaskDependencies deps) Construct anNonBlockingFiniteStateMachinegiven aModel. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(FiniteStateMachineListener<S> listener) Add aFiniteStateMachineListenerto theFiniteStateMachine.getName()Obtains the name of theFiniteStateMachine.getState()Obtains the current state of theFiniteStateMachine.longObtains the number of transitions that have occurred in theFiniteStateMachine.booleanDetermines if there are any pendingEvents for theFiniteStateMachineto process.voidRequest theFiniteStateMachineto process the specifiedEvent.voidprocessLater(Event<S> event) Request theFiniteStateMachineto process the specifiedEventas soon as possible.voidprocessLater(Event<S> event, long duration, TimeUnit timeUnit) Request theFiniteStateMachineto process the specifiedEventat some point in the future (represented as a duration to wait from the moment the method is called).booleanRequests theFiniteStateMachineto stop accepting newEvents to process, wait for any existing queuedEvents to be processed and then stop.voidremoveListener(FiniteStateMachineListener<S> listener) Remove aFiniteStateMachineListenerfrom theFiniteStateMachine.booleanstart()Start theFiniteStateMachineand enter the initial state.booleanstop()Stops theFiniteStateMachineas 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 anNonBlockingFiniteStateMachinegiven aModel.- Parameters:
sName- the name of theNonBlockingFiniteStateMachinemodel- theModelof theNonBlockingFiniteStateMachinestateInitial- the initial statedaemonPoolDeps- OptionalDaemonPoolDependenciesfor Daemon Pool that will be used for schedulingTransitionsfIgnoreExceptions- whentrueRuntimeExceptions will be ignored, whenfalseRuntimeExceptions will immediately stop theNonBlockingFiniteStateMachinedeps- theNonBlockingFiniteStateMachine.TaskDependenciesspecifies the event processing configs.
-
-
Method Details
-
addListener
Add aFiniteStateMachineListenerto theFiniteStateMachine.Note that unique instances of FiniteStateMachineListener are identified via their
equalsandhashCodeimplementations.- Specified by:
addListenerin interfaceFiniteStateMachine<S extends Enum<S>>- Parameters:
listener- the listener to be added
-
removeListener
Remove aFiniteStateMachineListenerfrom theFiniteStateMachine.Note that unique instances of FiniteStateMachineListener are identified via their
equalsandhashCodeimplementations.- Specified by:
removeListenerin 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:
getNamein interfaceExecutionContext- Specified by:
getNamein 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
Transitionmay be executing asynchronously in the background on another thread.- Specified by:
getStatein 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
Transitionmay be executing asynchronously in the background on another thread.- Specified by:
getTransitionCountin interfaceExecutionContext- Specified by:
getTransitionCountin interfaceFiniteStateMachine<S extends Enum<S>>- Returns:
- the number of transitions that have occurred in the
FiniteStateMachine
-
start
public boolean start()Start theFiniteStateMachineand enter the initial state.Note: Once stopped a
FiniteStateMachinecan't be restarted; instead a newFiniteStateMachineshould be created.- Specified by:
startin interfaceFiniteStateMachine<S extends Enum<S>>- Returns:
trueif the start was successful or the FiniteStateMachine is already stated,falseif it has been stopped
-
stop
public boolean stop()Stops theFiniteStateMachineas soon as possible.Note: Once stopped a
FiniteStateMachinecan't be restarted; instead a newFiniteStateMachineshould be created.- Specified by:
stopin interfaceFiniteStateMachine<S extends Enum<S>>- Returns:
trueif the stop was successful,falseif it's already stopped
-
quiesceThenStop
public boolean quiesceThenStop()Requests theFiniteStateMachineto stop accepting newEvents to process, wait for any existing queuedEvents to be processed and then stop.Note: Once stopped a
FiniteStateMachinecan't be restarted. Instead a newFiniteStateMachineshould be created.- Returns:
trueif theFiniteStateMachinewas stopped orfalseif it was already stopped- Throws:
IllegalStateException- if the FiniteStateMachine was never started
-
toString
-
process
Request theFiniteStateMachineto process the specifiedEvent.Note: There's no guarantee that the
Eventwill be processed because:- the
Transitionto be performed for theEventis invalid as theFiniteStateMachineis not in the required starting state. - the
FiniteStateMachinemay have been stopped.
- Specified by:
processin interfaceFiniteStateMachine<S extends Enum<S>>- Parameters:
event- theEventfor theFiniteStateMachineto process
- the
-
processLater
Request theFiniteStateMachineto process the specifiedEventas soon as possible.Note: This method is semantically equivalent to
process(Event).- Parameters:
event- theEventfor theFiniteStateMachineto process
-
processLater
Request theFiniteStateMachineto process the specifiedEventat 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
Eventwill processed because:- the
Transitionto be performed for theEventis invalid as theFiniteStateMachineis not in the required starting state. - the
FiniteStateMachinemay have been stopped.
- Parameters:
event- theEventfor theFiniteStateMachineto processduration- the amount of theTimeUnitto wait before theEventis processedtimeUnit- theTimeUnit
- the
-
hasPendingEvents
public boolean hasPendingEvents()Determines if there are any pendingEvents for theFiniteStateMachineto process.Note: If the
FiniteStateMachinecan no longer processEvents false will be returned.
-