Class Monitor
Namespace: Keychain
#include "keychain/monitor/monitor.hpp"
Inheritance: monitor
Definition
Monitor
subscribes to block updates from the blockchain and updates the database cache state of Persona
and Contacts
accordingly. Monitor
updates attributes such as number of confirmations, public keys and metadata, certificate transaction data. A thread for monitoring the blockchain state is created in the on_start()
method.
Monitor method names should be read as "what the Monitor should do in response to the underlying execution environment entering the specified state". For instance, you should call on_start() once your activity/application has been started. Specifically, note that the Monitor thread is not started during on_start(); it is merely created during that method. This is because some execution environments (namely mobile device environments) prefer to decouple the creation and start states of applications and intend the start process to be as lightweight as possible. |
Without at least one Monitor
the gateway
will run out of sync with the blockchain and will cause the gateway
to be able to perform cryptographic operations properly on subsequent data. Thus, you should ensure that a monitor
is instantiated within the current Activity.
Constructors
Monitor(std::string db_path,
std::string config_file,
std::string drop_sql_file,
std::string create_sql_file); (1)
Parameters
Parameter | Description |
---|---|
std::string db_path |
File path of the Keychain database |
std::string config_path |
File path of the Keychain configuration file |
std::string drop_sql_path |
File path of the Keychain database schema migration cleanup script |
std::string create_sql_path |
File path of the Keychain database schema migration script |
Method Summary
Return type | Method and Description |
---|---|
|
Pause the monitor thread. |
|
Run/resume the monitor thread. |
|
Create the monitor thread. |
|
Stop and destroy the monitor thread. |
Methods
on_pause() Method
kc::code on_pause();
Block the monitor thread if it was unblocked and running. The thread will remain blocked until on_resume() is called.
on_resume() Method
kc::code on_resume();
This method starts/unblocks the monitor thread if it was blocked or not running. If the thread does not exist upon calling on_resume(), on_resume() will call on_start() to create the thread. The thread will remain running until on_pause() is called.
on_stop() Method
kc::code on_stop();
Destroy the monitor thread if it exists. If the thread is running upon entry in this method, this method will (safely) cause the thread to stop execution before destroying the thread.
As of this version of the library, the worst-case complexity of the stopping process is linear in the number of blockchain certificates and addresses that exist in the database. We expect to reduce this to logarithmic if not constant time in a subsequent release. Until then, some environments (particularly mobile environments) may incur delays in switching activity/application contexts during long-running and stress-test scenarios. |