public interface FlagValueChangeListener
Use this in conjunction with FlagTracker.addFlagValueChangeListener(String, com.launchdarkly.sdk.LDContext, FlagValueChangeListener)
if you want the client to re-evaluate a flag for a specific evaluation context whenever the
flag's configuration has changed, and notify you only if the new value is different from the old
value. The listener will not be notified if the flag's configuration is changed in some way that does
not affect its value for that context.
String flagKey = "my-important-flag";
LDContext contextForFlagEvaluation = LDContext.create("context-key-for-global-flag-state");
FlagValueChangeListener listenForNewValue = event -> {
if (event.getKey().equals(flagKey)) {
doSomethingWithNewValue(event.getNewValue().booleanValue());
}
};
client.getFlagTracker().addFlagValueChangeListener(flagKey,
contextForFlagEvaluation, listenForNewValue);
In the above example, the value provided in event.getNewValue()
is the result of calling
client.jsonValueVariation(flagKey, contextForFlagEvaluation, LDValue.ofNull())
after the flag
has changed.Modifier and Type | Method and Description |
---|---|
void |
onFlagValueChange(FlagValueChangeEvent event)
The SDK calls this method when a feature flag's value has changed with regard to the specified
evaluation context.
|
void onFlagValueChange(FlagValueChangeEvent event)
event
- the event parameters