Description
I am working on open sourcing a Kotlin Multiplatform feature flagging abstraction library which my team at work has used happily for 2+ years. Until now, it's had a tight coupling to Android and iOS clients, but in the library release I'm hoping to generalize my JVM implementation across both server and client.
The java-sdk-common
library is the exact thing I need, but it does not offer a LDClientInterface
for which I can write common code against. Instead, both the Android and the java server clients choose to declare these API surfaces in their respective package namespaces. They differ slightly, but offer some common API which could be shared across SDK clients.
My proposal is to offer an interface named CommonLDClientInterface
with the following functionality.
package com.launchdarkly.sdk;
interface CommonLDClientInterface extends Closeable {
boolean boolVariation(String flagKey, boolean defaultValue);
EvaluationDetail<Boolean> boolVariationDetail(String flagKey, boolean defaultValue);
int intVariation(String flagKey, int defaultValue);
EvaluationDetail<Integer> intVariationDetail(String flagKey, int defaultValue);
double doubleVariation(String flagKey, double defaultValue);
EvaluationDetail<Double> doubleVariationDetail(String flagKey, double defaultValue);
String stringVariation(String flagKey, String defaultValue);
EvaluationDetail<String> stringVariationDetail(String flagKey, String defaultValue);
LDValue jsonValueVariation(String flagKey, LDValue defaultValue);
EvaluationDetail<LDValue> jsonValueVariationDetail(String flagKey, LDValue defaultValue);
void registerFeatureFlagListener(String flagKey, FeatureFlagChangeListener listener);
void unregisterFeatureFlagListener(String flagKey, FeatureFlagChangeListener listener);
}
And then have each respective platform's interface extend the common one:
Android:
package com.launchdarkly.sdk.android;
import com.launchdarkly.sdk.CommonLDClientInterface;
public interface LDClientInterface extends CommonLDClientInterface { /* omitted */ }
Server:
package com.launchdarkly.sdk.server.interfaces;
import com.launchdarkly.sdk.CommonLDClientInterface;
public interface LDClientInterface extends CommonLDClientInterface { /* omitted */ }
My motivation for this feature is that the Kotlin Multiplatform Android integration is in a slight amount of flux. Ownership of the android multiplatform target is being transferred from the Kotlin team at Jetbrain to the Android team at Google. The benefit of this request is not just code de-duplication between JVM and Android, but also API stability in my library since I am not required to use the Android target.
Currently, it doesn't look like the JVM server client API supports registering feature change change listeners like the Android client does, but perhaps this is possible. It seems like a hook into InMemoryDataStore#upsert could be written to notify listeners similar to how the Android client works. Aside from my use case, this could be useful for persistent server endpoints, like websockets and HTTP server sent events.
I want to reiterate though that this request is limited to simply offering an interface with the above functionality.