Chapter 13. Heartbeat objects


Application identifiers and status template parameters
Instantiating a heartbeat class
Heartbeat updates
A heartbeat example
The contents of a stasher::heartbeat object


The stasher::heartbeat template uses a versioned current object template class to implement a design pattern for a heartbeat object for an application that runs as multiple instances; often on different nodes in the object repository cluster, but multiple instances can run on the same node too, as different processes.

Each instance of the application has a unique identifier, and a class that represents the application instance's status. Each instance posts, at regular intervals, or sooner, its current status to a shared heartbeat object in the object repository. All instances of the application update the shared heartbeat object with their status, and each posted status gets timedstamped. This serves to announce, to other instances of the application, that this instance is still running and its latest status.

The heartbeat object functions as a shared dashboard with the latest status of each instance of the application. Each application instance updates its status, and can read other instances' status.

Updates to an instance's heartbeat discontinue when the application instance terminates, of course. Naturally, a stopped instance does not get detected immediately, but only after some time elapses after its last posted status.


The heartbeat object methods described here are not thread safe in of themselves, although they employ other objects, like versioned current object, that are generally thread-safe themselves. The heartbeat object is designed to be owned by a single update thread that invokes the methods described here.