Search Results for

    Show / Hide Table of Contents

    Class FSM<TState, TData>

    Finite state machine (FSM) actor.

    Inheritance
    object
    ActorBase
    FSMBase
    FSM<TState, TData>
    ClusterSingletonManager
    Implements
    IInternalActor
    IListeners
    Inherited Members
    ActorBase.Sender
    ActorBase.Self
    ActorBase.Context
    ActorBase.AroundReceive(Receive, object)
    ActorBase.EmptyReceive
    ActorBase.Unhandled(object)
    ActorBase.Become(Receive)
    ActorBase.BecomeStacked(Receive)
    ActorBase.UnbecomeStacked()
    ActorBase.SetReceiveTimeout(TimeSpan?)
    ActorBase.AroundPreRestart(Exception, object)
    ActorBase.AroundPreStart()
    ActorBase.PreStart()
    ActorBase.AroundPostRestart(Exception, object)
    ActorBase.PreRestart(Exception, object)
    ActorBase.PostRestart(Exception)
    ActorBase.AroundPostStop()
    ActorBase.SupervisorStrategy()
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Akka.Actor
    Assembly: Akka.dll
    Syntax
    public abstract class FSM<TState, TData> : FSMBase, IInternalActor, IListeners
    Type Parameters
    Name Description
    TState

    The state name type

    TData

    The state data type

    Constructors

    | Edit this page View Source

    FSM()

    Initializes a new instance of the FSM class.

    Declaration
    protected FSM()

    Fields

    | Edit this page View Source

    DebugEvent

    Can be set to enable debugging on certain actions taken by the FSM

    Declaration
    protected bool DebugEvent
    Field Value
    Type Description
    bool

    Properties

    | Edit this page View Source

    Listeners

    Retrieves the support needed to interact with an actor's listeners.

    Declaration
    public ListenerSupport Listeners { get; }
    Property Value
    Type Description
    ListenerSupport
    | Edit this page View Source

    NextStateData

    Return next state data (available in OnTransition(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(TransitionHandler) handler.

    | Edit this page View Source

    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, TimeSpan?) was called.

    | Edit this page View Source

    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, TimeSpan?) was called.

    Methods

    | Edit this page View Source

    CancelTimer(string)

    Cancel a named 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.

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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, TimeSpan?) is called.

    | Edit this page View Source

    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
    bool

    TBD

    | Edit this page View Source

    LogTermination(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

    | Edit this page View Source

    OnTermination(Action<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

    | Edit this page View Source

    OnTransition(TransitionHandler)

    Set handler which is called upon each state transition

    Declaration
    public void OnTransition(FSM<TState, TData>.TransitionHandler transitionHandler)
    Parameters
    Type Name Description
    FSM<TState, TData>.TransitionHandler transitionHandler

    TBD

    | Edit this page View Source

    PostStop()

    Call the OnTermination(Action<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<StopEvent<TState, TData>>) shall not be called during restart.

    Declaration
    protected override void PostStop()
    Overrides
    ActorBase.PostStop()
    | Edit this page View Source

    Receive(object)

    Processor for user defined messages.

    Declaration
    protected override bool Receive(object message)
    Parameters
    Type Name Description
    object message

    The message.

    Returns
    Type Description
    bool

    TBD

    Overrides
    ActorBase.Receive(object)
    | Edit this page View Source

    SetStateTimeout(TState, 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

    TimeSpan? timeout

    TBD

    | Edit this page View Source

    SetTimer(string, object, TimeSpan, bool)

    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.

    bool repeat

    send once if false, scheduleAtFixedRate if true

    | Edit this page View Source

    StartWith(TState, TData, 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.

    TimeSpan? timeout

    State timeout for the initial state, overriding the default timeout for that state.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    Stop(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.

    | Edit this page View Source

    Stop(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.

    | Edit this page View Source

    Transform(StateFunction)

    TBD

    Declaration
    public FSM<TState, TData>.TransformHelper Transform(FSM<TState, TData>.StateFunction func)
    Parameters
    Type Name Description
    FSM<TState, TData>.StateFunction func

    TBD

    Returns
    Type Description
    FSM<TState, TData>.TransformHelper

    TBD

    | Edit this page View Source

    When(TState, StateFunction, 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<TState, TData>.StateFunction func

    delegate describing this state's response to input

    TimeSpan? timeout

    default timeout for this state

    | Edit this page View Source

    WhenUnhandled(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<TState, TData>.StateFunction stateFunction

    TBD

    Implements

    IInternalActor
    IListeners

    Extension Methods

    ObjectExtensions.IsDefaultForType<T>(T)
    ObjectExtensions.AsOption<T>(T)
    Extensions.AsInstanceOf<T>(object)
    In this article
    • githubEdit this page
    • View Source
    Back to top
    Contribute
    • Project Chat
    • Discussion Forum
    • Source Code
    Support
    • Akka.NET Support Plans
    • Akka.NET Observability Tools
    • Akka.NET Training & Consulting
    Maintained By
    • Petabridge - The Akka.NET Company
    • Learn Akka.NET