Class ExperimentTracker

java.lang.Object
growthbook.sdk.java.multiusermode.ExperimentTracker

public class ExperimentTracker extends Object
A thread-safe LRU cache deduplicating experiment-exposure events by hashAttribute + hashValue + experimentKey + variationId (the same key composition as the JavaScript and Python SDKs).

Sizing matters: the multi-user client shares ONE tracker across all users, so the bound must comfortably exceed the number of concurrently active unique exposures — an undersized LRU evicts and re-fires exposures under load. Past the bound, an evicted exposure may legitimately fire again.

  • Constructor Details

    • ExperimentTracker

      public ExperimentTracker()
      Evaluator-local tracker with the legacy 30-entry bound (single-user scope).
    • ExperimentTracker

      public ExperimentTracker(int maxSize)
      Parameters:
      maxSize - maximum tracked exposures before least-recently-used eviction; must be at least 1
      Throws:
      IllegalArgumentException - if maxSize is less than 1
  • Method Details

    • trackExperiment

      public void trackExperiment(String experimentId)
    • isExperimentTracked

      public boolean isExperimentTracked(String experimentId)
    • markIfFirst

      @Nullable public Object markIfFirst(String experimentId)
      Atomically claims an exposure for delivery: marks it tracked and reports whether this caller was the first to do so. Concurrent first evaluations of the same key on a shared tracker see exactly one claim, so the exposure is dispatched once rather than racing a separate check-then-mark.
      Parameters:
      experimentId - the dedup key to claim
      Returns:
      this caller's claim, to hand to untrack(java.lang.String, java.lang.Object) if delivery fails, or null if the key was already tracked
    • untrack

      public void untrack(String experimentId, Object claim)
      Un-marks an exposure whose delivery failed, so it is retried on the next evaluation instead of being silently lost. Only the mark made by claim is removed: if the key was evicted and claimed again while the failed delivery was still running, the newer mark stays.
      Parameters:
      experimentId - the dedup key to un-mark
      claim - the value markIfFirst(java.lang.String) returned for this delivery
    • clearTrackedExperiments

      public void clearTrackedExperiments()