pip_services3_components.state package

Submodules

Module contents

class pip_services3_components.state.DefaultStateStoreFactory

Bases: pip_services3_components.build.Factory.Factory

Creates IStateStore components by their descriptors.

See: Factory, IStateStore, MemoryStateStore, NullStateStore

MemoryStateStoreDescriptor = <pip_services3_commons.refer.Descriptor.Descriptor object>
NullStateStoreDescriptor = <pip_services3_commons.refer.Descriptor.Descriptor object>
descriptor = <pip_services3_commons.refer.Descriptor.Descriptor object>
class pip_services3_components.state.IStateStore

Bases: abc.ABC

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

abstract delete(correlation_id: Optional[str], key: str) → Any

Deletes a state from the store by its key.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • key – a unique value key.

Returns

deleted item

abstract load(correlation_id: Optional[str], key: str) → Any

Loads state from the store using its key. If value is missing in the store it returns None.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • key – a unique state key.

Returns

the state value or None if value wasn’t found.

abstract load_bulk(correlation_id: Optional[str], keys: List[str]) → List[pip_services3_components.state.StateValue.StateValue]

Loads an array of states from the store using their keys.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • keys – unique state keys.

Returns

an array with state values and their corresponding keys.

abstract save(correlation_id: Optional[str], key: str, value: Any) → Any

Saves state into the store.

Parameters
  • correlation_id – (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.

class pip_services3_components.state.MemoryStateStore

Bases: pip_services3_components.state.IStateStore.IStateStore, pip_services3_commons.config.IReconfigurable.IReconfigurable

State store that keeps states in the process memory.

Remember: This implementation is not suitable for synchronization of distributed processes.

### Configuration parameters ###

__options:__ - timeout: default caching timeout in milliseconds (default: disabled)

See: ICache

Example:

store = MemoryStateStore()

value = store.load("123", "key1")
...
store.save("123", "key1", "ABC")
configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)

Configures component by passing configuration parameters.

Parameters

config – configuration parameters to be set.

delete(correlation_id: Optional[str], key: str) → Any

Deletes a state from the store by its key.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • key – a unique state key.

Returns

deleted item

load(correlation_id: Optional[str], key: str) → Any

Loads stored value from the store using its key. If value is missing in the store it returns None.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • key – a unique state key.

Returns

the state value or None if value wasn’t found.

load_bulk(correlation_id: Optional[str], keys: List[str]) → List[pip_services3_components.state.StateValue.StateValue]

Loads an array of states from the store using their keys.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • keys – unique state keys.

Returns

an array with state values.

save(correlation_id: Optional[str], key: str, value: Any) → Any

Saves state into the store

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • key – a unique state key.

  • value – a state value to store.

Returns

The value that was stored in the cache.

class pip_services3_components.state.NullStateStore

Bases: pip_services3_components.state.IStateStore.IStateStore

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.

See: ICache

delete(correlation_id: Optional[str], key: str) → Any

Deletes a state from the store by its key.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • key – a unique value key.

Returns

deleted item

load(correlation_id: Optional[str], key: str) → Any

Loads state from the store using its key. If value is missing in the stored it returns None.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • key – a unique state key.

Returns

the state value or None if value wasn’t found.

load_bulk(correlation_id: Optional[str], keys: List[str]) → List[pip_services3_components.state.StateValue.StateValue]

Loads an array of states from the store using their keys.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • keys – unique state keys.

Returns

an array with state values and their corresponding keys.

save(correlation_id: Optional[str], key: str, value: Any) → Any

Saves state into the store.

Parameters
  • correlation_id – (optional) transaction id to trace execution throug

  • key – a unique state key.

  • value – a state value.

Returns

The state that was stored in the store.

class pip_services3_components.state.StateEntry(key: str, value: Any)

Bases: object

Data object to store state values with their keys used by MemoryStateStore

get_key()str

Gets the key to locate the state value.

Returns

the value key.

get_last_update_time()int

Gets the last update time.

Returns

the timestamp when the value ware stored.

get_value()

Gets the sstate value.

Returns

the value object.

set_value(value: Any)

Sets a new state value.

Parameters

value – a new cached value.

class pip_services3_components.state.StateValue(key: str = None, value: Any = None)

Bases: object