java-sdk icon indicating copy to clipboard operation
java-sdk copied to clipboard

Provide better mechanism for "readiness"

Open croemmich opened this issue 1 year ago • 1 comments

We're using auto-polling and want to prevent our application's readiness check from going healthy until a config has been cached. However, there's not a great way to determine that because the client becomes initialized after maxInitWaitTimeSeconds regardless of if it has fetched a config, the onClientReady hook is also fired despite having no config, and from what I can find there are no public methods to get the cached config or last refresh time from the client.

We're currently working around it by calling ConfigCatClient.forceRefresh and inspecting the result, however that creates an unnecessary network call most of the time.

It would be nice if one or more was possible:

  • Method(s) to get the cached config entry and/or json string
  • Await-able method(s) to get the cached config entry and/or json string
  • Method to get the last successful fetch time
  • New hook/change behavior to have a "ready" hook that is only fired after the client is actually ready (which to me implies it has loaded a config)

croemmich avatar May 21 '24 07:05 croemmich

Hi @croemmich, Thank you for reaching out!

I'd be moving further with the ready hook that accepts a parameter that could indicate in which state the SDK was initialized. Besides that, a method that returns a Future<InitState> that completes when the ready hook fires would also be beneficial. We have already done this in some of our other SDKs.

In other SDKs, we use these states:

  • noFlagData
  • hasLocalOverrideFlagDataOnly
  • hasCachedFlagDataOnly
  • hasUpToDateFlagData

What do you think?

z4kn4fein avatar May 22 '24 16:05 z4kn4fein

Hi @croemmich,

I wanted to let you know that we released the v9.2.0 SDK version.

This version contains the following changes you may interested in:

  • Your contribution, the ReentrantReadWriteLock replacement in the ConfigCatHooks.
  • An updated onClientReady hook has a Consumer<ClientCacheState> parameter to provide information about the client state.
  • A new waitForReadyAsync method returns a CompletableFuture<ClientCacheState>, completed when the client is initialized.

I hope these changes will help you. If you have any questions, let us know!

novalisdenahi avatar Jun 07 '24 19:06 novalisdenahi

This issue is marked stale because it has no activity in the last 3 weeks. The issue will be closed in one week. Please remove the stale flag to keep it open.

github-actions[bot] avatar Jun 29 '24 01:06 github-actions[bot]

This issue was closed due to no activity.

github-actions[bot] avatar Jul 07 '24 02:07 github-actions[bot]