LokAccessExecutor

Inherits:

The LokAccessExecutor class separates accesses to another Thread.

Description

The LokAccessExecutor class is responsible for managing and separating the execution of access methods to another Thread, so that those operations don’t block the main flow of the program.

Version: 1.0.0 Author: Daniel Sousa (github.com/nadjiel <github.com/nadjiel>_)

Property Index

Type

Name

Default value

LokAccessStrategy

access_strategy

null

Mutex

_mutex

new()

Semaphore

_semaphore

new()

Thread

_thread

new()

bool

_exit_executor

false

:ref:`LokAccessOperation <LokAccessOperation>`[]

_queued_operations

[]

LokAccessOperation

_current_operation

null

Method Index

Signal Descriptions

operation_started(StringName operation)

The operation_started signal is emitted when an operation starts. The operation that started is passed along in the operation parameter.

operation_finished(Dictionary result, StringName operation)

The operation_finished signal is emitted when an operation finishes. The result of the operation and the operation itself are passed along in the result and operation parameters.

Property Descriptions

LokAccessStrategy access_strategy = null

The access_strategy property stores the LokAccessStrategy that this LokAccessExecutor uses to manipulate data.

Mutex _mutex = new()

The _mutex property stores a Mutex that helps controlling access to this LokAccessExecutor’s properties by multiple :ref:`Thread <Thread>`s.

Semaphore _semaphore = new()

The _semaphore property stores a Semaphore that controls the flow of the _thread of this LokAccessExecutor.

Thread _thread = new()

The _thread property stores a Thread that executes all the heavy operation codes that this LokAccessExecutor must execute.

bool _exit_executor = false

The _exit_executor property stores a bool indicating if the execution of the _thread should stop.

LokAccessOperation <LokAccessOperation>`[] _queued_operations = ``[]`

The _queued_operations property stores an Array of LokAccessOperation becomes free to execute them.

LokAccessOperation _current_operation = null

The _current_operation property stores the current LokAccessOperation that is being executed by this LokAccessExecutor.

Method Descriptions

void finish_execution()

The finish_execution method finishes the execution of this LokAccessExecutor’s _thread by setting the _exit_executor property to false and awaiting the _thread finish.

bool has_queued_operations()

The has_queued_operations method returns a bool indicating if the _queued_operations has any operations queued.

bool has_current_operation()

The has_current_operation method returns a bool indicating if the _current_operation has an operation.

bool is_busy()

The has_current_operation method returns a bool indicating if this LokAccessExecutor is currently busy with a _current_operation or will be busy with one of the _queued_operations.

Dictionary request_get_file_ids(String files_path)

The request_get_file_ids method queues an operation of getting the saved files’ ids to be executed by this LokAccessExecutor the sooner the possible. The parameters of this method and its return are the same of the LokAccessStrategy.get_saved_files_ids, with the exception that this method is asynchronous.

Dictionary request_saving(String file_path, String file_format, Dictionary data, bool replace = false)

The request_saving method queues a saving operation to be executed by this LokAccessExecutor the sooner the possible. The parameters of this method and its return are the same of the LokAccessStrategy.save_data, with the exception that this method is asynchronous.

Dictionary request_loading(String file_path, String file_format, String <String>`[] partition_ids = ``[]`, String <String>`[] accessor_ids = ``[]`, String <String>`[] version_numbers = ``[]`)

The request_loading method queues a loading operation to be executed by this LokAccessExecutor the sooner the possible. The parameters of this method and its return are the same of the LokAccessStrategy.load_data, with the exception that this method is asynchronous.

Dictionary request_removing(String file_path, String file_format, String <String>`[] partition_ids = ``[]`, String <String>`[] accessor_ids = ``[]`, String <String>`[] version_numbers = ``[]`)

The request_removing method queues a reading operation to be executed by this LokAccessExecutor the sooner the possible. The parameters of this method and its return are the same of the LokAccessStrategy.remove_data, with the exception that this method is asynchronous.

void _start_execution()

The _start_execution method starts the execution of this LokAccessExecutor’s _thread with the _execute method.

void _execute()

The _execute method is responsible for executing the LokAccessOperation and always keep waiting for more, unless the _exit_executor is set to false.

void _queue_operation(LokAccessOperation operation)

The _queue_operation method takes a new LokAccessOperation and appends it to the _queued_operations property, so that this operation can be executed the sooner possible.

LokAccessOperation _dequeue_operation()

The _dequeue_operation method removes a LokAccessOperation from the _queued_operations property and returns it, so that it can be used for execution.

LokAccessOperation _create_operation(Callable callable)

The _create_operation method creates a new LokAccessOperation and returns it, making sure to connect its signals to the operation_started and operation_finished signals.

Dictionary _operate(Callable operation_callable)

The _operate method receives an operation_callable and creates a new LokAccessOperation, which is appended to the _queued_operations, so that the _thread can execute it in the _execute method. This method then, returns the result of the operation when it is ready by awaiting the LokAccessOperation.finished signal.

Dictionary _get_saved_files_ids(String files_path)

The _get_saved_files_ids method is responsible for using the access_strategy to get the file ids of the saved files. This method is wrapped by the request_get_file_ids method, so that it can be executed asynchronously. If you want more information about its parameters and return, see the LokAccessStrategy.get_saved_files_ids method, which has the same signature.

Dictionary _save_data(String file_path, String file_format, Dictionary data, bool replace = false)

The _save_data method is responsible for using the access_strategy to save data. This method is wrapped by the request_saving method, so that it can be executed asynchronously. If you want more information about its parameters and return, see the LokAccessStrategy.save_data method, which has the same signature.

Dictionary _load_data(String file_path, String file_format, String <String>`[] partition_ids = ``[]`, String <String>`[] accessor_ids = ``[]`, String <String>`[] version_numbers = ``[]`)

The _load_data method is responsible for using the access_strategy to load data. This method is wrapped by the request_loading method, so that it can be executed asynchronously. If you want more information about its parameters and return, see the LokAccessStrategy.load_data method, which has the same signature.

Dictionary _remove_data(String file_path, String file_format, String <String>`[] partition_ids = ``[]`, String <String>`[] accessor_ids = ``[]`, String <String>`[] version_numbers = ``[]`)

The _remove_data method is responsible for using the access_strategy to remove data. This method is wrapped by the request_removing method, so that it can be executed asynchronously. If you want more information about its parameters and return, see the LokAccessStrategy.remove_data method, which has the same signature.

void _push_error_no_access_strategy()

The _push_error_no_access_strategy method pushes an error warning that no LokAccessStrategy.