Class Monitor

Module: Keychain

Inheritance: monitor

Definition

Monitor subscribes to block updates from the blockchain and updates the database cache state of Facades 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(settings, db_path)

Parameters

Parameter Description

Settings settings

Settings object returned from gateway.init()

string db_path

File path of the Keychain database


Method Summary

Return type Method and Description

bool

on_pause()

Pause the monitor thread.

bool

on_resume()

Run/resume the monitor thread.

bool

on_start()

Create the monitor thread.

bool

on_stop()

Stop and destroy the monitor thread.


Methods

on_pause() Method

None on_pause()

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

Parameters

None

Returns

bool

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




on_resume() Method

None 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.

Parameters

None

Returns

None




on_start() Method

None on_start()

Create the monitor thread if it did not exist.

Parameters

None

Returns

None




on_stop() Method

None 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.

Parameters

None

Returns

None


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.