state

package
v1.0.7-14 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const StoreOptionsTimeoutConfigParameter = "options.timeout"

Variables

This section is empty.

Functions

func NewDefaultStateStoreFactory

func NewDefaultStateStoreFactory() *build.Factory

NewDefaultStateStoreFactory creates IStateStore components by their descriptors.

See Factory
See IStateStore
See MemoryStateStore
See NullStateStore

Types

type IStateStore

type IStateStore[T any] interface {

	// Load state from the store using its key.
	// If value is missing in the store it returns nil.
	//	Parameters:
	//		- ctx context.Context
	//		- correlationId (optional) transaction id to trace execution through call chain.
	//		- key           a unique state key.
	//	Returns: the state value or nil if value wasn't found.
	Load(ctx context.Context, correlationId string, key string) T

	// LoadBulk loads an array of states from the store using their keys.
	//	Parameters:
	//		- ctx context.Context
	//		- correlationId (optional) transaction id to trace execution through call chain.
	//		- keys          unique state keys.
	//	Returns: an array with state values and their corresponding keys.
	LoadBulk(ctx context.Context, correlationId string, keys []string) []StateValue[T]

	// Save state into the store.
	//	Parameters:
	//		- ctx context.Context
	//		- correlationId (optional) transaction id to trace execution through call chain.
	//		- key           a unique state key.
	//		- value         a state value.
	//	Returns: the state that was stored in the store.
	Save(ctx context.Context, correlationId string, key string, value T) T

	// Delete a state from the store by its key.
	//	Parameters:
	//		- ctx context.Context
	//		- correlationId (optional) transaction id to trace execution through call chain.
	//		- key           a unique value key.
	//	Returns: the state that was deleted in the store.
	Delete(ctx context.Context, correlationId string, key string) T
}

IStateStore interface for state storages that are used to store and retrieve transaction states.

type MemoryStateStore

type MemoryStateStore[T any] struct {
	// contains filtered or unexported fields
}

MemoryStateStore is a state store that keeps states in the process memory.

Configuration parameters:
	- options:
	- timeout: default caching timeout in milliseconds (default: disabled)

Example:
	store := NewMemoryStateStore[MyType]();
	value := store.Load(context.Background(), "123", "key1");
	...
	store.Save(context.Background(), "123", "key1", MyType{});

func NewEmptyMemoryStateStore

func NewEmptyMemoryStateStore[T any]() *MemoryStateStore[T]

NewEmptyMemoryStateStore creates a new instance of the state store.

func (*MemoryStateStore[T]) Configure

func (c *MemoryStateStore[T]) Configure(ctx context.Context, config *cconf.ConfigParams)

Configure component by passing configuration parameters.

Parameters:
	- ctx context.Context
	- config configuration parameters to be set.

func (*MemoryStateStore[T]) Delete

func (c *MemoryStateStore[T]) Delete(ctx context.Context, correlationId string, key string) T

Delete a state from the store by its key.

Parameters:
	- ctx context.Context
	- correlationId (optional) transaction id to trace execution through call chain.
	- key           a unique value key.
Returns: the state that was deleted in the store.

func (*MemoryStateStore[T]) Load

func (c *MemoryStateStore[T]) Load(correlationId string, key string) T

Load state from the store using its key. If value is missing in the store it returns nil.

Parameters:
	- ctx context.Context
	- correlationId (optional) transaction id to trace execution through call chain.
	- key           a unique state key.
Returns: the state value or nil if value wasn't found.

func (*MemoryStateStore[T]) LoadBulk

func (c *MemoryStateStore[T]) LoadBulk(ctx context.Context, correlationId string, keys []string) []StateValue[T]

LoadBulk loads an array of states from the store using their keys.

Parameters:
	- ctx context.Context
	- correlationId (optional) transaction id to trace execution through call chain.
	- keys          unique state keys.
Returns: an array with state values and their corresponding keys.

func (*MemoryStateStore[T]) Save

func (c *MemoryStateStore[T]) Save(ctx context.Context, correlationId string, key string, value T) T

Save state into the store.

Parameters:
	- ctx context.Context
	- correlationId (optional) transaction id to trace execution through call chain.
	- key           a unique state key.
	- value         a state value.
Returns: the state that was stored in the store.

type NullStateStore

type NullStateStore[T any] struct {
}

NullStateStore dummy state store implementation that doesn't do anything. It can be used in testing or in situations when state management is not required but shall be disabled.

func NewEmptyNullStateStore

func NewEmptyNullStateStore[T any]() *NullStateStore[T]

func (*NullStateStore[T]) Delete

func (c *NullStateStore[T]) Delete(ctx context.Context, correlationId string, key string) T

Delete a state from the store by its key.

Parameters:
	- ctx context.Context
	- correlationId (optional) transaction id to trace execution through call chain.
	- key           a unique value key.
Returns: the state that was deleted in the store.

func (*NullStateStore[T]) Load

func (c *NullStateStore[T]) Load(ctx context.Context, correlationId string, key string) T

Load state from the store using its key. If value is missing in the store it returns nil.

Parameters:
	- ctx context.Context
	- correlationId (optional) transaction id to trace execution through call chain.
	- key           a unique state key.
Returns: the state value or nil if value wasn't found.

func (*NullStateStore[T]) LoadBulk

func (c *NullStateStore[T]) LoadBulk(ctx context.Context, correlationId string, keys []string) []StateValue[T]

LoadBulk loads an array of states from the store using their keys.

Parameters:
	- ctx context.Context
	- correlationId (optional) transaction id to trace execution through call chain.
	- keys          unique state keys.
Returns: an array with state values and their corresponding keys.

func (*NullStateStore[T]) Save

func (c *NullStateStore[T]) Save(ctx context.Context, correlationId string, key string, value T) T

Save state into the store.

Parameters:
	- ctx context.Context
	- correlationId (optional) transaction id to trace execution through call chain.
	- key           a unique state key.
	- value         a state value.
Returns: the state that was stored in the store.

type StateEntry

type StateEntry[T any] struct {
	// contains filtered or unexported fields
}

StateEntry data object to store state values with their keys used by MemoryStateEntry

func NewStateEntry

func NewStateEntry[T any](key string, value T) *StateEntry[T]

NewStateEntry method creates a new instance of the state entry and assigns its values.

Parameters:
	- key   a unique key to locate the value.
	- value a value to be stored.

func (*StateEntry[T]) GetKey

func (c *StateEntry[T]) GetKey() string

GetKey method gets the key to locate the state value.

Returns the value key.

func (*StateEntry[T]) GetLastUpdateTime

func (c *StateEntry[T]) GetLastUpdateTime() int64

GetLastUpdateTime method gets the last update time.

Returns the timestamp when the value ware stored.

func (*StateEntry[T]) GetValue

func (c *StateEntry[T]) GetValue() T

GetValue method gets the sstate value.

Returns the value object.

func (*StateEntry[T]) SetValue

func (c *StateEntry[T]) SetValue(value T)

SetValue method sets a new state value.

Parameters:
	- value a new cached value.

type StateValue

type StateValue[T any] struct {
	Key   string `json:"key" bson:"key"`     // A unique state key
	Value T      `json:"value" bson:"value"` // A stored state value
}

StateValue a data object that holds a retrieved state value with its key.

Jump to

Keyboard shortcuts

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