Documentation ΒΆ
Index ΒΆ
- Constants
- type CannotRunFromStateError
- type CannotTransferToStateError
- type DefaultState
- type State
- type StateMachine
- func (sm *StateMachine) AddTransition(transition Transition, sourceStates States, destinationStates States)
- func (sm StateMachine) GetAllStates() States
- func (sm StateMachine) GetAvailableTransitions() Transitions
- func (sm StateMachine) GetTransitionRules() TransitionRules
- func (sm StateMachine) Run(transition Transition, transitionArguments TransitionArguments) error
- type Stateful
- type States
- type Transition
- type TransitionArguments
- type TransitionRule
- type TransitionRuleNotFoundError
- type TransitionRules
- type Transitions
Constants ΒΆ
const ( // AllStates is a wildcard which represents all states in the state machine AllStates = DefaultState("*") )
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type CannotRunFromStateError ΒΆ
type CannotRunFromStateError struct {
// contains filtered or unexported fields
}
func NewCannotRunFromStateError ΒΆ
func NewCannotRunFromStateError(stateMachine StateMachine, transitionRule TransitionRule) *CannotRunFromStateError
func (CannotRunFromStateError) Error ΒΆ
func (crfse CannotRunFromStateError) Error() string
type CannotTransferToStateError ΒΆ
type CannotTransferToStateError struct {
// contains filtered or unexported fields
}
func NewCannotTransferToStateError ΒΆ
func NewCannotTransferToStateError(state State) *CannotTransferToStateError
func (CannotTransferToStateError) Error ΒΆ
func (cttse CannotTransferToStateError) Error() string
type DefaultState ΒΆ
type DefaultState string
DefaultState is a string which should be used in every stateful object as the state
func (DefaultState) GetID ΒΆ
func (ds DefaultState) GetID() string
GetID returns the string representation of the DefaultState
func (DefaultState) IsWildCard ΒΆ
func (ds DefaultState) IsWildCard() bool
IsWildCard checks if the current state is a wildcard. So if the state stands for all possible states
type StateMachine ΒΆ
type StateMachine struct { StatefulObject Stateful // contains filtered or unexported fields }
StateMachine handles the state of the StatefulObject
func (*StateMachine) AddTransition ΒΆ
func (sm *StateMachine) AddTransition( transition Transition, sourceStates States, destinationStates States, )
AddTransition adds a transition to the state machine.
func (StateMachine) GetAllStates ΒΆ
func (sm StateMachine) GetAllStates() States
GetAllStates returns all known and possible states by the state machine
func (StateMachine) GetAvailableTransitions ΒΆ
func (sm StateMachine) GetAvailableTransitions() Transitions
func (StateMachine) GetTransitionRules ΒΆ
func (sm StateMachine) GetTransitionRules() TransitionRules
GetTransitionRules returns all transitionRules in the state machine
func (StateMachine) Run ΒΆ
func (sm StateMachine) Run( transition Transition, transitionArguments TransitionArguments, ) error
Run runs the state machine with the given transition. If the transition
type Stateful ΒΆ
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 ΒΆ
type States []State
States are a slice of State
func (States) Contains ΒΆ
Contains search in States if the given state is inside the States. It compares with GetID
func (States) HasWildCard ΒΆ
HasWildCard checks if there is a wildcard state inside of States
type Transition ΒΆ
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 ΒΆ
func (t Transition) GetID() uintptr
func (Transition) GetName ΒΆ
func (t Transition) GetName() string
type TransitionArguments ΒΆ added in v0.0.7
type TransitionArguments interface{}
TransitionArguments represents the arguments
type TransitionRule ΒΆ
type TransitionRule struct { SourceStates States Transition Transition DestinationStates States }
func (TransitionRule) IsAllowedToRun ΒΆ
func (tr TransitionRule) IsAllowedToRun(state State) bool
func (TransitionRule) IsAllowedToTransfer ΒΆ
func (tr TransitionRule) IsAllowedToTransfer(state State) bool
type TransitionRuleNotFoundError ΒΆ
type TransitionRuleNotFoundError struct {
// contains filtered or unexported fields
}
func NewTransitionRuleNotFoundError ΒΆ
func NewTransitionRuleNotFoundError(transition Transition) *TransitionRuleNotFoundError
func (TransitionRuleNotFoundError) Error ΒΆ
func (trnfe TransitionRuleNotFoundError) Error() string
type TransitionRules ΒΆ
type TransitionRules []TransitionRule
func (TransitionRules) Find ΒΆ
func (trs TransitionRules) Find(transition Transition) *TransitionRule
type Transitions ΒΆ
type Transitions []Transition
Transitions are a slice of Transition
func (Transitions) Contains ΒΆ
func (ts Transitions) Contains(transition Transition) bool