Class PresenceKvMonitor

java.lang.Object
io.deephaven.enterprise.etcdclient.presence.PresenceKvMonitor

public class PresenceKvMonitor extends Object

The PresenceKvMonitor watches a KV in etcd intended as proof of presence (liveness) by another process. Updates in KV values (represented as a Map<String, String>) are passed to the user of the class to be reacted upon; the expectation is the values in the KV represent data about the watched process (eg, discovery location to talk back to it, relevant state, etc).

A presence KV is a mechanism for a process to prove its availability and readiness; the process needs to periodically renew a lease with etcd to maintain the KV which is associated to that lease; therefore, if the process stops, the lease is not refreshed and etcd will shortly (depending on lease TTL) remove the KV. See LivenessLeaseHandler for how to create an maintain a liveness lease and associated KVs.

  • Constructor Details

    • PresenceKvMonitor

      public PresenceKvMonitor(@NotNull @NotNull String logPrefix, @NotNull @NotNull com.fishlib.io.logger.Logger log, @NotNull @NotNull io.deephaven.shadow.jetcd.io.etcd.jetcd.Client client, long ttlMillis, @NotNull @NotNull io.deephaven.shadow.jetcd.io.etcd.jetcd.ByteSequence key, @NotNull @NotNull PresenceKvMonitor.PresenceKvUpdateListener presenceKvUpdateListener)

      Monitor a presence KV in etcd. The underlying implementation uses an etcd watcher to get updates for KV changes from etcd.

      Note the etcd watcher is not started until start() is called, therefore no updates will be notified to the provided listener before that point.

      Note the updates to the provided PreseceKvUpdateListener are executed over shared threads (either underlying etcd infrastructure threads or a shared timer thread). As such, is critical that the listener update call returns quickly; anything minimally computationally expensive should be done to the side, as work dispatched in a separate thread while the update call itself can return quickly.

      Parameters:
      logPrefix - a string indicating the owner, useful to distinguish difference instances in logging.
      log - the logger to use
      client - the etcd client to use
      ttlMillis - the time to live, in milliseconds
      key - the key for the etcd KV to monitor
      presenceKvUpdateListener - a listener where to dispatch notifications for state changes
  • Method Details

    • getTtlSecondsFromProperty

      public static int getTtlSecondsFromProperty(String base)
    • start

      public void start()
      Start to monitor our KV for updates.
    • ttlMillis

      public long ttlMillis()
    • closeAsync

      public void closeAsync()

      Stop this monitor. Close the underlying etcd watcher. Closing is asynchronous; calls to the update listener may happen after this method has returned.

      No calls should be made to any other methods of this class after this method is called. It is safe to call this method more than once; any subsequent calls after the first one is a no-op.