scistag.datastag.data_stag_command_handler.DataStagCommandHandler¶
- class DataStagCommandHandler(local=True)[source]¶
Bases:
DataStagConnectionMaps http calls to the server to connection function calls
Initializer
- Parameters
local (
bool) – Defines if the local connection shall be used.
Methods
Adds given value to the element stored in the database.
Converts the data to a JSON compatible representation
Implicit garbage collection request
Converts data of a binary type, e.g.
Deletes an element :type name:
str:param name: The element's name.Deletes a set of elements
Verifies if given element exists
Finds a list of elements by name
Tries to read an element from the database :type name:
str:param name: The element's name :type default:Union[str,bool,int,float,bytes,dict,list,ndarray,None] :param default: The default return value if the element does nto exist :rtype:Union[str,bool,int,float,bytes,dict,list,ndarray,None] :return: The elementTries to read an element from the database.
Returns the database status
Returns an object's update time stamp (if it was set via set_ts)
Returns the object if it was modified since timestamp :param name: The element's name :param timestamp: The previous timestamp :return: The timestamp or counter, the data on success, otherwise the old timestamp, None
Returns the data of a set of elements by name.
Execute a single remote command or list of remote commands executed in the DataVault
Converts an element converted to JSOn back to it's original type.
Tries to receive a list of elements from the vault
Tries to retrieve the data of a list
Tries to remove an element at the beginning of a list
Inserts an element at the beginning of a list
Stores a named element in the database
Stores a named element in the database and adds a timestamp to it in a neighbour entry named :timeStamp
Starts a new transaction. All write operations will be bundled and
Locks the access to the vault and bundles upcoming write events
Unlocks the access to the vault and bundles upcoming write events
Attributes
_ADVANCED_COMMAND_COMMAND_ADD_COMMAND_COLLECT_GARBAGE_COMMAND_DELETE_COMMAND_DELETE_MULTIPLE_COMMAND_EXISTS_COMMAND_FIND_COMMAND_GET_COMMAND_GET_EX_COMMAND_GET_VALUES_BY_NAME_COMMAND_LELEMENTS_COMMAND_LLEN_COMMAND_POP_COMMAND_PUSH_COMMAND_SET_COMMAND_STATUSName of a timestamp neighbour entry in which the time when an entry was written is stored
_DATA_DEFAULT_ELEMENTS_END_FLAT_INDEX_LIMIT_MASK_NAME_RECURSIVE_RELATIVE_NAMES_SEARCH_MASKS_START_TIMESTAMP_IDENTIFIER_TIME_OUT_TYPE_TYPE_BYTES_TYPE_NUMPY_VALUE_VERSION_COUNTER__dict____doc____module____weakref__list of weak references to the object (if defined)
Dictionary which maps the incoming commands to their corresponding functions
- _execute_remote(command)¶
Executes a command remotely and returns it’s result
- _handle_delete_multiple(command)[source]¶
Executes a delete_multiple command which deletes a list of values m atching a given mask
- _handle_find(command)[source]¶
Executes a find command which returns all values’ names matching a given mask
- _handle_get_ex(command)[source]¶
Executes an advanced get command which allows retrieving a value only if it changed
- _handle_get_values_by_name(command)[source]¶
Executes a get_values_by_name command which receives all values matching a given mask by name
- _handle_lelements(command)[source]¶
Executes a lelements command which receives a set of elements in a given range from a list
- _handle_pop(command)[source]¶
Executes an advanced list pop which tries to retrieve a value from a list
- _handle_status(command)[source]¶
Executes a server status request checking the server’s health status
- _verify_bool_result(result)¶
Verifies if the result is of type bool
- _verify_ct_result(result)¶
Verifies if the result is of any allowed storable type
- _verify_dict_result(result)¶
Verifies if the result is of type dict
- _verify_int_result(result)¶
Verifies if the result is of type int
- classmethod _verify_result(result, supported_types)¶
Verifies if the result is of a given type
- add(name, value=1, timeout_s=None, default=0)¶
Adds given value to the element stored in the database. If it does not exist yet, it will be initialized with default.
- Parameters
name – The element’s name
value – The value to be added. 1 by default.
timeout_s – The timeout for automatic deletion
default – The default value
- Returns
The new value
- classmethod bundle_return(data)[source]¶
Converts the data to a JSON compatible representation
- Parameters
data – The data
- Return type
- Returns
The JSON compatible dictionary
- collect_garbage()¶
Implicit garbage collection request
- Return type
- Returns
True if at least one time interval passed and something could get collected
- classmethod data_to_json(data)¶
Converts data of a binary type, e.g. np.ndarray or bytes to a JSON representation
- delete(name)¶
Deletes an element :type name:
str:param name: The element’s name. :rtype:bool:return: True on success
- delete_multiple(search_masks, recursive=False)¶
Deletes a set of elements
- exists(name)¶
Verifies if given element exists
- find(mask, limit=100, relative_names=False, recursive=False)¶
Finds a list of elements by name
- get(name, default=None)¶
Tries to read an element from the database :type name:
str:param name: The element’s name :type default:Union[str,bool,int,float,bytes,dict,list,ndarray,None] :param default: The default return value if the element does nto exist :rtype:Union[str,bool,int,float,bytes,dict,list,ndarray,None] :return: The element
- get_ex(name, default=None, version_counter=-1)¶
Tries to read an element from the database. Allows to add a version check so only data will be returned if it changed since the last get_ex. :param name: The element’s name :param default: The default return value if the element does not exist :param version_counter: If set then a value will only be returned if the element’s update counter does not match :return: The element’s version, The element
- get_status(advanced=False)¶
Returns the database status
- Parameters
advanced (
bool) – Defines if advanced details shall be received as well- Returns
A dictionary containing the status
- get_ts(name, default=0.0)¶
Returns an object’s update time stamp (if it was set via set_ts)
- get_ts_modified(name, timestamp=0.0)¶
Returns the object if it was modified since timestamp :param name: The element’s name :param timestamp: The previous timestamp :return: The timestamp or counter, the data on success, otherwise the
old timestamp, None
- get_values_by_name(mask, limit=100, flat=True)¶
Returns the data of a set of elements by name.
- Parameters
- Returns
A list containing the data and names of all valid elements
- handle_command_data(command_data)[source]¶
Execute a single remote command or list of remote commands executed in the DataVault
- classmethod json_to_data(data)¶
Converts an element converted to JSOn back to it’s original type. Special types, e.g. binary representations are flagged as those using a _TYPE and a _VALUE element in a dictionary.
- lelements(name, start=0, end=None)¶
Tries to receive a list of elements from the vault
- llen(name)¶
Tries to retrieve the data of a list
- pop(name, default=None, index=0)¶
Tries to remove an element at the beginning of a list
- push(name, data, timeout_s=None, index=-1)¶
Inserts an element at the beginning of a list
- Parameters
- Return type
- Returns
The new length of the list
- set(name, data, timeout_s=None)¶
Stores a named element in the database
- set_ts(name, data, timeout_s=None, timestamp=None)¶
Stores a named element in the database and adds a timestamp to it in a neighbour entry named :timeStamp
- Parameters
- Return type
- Returns
True on success
- start_transaction()¶
- Starts a new transaction. All write operations will be bundled and
executed in a single lock.
Use like: with my_connection.start_transaction(): … :return: The transaction object
- ts_lock(target)¶
Locks the access to the vault and bundles upcoming write events
- Parameters
target (
DataStagTransaction) – The current transaction
- ts_unlock()¶
Unlocks the access to the vault and bundles upcoming write events
- _COUNTER_IDENTIFIER = ':counter'¶
Name of a timestamp neighbour entry in which the time when an entry was written is stored
- commands: dict[str, Callable[[dict], dict]]¶
Dictionary which maps the incoming commands to their corresponding functions
- local¶
Defines if a local storage is being used
- request_client: FlaskClient¶
When testing locally this links to the local test client
- vault: DataStagVault | None¶
Link to the local data vault