stateful: github.com/bykof/stateful Index | Files | Directories

package stateful

import "github.com/bykof/stateful"

Index

Package Files

errors.go state.go stateMachine.go stateful.go transition.go transitionRule.go

Constants

const (
    // AllStates is a wildcard which represents all states in the state machine
    AllStates = DefaultState("*")
)

type CannotRunFromStateError Uses

type CannotRunFromStateError struct {
    // contains filtered or unexported fields
}

func NewCannotRunFromStateError Uses

func NewCannotRunFromStateError(stateMachine StateMachine, transitionRule TransitionRule) *CannotRunFromStateError

func (CannotRunFromStateError) Error Uses

func (crfse CannotRunFromStateError) Error() string

type CannotTransferToStateError Uses

type CannotTransferToStateError struct {
    // contains filtered or unexported fields
}

func NewCannotTransferToStateError Uses

func NewCannotTransferToStateError(state State) *CannotTransferToStateError

func (CannotTransferToStateError) Error Uses

func (cttse CannotTransferToStateError) Error() string

type DefaultState Uses

type DefaultState string

DefaultState is a string which should be used in every stateful object as the state

func (DefaultState) GetID Uses

func (ds DefaultState) GetID() string

GetID returns the string representation of the DefaultState

func (DefaultState) IsWildCard Uses

func (ds DefaultState) IsWildCard() bool

IsWildCard checks if the current state is a wildcard. So if the state stands for all possible states

type State Uses

type State interface {
    GetID() string
    IsWildCard() bool
}

State represents a state of a stateful object

type StateMachine Uses

type StateMachine struct {
    StatefulObject Stateful
    // contains filtered or unexported fields
}

StateMachine handles the state of the StatefulObject

func (*StateMachine) AddTransition Uses

func (sm *StateMachine) AddTransition(
    transition Transition,
    sourceStates States,
    destinationStates States,
)

AddTransition adds a transition to the state machine.

func (StateMachine) GetAllStates Uses

func (sm StateMachine) GetAllStates() States

GetAllStates returns all known and possible states by the state machine

func (StateMachine) GetAvailableTransitions Uses

func (sm StateMachine) GetAvailableTransitions() Transitions

func (StateMachine) GetTransitionRules Uses

func (sm StateMachine) GetTransitionRules() TransitionRules

GetTransitionRules returns all transitionRules in the state machine

func (StateMachine) Run Uses

func (sm StateMachine) Run(
    transition Transition,
    transitionArguments TransitionArguments,
) error

Run runs the state machine with the given transition. If the transition

type Stateful Uses

type Stateful interface {
    // State returns the current state of the stateful object
    State() State

    // SetState sets the state of the stateful object and returns an error if it fails
    SetState(state State) error
}

Stateful is the core interface which should be implemented by all stateful structs. If this interface is implemented by a struct it can be processed by the state machine

type States Uses

type States []State

States are a slice of State

func (States) Contains Uses

func (ss States) Contains(state State) bool

Contains search in States if the given state is inside the States. It compares with GetID

func (States) HasWildCard Uses

func (ss States) HasWildCard() bool

HasWildCard checks if there is a wildcard state inside of States

type Transition Uses

type Transition func(transitionArguments TransitionArguments) (State, error)

Transition represents the transition function which will be executed if the order is in the proper state and there is a valid transitionRule in the state machine

func (Transition) GetID Uses

func (t Transition) GetID() uintptr

func (Transition) GetName Uses

func (t Transition) GetName() string

type TransitionArguments Uses

type TransitionArguments interface{}

TransitionArguments represents the arguments

type TransitionRule Uses

type TransitionRule struct {
    SourceStates      States
    Transition        Transition
    DestinationStates States
}

func (TransitionRule) IsAllowedToRun Uses

func (tr TransitionRule) IsAllowedToRun(state State) bool

func (TransitionRule) IsAllowedToTransfer Uses

func (tr TransitionRule) IsAllowedToTransfer(state State) bool

type TransitionRuleNotFoundError Uses

type TransitionRuleNotFoundError struct {
    // contains filtered or unexported fields
}

func NewTransitionRuleNotFoundError Uses

func NewTransitionRuleNotFoundError(transition Transition) *TransitionRuleNotFoundError

func (TransitionRuleNotFoundError) Error Uses

func (trnfe TransitionRuleNotFoundError) Error() string

type TransitionRules Uses

type TransitionRules []TransitionRule

func (TransitionRules) Find Uses

func (trs TransitionRules) Find(transition Transition) *TransitionRule

type Transitions Uses

type Transitions []Transition

Transitions are a slice of Transition

func (Transitions) Contains Uses

func (ts Transitions) Contains(transition Transition) bool

Directories

PathSynopsis
statefulGraph

Package stateful imports 4 packages (graph) and is imported by 1 packages. Updated 2020-05-27. Refresh now. Tools for package owners.