Class Monitor

Namespace: Keychain

Assemblies: libkeychain.dll

Inheritance: Object → 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 onStart() 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 onStart() once your activity/application has been started.

Specifically, note that the Monitor thread is not started during onStart(); 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(string dbPath,
string configFile,
string dropSqlFile,
string createSqlFile); (1)

Parameters

Parameter Description

string dbPath

File path of the Keychain database

string configPath

File path of the Keychain configuration file

string dropSqlPath

File path of the Keychain database schema migration cleanup script

string createSqlPath

File path of the Keychain database schema migration script

iRefreshable uiRefresher

Reference to object that is responsible for painting updates to the UI


Method Summary

Return type Method and Description

bool

onPause()

Pause the monitor thread.

bool

onResume()

Run/resume the monitor thread.

bool

onStart()

Create the monitor thread.

bool

onStop()

Stop and destroy the monitor thread.


Methods

onPause() Method

public int onPause();

Block the monitor thread if it was unblocked and running. The thread will remain blocked until onResume() is called.

Parameters

None

Returns

bool

true if the thread execution was blocked; otherwise, false.




onResume() Method

public int onResume();

This method starts/unblocks the monitor thread if it was blocked or not running. If the thread does not exist upon calling onResume(), onResume() will call onStart() to create the thread. The thread will remain running until onPause() is called.

Parameters

None

Returns

bool

true if the thread execution was started/unblocked; otherwise, false.




onStart() Method

public int onStart();

Create the monitor thread if it did not exist.

Parameters

None

Returns

bool

true if

  1. the thread did not exist already and was successfully created, or

  2. the thread already existed

otherwise, false.




onStop() Method

public int onStop();

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.

Parameters

None

Returns

bool

true if

  1. the thread existed and was successfully destroyed, or

  2. the thread did not exist

otherwise, false.


Thread Safety

This class is fully thread-safe; any of its methods may be invoked in multiple threads concurrently.


Idempotence

This class’s methods are idempotent.