Class ConnectLogDebouncer

java.lang.Object
app.ductape.sdk.core.observability.ConnectLogDebouncer

public final class ConnectLogDebouncer extends Object
TS parity utility mirroring the VECTOR_LOG_DEBOUNCE_MS, GRAPH_CONNECT_LOG_DEBOUNCE_MS, and CONNECT_LOG_DEBOUNCE_MS pattern used in the TypeScript SDK to suppress duplicate connect/disconnect log rows within a short window.

Each domain instance is keyed by productTag:component:envSlug (mirroring the TS logKey convention). For each key we track the most recent emission timestamp for the initiated, success, and failed buckets; a new emission is only allowed if the previous one is older than windowMs(). The default window is 15 seconds, matching TS.

Use shouldEmit(String, Bucket) on the hot path: it both checks the window and (when true) records the new timestamp atomically.

The clock is injectable via withClock(LongSupplier) so parity tests can advance virtual time without sleeping.

  • Field Details

    • DEFAULT_WINDOW_MS

      public static final long DEFAULT_WINDOW_MS
      TS parity default window for connect/disconnect log debounce.
      See Also:
  • Constructor Details

    • ConnectLogDebouncer

      public ConnectLogDebouncer()
      Construct a debouncer with the default 15s TS window.
    • ConnectLogDebouncer

      public ConnectLogDebouncer(long windowMs)
  • Method Details

    • windowMs

      public long windowMs()
      TS parity: 15000ms by default.
    • withClock

      public ConnectLogDebouncer withClock(LongSupplier clock)
      Inject a virtual clock for parity tests; passing null resets to the system clock.
    • shouldEmit

      public boolean shouldEmit(String key, ConnectLogDebouncer.Bucket bucket)
      Returns true if a log row for (key, bucket) should be emitted now, stamps the bucket with the current time, and otherwise returns false.
    • reset

      public void reset(String key)
      Forget the most recent emissions for key (e.g. on shutdown / reset).
    • resetAll

      public void resetAll()
      Forget all emissions (e.g. between test cases).
    • key

      public static String key(String productTag, String component, String envSlug)
      TS-style logKey factory: "{product}:{component}:{env}". Callers are free to construct keys however they like; this helper documents the convention.