Class RemoteEvalCoordinator

java.lang.Object
growthbook.sdk.java.multiusermode.internal.RemoteEvalCoordinator

public final class RemoteEvalCoordinator extends Object
INTERNAL: not part of the supported API. Public only because GrowthBookClient lives in the parent package — treat its signatures as free to change without a major version bump. Keeps remote-evaluation fetching, caching, SSE-based cache invalidation, and per-user evaluation context creation outside of the public facade.

This is the remote-eval counterpart to GlobalContextManager/ FeatureRepositoryProvider: the GrowthBookClient facade delegates to it instead of carrying remote-eval-specific state and control flow itself.

  • Constructor Details

    • RemoteEvalCoordinator

      public RemoteEvalCoordinator(Options options, FeatureRefreshListenerRegistry refreshListeners)
      Creates a coordinator bound to the client options instance.
      Parameters:
      options - client options used to drive remote evaluation
      refreshListeners - registry used to publish SSE-driven refresh events to subscribers
  • Method Details

    • initialize

      public boolean initialize()
      Prepares the remote-eval service, cache, and (when configured) the SSE invalidation channel.
      Returns:
      true once the coordinator is ready to evaluate
    • createEvaluationContext

      public EvaluationContext createEvaluationContext(UserContext userContext)
      Creates an evaluation context for a user by fetching (or reusing a cached) remote response. Falls back to an empty local context when the remote request fails or after shutdown.
      Parameters:
      userContext - per-user evaluation context
      Returns:
      evaluation context used by feature and experiment evaluators
    • preload

      public boolean preload(UserContext userContext)
      Warms the cache for a user context without producing an evaluation context.
      Parameters:
      userContext - per-user evaluation context
      Returns:
      true when the response was fetched (or already cached)
    • refresh

      public void refresh(RequestBodyForRemoteEval requestBodyForRemoteEval) throws FeatureFetchException
      Fetches a fresh response for an explicit payload, refreshes the fallback context, and clears the cache so the next evaluation uses the latest data.
      Parameters:
      requestBodyForRemoteEval - remote evaluation request payload
      Throws:
      FeatureFetchException - when the remote request fails
    • isReady

      public boolean isReady()
      Returns:
      true once remote evaluation has been initialized and is ready to serve.
    • isCacheConfigured

      public boolean isCacheConfigured()
      Returns:
      true when a remote-eval response cache has been created.
    • fallbackFeatureCount

      public int fallbackFeatureCount()
      Returns:
      number of features in the remote-eval fallback context (0 when none).
    • invalidateCache

      public void invalidateCache()
      Drops all cached remote responses; the next evaluation refetches per user context.
    • shutdown

      public void shutdown()
      Releases the service, cache, and SSE invalidation resources owned by this coordinator.

      Synchronized on the same monitor as getService(), getCache(), and ensureReady() so teardown cannot interleave with lazy creation. In-flight callers already holding a reference are unaffected: RemoteEvalCache.get reports a closed cache as a FeatureFetchException, which callers handle as a fallback.