Documentation ¶
Index ¶
- Constants
- Variables
- func Error(msg string) func(string) StoreErr
- func IsNotFoundErr(err StoreErr) bool
- func NewKeyForConfig(id string) string
- func NewKeyForEvent(id string, cfgName string) string
- func NewKeyForMachine(id string, cfgName string) string
- func NewKeyForMachinesByState(cfgName, state string) string
- func NewKeyForOutcome(id string, cfgName string) string
- type ConfigStore
- type EventStore
- type FSMStore
- type RedisStore
- func (csm *RedisStore) AddEventOutcome(id string, cfg string, response *protos.EventOutcome, ttl time.Duration) StoreErr
- func (csm *RedisStore) GetAllConfigs() []string
- func (csm *RedisStore) GetAllInState(cfg string, state string) []string
- func (csm *RedisStore) GetAllVersions(name string) []string
- func (csm *RedisStore) GetConfig(id string) (*protos.Configuration, StoreErr)
- func (csm *RedisStore) GetEvent(id string, cfg string) (*protos.Event, StoreErr)
- func (csm *RedisStore) GetOutcomeForEvent(id string, cfg string) (*protos.EventOutcome, StoreErr)
- func (csm *RedisStore) GetStateMachine(id string, cfg string) (*protos.FiniteStateMachine, StoreErr)
- func (csm *RedisStore) GetTimeout() time.Duration
- func (csm *RedisStore) Health() StoreErr
- func (csm *RedisStore) PutConfig(cfg *protos.Configuration) StoreErr
- func (csm *RedisStore) PutEvent(event *protos.Event, cfg string, ttl time.Duration) StoreErr
- func (csm *RedisStore) PutStateMachine(id string, stateMachine *protos.FiniteStateMachine) StoreErr
- func (csm *RedisStore) SetLogLevel(level slf4go.LogLevel)
- func (csm *RedisStore) SetTimeout(duration time.Duration)
- func (csm *RedisStore) TxProcessEvent(id, cfgName string, evt *protos.Event) StoreErr
- func (csm *RedisStore) UpdateState(cfgName string, id string, oldState string, newState string) StoreErr
- type StoreErr
- type StoreManager
Constants ¶
const ( ConfigsPrefix = "configs" EventsPrefix = "events" FsmPrefix = "fsm" KeyPrefixComponentsSeparator = ":" KeyPrefixIDSeparator = "#" )
const ( NeverExpire = 0 DefaultRedisDb = 0 DefaultMaxRetries = 3 DefaultTimeout = 200 * time.Millisecond ReturningItemsFmt = "Returning %d items" NoConfigurationsFmt = "Could not retrieve configurations: %s" )
Variables ¶
var ( AlreadyExistsError = Error("key %s already exists") GenericStoreError = Error("store error: %v") InvalidDataError = Error("error storing invalid data: %v") NotFoundError = Error("key %s not found") NotImplementedError = Error("functionality %s has not been implemented yet") TooManyAttempts = Error("retries exceeded") )
Functions ¶
func IsNotFoundErr ¶
func NewKeyForConfig ¶
NewKeyForConfig configs#<config:id>
By convention, the config ID is the `name:version` of the configuration; however, this is not enforced here, but rather in the implementation of the stores.
func NewKeyForEvent ¶
NewKeyForEvent events:<cfg:name>#<event:id>
func NewKeyForMachine ¶
NewKeyForMachine fsm:<cfg:name>#<machine:id>
func NewKeyForMachinesByState ¶
NewKeyForMachinesByState fsm:<cfg:name>:state#<state>
func NewKeyForOutcome ¶
NewKeyForOutcome events:<cfg:name>:outcome#<event:id>
Types ¶
type ConfigStore ¶
type ConfigStore interface { GetConfig(versionId string) (*protos.Configuration, StoreErr) PutConfig(cfg *protos.Configuration) StoreErr // GetAllConfigs returns all the `Configurations` that exist in the store, regardless of // the version, and whether they are used or not by an FSM. GetAllConfigs() []string // GetAllVersions returns the full `name:version` ID of all the Configurations whose // name matches `name`. GetAllVersions(name string) []string }
type EventStore ¶
type EventStore interface { GetEvent(id string, cfg string) (*protos.Event, StoreErr) PutEvent(event *protos.Event, cfg string, ttl time.Duration) StoreErr // AddEventOutcome adds the outcome of an event to the storage, given the `eventId` and the // "type" (`Configuration.Name`) of the FSM that received the event. // // Optionally, it will remove the outcome after a given `ttl` (time-to-live); use // `NeverExpire` to keep the outcome forever. AddEventOutcome(eventId string, cfgName string, response *protos.EventOutcome, ttl time.Duration) StoreErr // GetOutcomeForEvent returns the outcome of an event, given the `eventId` and the "type" of the // FSM that received the event. GetOutcomeForEvent(eventId string, cfgName string) (*protos.EventOutcome, StoreErr) }
type FSMStore ¶
type FSMStore interface { // GetStateMachine will find the FSM with `id and that is configured via a `Configuration` whose // `name` matches `cfg` (without the `version`). GetStateMachine(id string, cfg string) (*protos.FiniteStateMachine, StoreErr) // PutStateMachine creates or updates the FSM whose `id` is given. // No further action is taken: no check that the referenced `Configuration` exists, and the // `state` SETs are not updated either: it is the caller's responsibility to call the // `UpdateState` method (possibly with an empty `oldState`, in the case of creation). PutStateMachine(id string, fsm *protos.FiniteStateMachine) StoreErr // GetAllInState looks up all the FSMs that are currently in the given `state` and // are configured with a `Configuration` whose name matches `cfg` (regardless of the // configuration's version). // // It returns the IDs for the FSMs. GetAllInState(cfg string, state string) []string // UpdateState will move the FSM's `id` from/to the respective Redis SETs. // // When creating or updating an FSM with `PutStateMachine`, the state SETs are not // modified; it is the responsibility of the caller to manage the FSM state appropriately // (or not, as the case may be). // // `oldState` may be empty in the case of a new FSM being created. UpdateState(cfgName string, id string, oldState string, newState string) StoreErr // TxProcessEvent processes an Event for the FSM in a transaction, guaranteeing that // there will be no races when updating the FSM state. TxProcessEvent(id, cfgName string, evt *protos.Event) StoreErr }
type RedisStore ¶
type RedisStore struct { Timeout time.Duration MaxRetries int // contains filtered or unexported fields }
func (*RedisStore) AddEventOutcome ¶
func (csm *RedisStore) AddEventOutcome(id string, cfg string, response *protos.EventOutcome, ttl time.Duration) StoreErr
func (*RedisStore) GetAllConfigs ¶
func (csm *RedisStore) GetAllConfigs() []string
func (*RedisStore) GetAllInState ¶
func (csm *RedisStore) GetAllInState(cfg string, state string) []string
func (*RedisStore) GetAllVersions ¶
func (csm *RedisStore) GetAllVersions(name string) []string
func (*RedisStore) GetConfig ¶
func (csm *RedisStore) GetConfig(id string) (*protos.Configuration, StoreErr)
func (*RedisStore) GetOutcomeForEvent ¶
func (csm *RedisStore) GetOutcomeForEvent(id string, cfg string) (*protos.EventOutcome, StoreErr)
func (*RedisStore) GetStateMachine ¶
func (csm *RedisStore) GetStateMachine(id string, cfg string) (*protos.FiniteStateMachine, StoreErr)
func (*RedisStore) GetTimeout ¶
func (csm *RedisStore) GetTimeout() time.Duration
func (*RedisStore) Health ¶
func (csm *RedisStore) Health() StoreErr
Health checks that the cmd is ready to accept connections
func (*RedisStore) PutConfig ¶
func (csm *RedisStore) PutConfig(cfg *protos.Configuration) StoreErr
func (*RedisStore) PutStateMachine ¶
func (csm *RedisStore) PutStateMachine(id string, stateMachine *protos.FiniteStateMachine) StoreErr
func (*RedisStore) SetLogLevel ¶
func (csm *RedisStore) SetLogLevel(level slf4go.LogLevel)
SetLogLevel for RedisStore implements the Loggable interface
func (*RedisStore) SetTimeout ¶
func (csm *RedisStore) SetTimeout(duration time.Duration)
func (*RedisStore) TxProcessEvent ¶
func (csm *RedisStore) TxProcessEvent(id, cfgName string, evt *protos.Event) StoreErr
func (*RedisStore) UpdateState ¶
type StoreManager ¶
type StoreManager interface { log.Loggable ConfigStore FSMStore EventStore SetTimeout(duration time.Duration) GetTimeout() time.Duration Health() error }
func NewRedisStore ¶
func NewRedisStore(address string, isCluster bool, db int, timeout time.Duration, maxRetries int) StoreManager
NewRedisStore creates a new StoreManager backed by a Redis cmd, reachable at address, in cluster configuration if isCluster is set to true. The db value indicates which database to use.
Some store queries (typically the get and put actions) will be retried up to maxRetries times, if they time out after timeout expires. Use the [Health] function to check whether the store is reachable.
func NewRedisStoreWithDefaults ¶
func NewRedisStoreWithDefaults(address string) StoreManager
NewRedisStoreWithDefaults creates a new StoreManager backed by a Redis cmd, with all default settings, in a single node configuration.