Class HeadBasedSamplingPolicy

java.lang.Object
com.tnsai.quality.sampling.HeadBasedSamplingPolicy
All Implemented Interfaces:
EventSamplingPolicy

public final class HeadBasedSamplingPolicy extends Object implements EventSamplingPolicy
Coin-flip-per-event sampling at a fixed rate (issue #82). Each call to sample(com.tnsai.quality.sampling.SamplingInput) draws a fresh random and captures with probability rate; otherwise drops.

Pros: trivially fast (single double comparison + RNG draw), stateless, requires no per-event coordination across threads. Cons: no per-session affinity (a captured chat can have some chunks captured and others not — tail-based sampling is the answer when that matters; out of scope here).

Captured events are returned as SamplingDecision.CaptureDownsampled with the configured rate so downstream aggregators can extrapolate volume correctly.

Since:
0.5.0 (issue #82)
  • Constructor Details

    • HeadBasedSamplingPolicy

      public HeadBasedSamplingPolicy(double rate)
      Parameters:
      rate - fraction in (0, 1]. 1.0 = capture all (functionally equivalent to AlwaysCapturePolicy but with a downsampled marker still emitted — use AlwaysCapturePolicy instead when you don't want the marker).
  • Method Details