Class FSM<TState, TData>
Finite state machine (FSM) actor.
Inherited Members
Namespace: Akka.Actor
Assembly: Akka.dll
Syntax
public abstract class FSM<TState, TData> : FSMBase, IInternalActor, IListeners, IInternalSupportsTestFSMRef<TState, TData>
Type Parameters
Name | Description |
---|---|
TState | The state name type |
TData | The state data type |
Constructors
| Improve this Doc View SourceFSM()
Initializes a new instance of the FSM class.
Declaration
protected FSM()
Fields
| Improve this Doc View SourceDebugEvent
Can be set to enable debugging on certain actions taken by the FSM
Declaration
protected bool DebugEvent
Field Value
Type | Description |
---|---|
Boolean |
Properties
| Improve this Doc View SourceListeners
Retrieves the support needed to interact with an actor's listeners.
Declaration
public ListenerSupport Listeners { get; }
Property Value
Type | Description |
---|---|
ListenerSupport |
NextStateData
Return next state data (available in OnTransition(FSM<TState, TData>.TransitionHandler) handlers)
Declaration
public TData NextStateData { get; }
Property Value
Type | Description |
---|---|
TData |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | This exception is thrown if this property is accessed outside of an OnTransition(FSM<TState, TData>.TransitionHandler) handler. |
StateData
Current state data
Declaration
public TData StateData { get; }
Property Value
Type | Description |
---|---|
TData |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown if this property is accessed before StartWith(TState, TData, Nullable<TimeSpan>) was called. |
StateName
Current state name
Declaration
public TState StateName { get; }
Property Value
Type | Description |
---|---|
TState |
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown if this property is accessed before StartWith(TState, TData, Nullable<TimeSpan>) was called. |
Methods
| Improve this Doc View SourceCancelTimer(String)
Cancel a named Akka.Actor.FSMBase.Timer, ensuring that the message is not subsequently delivered (no race.)
Declaration
public void CancelTimer(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the timer to cancel. |
GoTo(TState)
Produce transition to other state. Return this from a state function in order to effect the transition.
Declaration
public FSMBase.State<TState, TData> GoTo(TState nextStateName)
Parameters
Type | Name | Description |
---|---|---|
TState | nextStateName | State designator for the next state |
Returns
Type | Description |
---|---|
FSMBase.State<TState, TData> | State transition descriptor |
GoTo(TState, TData)
Obsolete. Use GoTo(nextStateName).Using(stateData) instead.
Declaration
[Obsolete("This method is obsoleted. Use GoTo(nextStateName).Using(newStateData) [1.2.0]")]
public FSMBase.State<TState, TData> GoTo(TState nextStateName, TData stateData)
Parameters
Type | Name | Description |
---|---|---|
TState | nextStateName | N/A |
TData | stateData | N/A |
Returns
Type | Description |
---|---|
FSMBase.State<TState, TData> | N/A |
Initialize()
Verify the existence of initial state and setup timers. This should be the last call within the constructor or PreStart() and PostRestart(Exception).
Declaration
public void Initialize()
Exceptions
Type | Condition |
---|---|
IllegalStateException | This exception is thrown when this method is called before StartWith(TState, TData, Nullable<TimeSpan>) is called. |
IsTimerActive(String)
Determines whether the named timer is still active. Returns true unless the timer does not exist, has previously been cancelled, or if it was a single-shot timer whose message was already received.
Declaration
public bool IsTimerActive(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | TBD |
Returns
Type | Description |
---|---|
Boolean | TBD |
LogTermination(FSMBase.Reason)
By default, Failure is logged at error level and other reason types are not logged. It is possible to override this behavior.
Declaration
protected virtual void LogTermination(FSMBase.Reason reason)
Parameters
Type | Name | Description |
---|---|---|
FSMBase.Reason | reason | TBD |
OnTermination(Action<FSMBase.StopEvent<TState, TData>>)
Set the handler which is called upon termination of this FSM actor. Calling this method again will overwrite the previous contents.
Declaration
public void OnTermination(Action<FSMBase.StopEvent<TState, TData>> terminationHandler)
Parameters
Type | Name | Description |
---|---|---|
Action<FSMBase.StopEvent<TState, TData>> | terminationHandler | TBD |
OnTransition(FSM<TState, TData>.TransitionHandler)
Set handler which is called upon each state transition
Declaration
public void OnTransition(FSM<TState, TData>.TransitionHandler transitionHandler)
Parameters
Type | Name | Description |
---|---|---|
FSM.TransitionHandler<> | transitionHandler | TBD |
PostStop()
Call the OnTermination(Action<FSMBase.StopEvent<TState, TData>>) hook if you want to retain this behavior. When overriding make sure to call base.PostStop();
Please note that this method is called by default from PreRestart(Exception, Object) so override that one if OnTermination(Action<FSMBase.StopEvent<TState, TData>>) shall not be called during restart.
Declaration
protected override void PostStop()
Overrides
| Improve this Doc View SourceReceive(Object)
Processor for user defined messages.
Declaration
protected override bool Receive(object message)
Parameters
Type | Name | Description |
---|---|---|
Object | message | The message. |
Returns
Type | Description |
---|---|
Boolean | TBD |
Overrides
| Improve this Doc View SourceSetStateTimeout(TState, Nullable<TimeSpan>)
Set the state timeout explicitly. This method can be safely used from within a state handler.
Declaration
public void SetStateTimeout(TState state, TimeSpan? timeout)
Parameters
Type | Name | Description |
---|---|---|
TState | state | TBD |
Nullable<TimeSpan> | timeout | TBD |
SetTimer(String, Object, TimeSpan, Boolean)
Schedule named timer to deliver message after given delay, possibly repeating. Any existing timer with the same name will automatically be canceled before adding the new timer.
Declaration
public void SetTimer(string name, object msg, TimeSpan timeout, bool repeat = false)
Parameters
Type | Name | Description |
---|---|---|
String | name | identifier to be used with CancelTimer(String). |
Object | msg | message to be delivered |
TimeSpan | timeout | delay of first message delivery and between subsequent messages. |
Boolean | repeat | send once if false, scheduleAtFixedRate if true |
StartWith(TState, TData, Nullable<TimeSpan>)
Sets the initial state for this FSM. Call this method from the constructor before the Initialize() method. If different state is needed after a restart this method, followed by Initialize(), can be used in the actor life cycle hooks PreStart() and PostRestart(Exception).
Declaration
public void StartWith(TState stateName, TData stateData, TimeSpan? timeout = null)
Parameters
Type | Name | Description |
---|---|---|
TState | stateName | Initial state designator. |
TData | stateData | Initial state data. |
Nullable<TimeSpan> | timeout | State timeout for the initial state, overriding the default timeout for that state. |
Stay()
Produce "empty" transition descriptor. Return this from a state function when no state change is to be effected.
Declaration
public FSMBase.State<TState, TData> Stay()
Returns
Type | Description |
---|---|
FSMBase.State<TState, TData> | Descriptor for staying in the current state. |
Stop()
Produce change descriptor to stop this FSM actor with FSMBase.Reason FSMBase.Normal
Declaration
public FSMBase.State<TState, TData> Stop()
Returns
Type | Description |
---|---|
FSMBase.State<TState, TData> | Descriptor for stopping in the current state. |
Stop(FSMBase.Reason)
Produce change descriptor to stop this FSM actor with the specified FSMBase.Reason.
Declaration
public FSMBase.State<TState, TData> Stop(FSMBase.Reason reason)
Parameters
Type | Name | Description |
---|---|---|
FSMBase.Reason | reason | Reason why this FSM<TState, TData> is shutting down. |
Returns
Type | Description |
---|---|
FSMBase.State<TState, TData> | Descriptor for stopping in the current state. |
Stop(FSMBase.Reason, TData)
Produce change descriptor to stop this FSM actor with the specified FSMBase.Reason.
Declaration
public FSMBase.State<TState, TData> Stop(FSMBase.Reason reason, TData stateData)
Parameters
Type | Name | Description |
---|---|---|
FSMBase.Reason | reason | Reason why this FSM<TState, TData> is shutting down. |
TData | stateData | State data. |
Returns
Type | Description |
---|---|
FSMBase.State<TState, TData> | Descriptor for stopping in the current state. |
Transform(FSM<TState, TData>.StateFunction)
TBD
Declaration
public FSM<TState, TData>.TransformHelper Transform(FSM<TState, TData>.StateFunction func)
Parameters
Type | Name | Description |
---|---|---|
FSM.StateFunction<> | func | TBD |
Returns
Type | Description |
---|---|
FSM.TransformHelper<> | TBD |
When(TState, FSM<TState, TData>.StateFunction, Nullable<TimeSpan>)
Insert a new FSM<TState, TData>.StateFunction at the end of the processing chain for the given state. If the stateTimeout parameter is set, entering this state without a differing explicit timeout setting will trigger a FSMBase.StateTimeout.
Declaration
public void When(TState stateName, FSM<TState, TData>.StateFunction func, TimeSpan? timeout = null)
Parameters
Type | Name | Description |
---|---|---|
TState | stateName | designator for the state |
FSM.StateFunction<> | func | delegate describing this state's response to input |
Nullable<TimeSpan> | timeout | default timeout for this state |
WhenUnhandled(FSM<TState, TData>.StateFunction)
Set handler which is called upon reception of unhandled FSM messages. Calling this method again will overwrite the previous contents.
Declaration
public void WhenUnhandled(FSM<TState, TData>.StateFunction stateFunction)
Parameters
Type | Name | Description |
---|---|---|
FSM.StateFunction<> | stateFunction | TBD |