Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/streaming-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {
}

dependencies {
implementation("io.getunleash:unleash-client-java:11.1.0")
implementation("com.launchdarkly:okhttp-eventsource:4.1.1")
implementation("io.getunleash:unleash-client-java:12.2.1-SNAPSHOT")
implementation("com.launchdarkly:okhttp-eventsource:4.2.0")
implementation("ch.qos.logback:logback-classic:1.5.18")
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,57 @@ public class StreamingExample {
private static Unleash unleash;

private static class StreamingEventSubscriber implements UnleashSubscriber {

@Override
public void togglesFetched(ClientFeaturesResponse toggleResponse) {
System.out.println("[STREAMING EVENT] Features updated");
if (unleash != null) {
boolean isEnabled = unleash.isEnabled("streaming_flag");
System.out.println(" streaming_flag: " + (isEnabled ? "ENABLED" : "DISABLED"));
System.out.println(
" streaming_flag: " + (isEnabled ? "ENABLED" : "DISABLED")
);
System.out.println(
" test devices flag: " + unleash.isEnabled("devices")
);
}
}

@Override
public void onError(UnleashException unleashException) {
System.err.println("[STREAMING ERROR] " + unleashException.getMessage());
System.err.println(
"[STREAMING ERROR] " + unleashException.getMessage()
);
}
}

public static void main(String[] args) {
StreamingEventSubscriber subscriber = new StreamingEventSubscriber();

UnleashConfig config =
UnleashConfig.builder()
.appName("streaming-example")
.instanceId("streaming-example-instance")
.unleashAPI(getOrElse("UNLEASH_API_URL", "https://app.unleash-hosted.com/demo/api"))
.customHttpHeader(
"Authorization",
getOrElse("UNLEASH_API_TOKEN",
"*:development.25a06b75248528f8ca93ce179dcdd141aedfb632231e0d21fd8ff349"))
.experimentalStreamingMode()
.subscriber(subscriber)
.build();
UnleashConfig config = UnleashConfig.builder()
.appName("streaming-example")
.instanceId("streaming-example-instance")
.unleashAPI(
getOrElse(
"UNLEASH_API_URL",
"https://app.unleash-hosted.com/demo/api"
)
)
.customHttpHeader(
"Authorization",
getOrElse(
"UNLEASH_API_TOKEN",
"*:development.25a06b75248528f8ca93ce179dcdd141aedfb632231e0d21fd8ff349"
)
)
.experimentalStreamingMode()
.subscriber(subscriber)
.build();

unleash = new DefaultUnleash(config);

System.out.println("Streaming client started. Waiting for events... (Press Ctrl+C to exit)");
System.out.println(
"Streaming client started. Waiting for events... (Press Ctrl+C to exit)"
);

try {
Thread.currentThread().join();
Expand All @@ -62,4 +79,4 @@ public static String getOrElse(String key, String defaultValue) {
}
return value;
}
}
}
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.unleash.specification>5.2.2</version.unleash.specification>
<version.unleash.specification>6.1.0</version.unleash.specification>
<arguments />
<version.assertj>3.27.7</version.assertj>
<version.gson>2.13.2</version.gson>
<version.jackson>2.20.1</version.jackson>
<version.junit5>5.14.0</version.junit5>
<version.logback>1.5.25</version.logback>
<version.mockito>5.20.0</version.mockito>
<version.okhttp>4.12.0</version.okhttp>
<version.okhttp>5.3.2</version.okhttp>
<version.slf4j>2.0.17</version.slf4j>
<version.wiremock>3.9.2</version.wiremock>
<version.wiremock>3.13.2</version.wiremock>
</properties>

<name>io.getunleash:unleash-client-java</name>
Expand Down Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>io.getunleash</groupId>
<artifactId>yggdrasil-engine</artifactId>
<version>0.5.1</version>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand All @@ -70,14 +70,14 @@
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<artifactId>okhttp-jvm</artifactId>
<version>${version.okhttp}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.launchdarkly</groupId>
<artifactId>okhttp-eventsource</artifactId>
<version>4.1.1</version>
<version>4.2.0</version>
</dependency>

<dependency>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/getunleash/DefaultUnleash.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ public List<EvaluatedToggle> evaluateAllToggles(UnleashContext context) {
UnleashContext enhancedContext = context.applyStaticFields(config);
FlatResponse<VariantDef> response =
featureRepository.getVariant(toggleName, enhancedContext);
Optional<VariantDef> variantDef = Optional.of(response.value);
Optional<VariantDef> variantDef =
Optional.ofNullable(response).map(r -> r.value);
Variant variant =
YggdrasilAdapters.adapt(variantDef, DISABLED_VARIANT);
return new EvaluatedToggle(
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/io/getunleash/metric/OkHttpMetricsSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.*;

public class OkHttpMetricsSender implements MetricSender {
private final UnleashConfig config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public FeatureRepositoryImpl(UnleashConfig unleashConfig, UnleashEngine engine)

private void initCollections(UnleashScheduledExecutor executor) {
Optional<String> features = this.featureBackupHandler.read();
if (!features.isPresent() && this.bootstrapper != null) {
if (features.isEmpty() && this.bootstrapper != null) {
features = this.bootstrapper.read();
}
if (features.isPresent()) {
Expand Down
Loading