Comments (4)
I'm not sure which part of the code you were looking at, but that's not quite accurate. Please look at LDClient.java:270 and you will see that it conditionally blocks if the startWait
configuration property (described here) is greater than zero. If you have set startWait
to zero, then the LDClient
constructor is guaranteed to return immediately.
The advantage to doing it this way is that then you have an LDClient
object which, even if it is not yet finished initializing, can be inspected to see its status, or to do other things like sending analytics events or setting listeners for notifications. If we returned a Future
, then you would have no way to access the LDClient
at all until it was finished.
Once you have that object, assuming you do want to wait at some point for client initialization (since trying to evaluate flags will fail if it has not yet acquired the flag data), the method for that is client.getDataSourceStatusProvider().waitFor()
.
from java-server-sdk.
Thanks!
startWait=0
should do the trick, however there after you still would need to use blocking waitFor()
, is there anything better that supports asynchrony?
from java-server-sdk.
@t3hnar Currently there is not, but it's trivial in Java to spin a thread for such a task. One way to do that would look like this:
final CompletableFuture<Boolean> clientInitialization = new CompletableFuture<>();
new Thread(() -> {
boolean result = client.getDataSourceStatusProvider()
.waitFor(DataSourceStatusProvider.State.VALID, Duration.ZERO);
clientInitialization.complete(result);
}).start();
There are two main reasons why we haven't implemented more asynchronous APIs in the Java SDK already. The main one is simply that we hadn't had any requests for them in the last two years (and prior to two years ago, we couldn't use most of the Future
mechanisms anyway because we still had to maintain compatibility with Java 7). The closest we've had was a request to rewrite the whole SDK to use one specific reactive Java framework, which we're unlikely to do. And in a server-side context, it's unsurprising that a lot of application developers were fine with using synchronous semantics for this one-time action of initializing the SDK during startup... but everyone has their own use cases which are hard to anticipate.
The other is that, unlike other platforms where there is a standard way to do asynchronous tasks and/or to manage thread pools, Java provides the building blocks but leaves a lot of leeway as to how you want those things to work, and it is tricky for library code to anticipate what will make sense for the application calling it. For instance, any caller who receives a Future
can configure it with CompletionStage
callbacks that could execute either on another worker thread or on the same thread that called complete
on the Future
, and the latter would be one of the SDK's core processing threads, which would be undesirable. That might still be a risk we decide is worthwhile with adequate documentation, but it does mean that some extra thought needs to go into the API design.
from java-server-sdk.
Thanks for an example and comprehensive reply :)
For us async api would be preferable as well as ability to control both CPU intensive and blocking ops thread pools to be used by the client.
Not a blocker though…
from java-server-sdk.
Related Issues (20)
- Getting numerous Error posting diagnostic event (giving up permanently): HTTP error 401 (invalid SDK key) HOT 2
- Synk reports the low version of okHttp3 dependency HOT 3
- Vulnerability in snakeyaml HOT 3
- LaunchDarkly Client initialing failed even add LaunchDarkly Certificate to java key store. HOT 9
- Add shaded libraries as dependencies to `-thin` jar HOT 2
- `isInitialized` & `dataStore.isInitialized()` HOT 3
- fat jar brings in duplicate copy of `launchdarkly-logging` HOT 3
- Allow lazily computed defaultValues in LDClient to improve code readability HOT 6
- java-server-sdk is vulnerable to CVE-2022-1471 RCE HOT 3
- Builder object is not exist in V6 but is taken as an example in the docs HOT 6
- Evaluation can throw when the same segment is used in multiple rules within a single flag HOT 6
- StreamClosedByServerException: Stream closed by server HOT 13
- Vulnerability CVE-2022-1471 is introduced via SnakeYaml 1.32. Upgrading to 2.0 should fix it. HOT 3
- Have a robust in memory datastore fallback when the persistent data store connection is not working HOT 2
- update to guava 32.0.0 to resolve CVE-2023-2976 HOT 6
- ApiException.getMessage throws NullPointerException when IOException occurs HOT 1
- Stream continuously reset HOT 2
- Support for use of java-server-sdk library in GraalVM native image applications HOT 8
- `launchdarkly-java-server-sdk:6.3.0` : causing LdFeatureFlagClient not initialized after '10' seconds! Until we restart the machine intermittently. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-server-sdk.