stasher::heartbeat
objecttypedef stasher::heartbeat<application_id
,status_class
> heartbeat; typedef stasher::heartbeatptr<application_id
,status_class
> heartbeatptr; heartbeat hb_instance=heartbeat::create( ... ); // ... hb_instance::base::lock lock(*hb_instance); stasher::current_heartbeatptr<application_id
,status_class
> ptr=lock->value; if (!ptr.null()) { stasher::current_heartbeat<application_id
,status_class
> ref=ptr; stasher::current_heartbeat<application_id
,status_class
>::base::timestamps_t ×tamps=ref->timestamps; for (auto &map_entry:timestamps) { constapplication_id
&instance=map_entry.first; const stasher::heartbeat_meta_t<status_class
> &meta=map_entry.second; time_t timestamp=meta.timestamp; conststatus_class
&status=meta.second; // Unlessstatus_class
is void } }
This is a synopsis of the contents of
stasher::heartbeat
. It is based on
a versioned current object.
It is a reference-counted object.
stasher::heartbeat
defines a reference, and
stasher::heartbeatptr
is a nullable pointer reference.
Constructing an instance of the lock
acquires an
exclusive lock on the reference-counted
stasher::current_heartbeatptr
value
.
This is a nullable reference pointer.
As explained in the section called “Versioned current objects” it's null immediately
after the heartbeat object gets constructed, until the current
value of the heartbeat object gets retrieved from the object repository.
lock
acquires an exclusive lock on the object, preventing it from
getting updated by the client connection thread if the object gets updated in the
repository. The lock object must be initiated on the stack, and it
should not be held for an extensive period of time.
If it's not null, it's a stasher::current_heartbeat
,
and it contains the usual stasher uuid, maintained by the versioned current
object template, and a single member, varname
,
which is a
stasher::current_heartbeat<
.
application_id
,status_class
>::base::timestamps_t
This is a std::map
that can be iterated over,
keyed by
.
The map's value is a
application_id
stasher::heartbeat_meta_t<status_class>
which contains two members, status
, which is
application_id
's most recent posted hearbeat
status, and timestamp
, giving the time that this
posted status expires.
A void
status_class
results in a stasher::heartbeat_meta_t
with just a
timestamp
.
The heartbeat update functor gets invoked each time the manager updates the heartbeat object (and in other cases too). After constructing a new heartbeat object, the application should wait for the first call the update functor in order to read the initial heartbeat status of other application instances.
hb->admin_drop(application_id
("listener"), [] (bool success, const std::string &message) { });
admin_drop
() removes another instance's posted
status
if it is expired, but not yet stale enough to get removed.
The first parameter is an application_id
() whose
status should be removed, the second parameter is a functor.
The functor takes two arguments, a bool
and a
std::string
. The functor gets invoked when the
request gets processed. This can happen before
admin_drop
() return or after, depending on whether
the request gets immediately rejected, or not.
The bool
value indicates whether the request succeded
and the instance's status was removed, or not. In all cases, the
std::string
parameter is a descriptive message.
hb->report(std::cout);
report
() produces a summary of the current status
of the heartbeat object, and writes it to the given output stream.