api

package
v0.13.2-gc72711f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigurationVersionSeparator = ":"
)

Variables

View Source
var (
	Release string

	MalformedConfigurationError   = fmt.Errorf("this configuration cannot be parsed")
	MissingNameConfigurationError = fmt.Errorf(
		"configuration must always specify a name (and optionally a version)")
	MissingStatesConfigurationError = fmt.Errorf(
		"configuration must always specify at least one state")
	MissingDestinationError = fmt.Errorf(
		"event must always have a `Destination` statemachine")
	MissingEventNameError = fmt.Errorf(
		"events must always specify the event type")
	MismatchStartingStateConfigurationError = fmt.Errorf(
		"the StartingState must be one of the possible FSM states")
	EmptyStartingStateConfigurationError = fmt.Errorf("the StartingState must be non-empty")
	UnexpectedTransitionError            = fmt.Errorf("unexpected event transition")
	UnexpectedError                      = fmt.Errorf("the request was malformed")
	UnreachableStateConfigurationError   = "state %s is not used in any of the transitions"

	// Logger is made accessible so that its `Level` can be changed
	// or can be sent to a `NullLog` during testing.
	Logger = log.NewLog("api")
)

Functions

func CfgHasState

func CfgHasState(configuration *protos.Configuration, state string) bool

CfgHasState checks that `state` is one of the Configuration's `States`

func CheckValid

func CheckValid(c *protos.Configuration) error

CheckValid will validate that there is at least one state, and that the starting state is one of the possible states; further for any of the states it will check that they appear in at least one transition.

Finally, it will check that the name is valid, and that the generated `ConfigId` is a valid URI segment.

func GetVersionId

func GetVersionId(c *protos.Configuration) string

func HasState

func HasState(transition *protos.Transition, state string) bool

HasState will check whether a given state is either origin or destination for the Transition

func NewEvent

func NewEvent(eventName string) *protos.Event

NewEvent creates a new Event, with the given `eventName` transition.

func UpdateEvent

func UpdateEvent(event *protos.Event)

UpdateEvent adds the ID and timestamp to the event, if not already set.

Types

type ConfiguredStateMachine

type ConfiguredStateMachine struct {
	Config *protos.Configuration
	FSM    *protos.FiniteStateMachine
}

ConfiguredStateMachine is the internal representation of an FSM, which carries within itself the configuration for ease of use.

func NewStateMachine

func NewStateMachine(configuration *protos.Configuration) (*ConfiguredStateMachine, error)

func (*ConfiguredStateMachine) CheckValid

func (x *ConfiguredStateMachine) CheckValid() bool

CheckValid checks that the Configuration is valid and that the current FSM `state` is one of the allowed states in the Configuration.

We also check that the reported FSM ConfigId, matches the Configuration's name, version.

func (*ConfiguredStateMachine) Reset

func (x *ConfiguredStateMachine) Reset()

func (*ConfiguredStateMachine) SendEvent

func (x *ConfiguredStateMachine) SendEvent(evt *protos.Event) error

SendEvent registers the event with the FSM and effects the transition, if valid. It also creates a new Event, and stores in the provided cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL