Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

def wasmResourcePath = "$projectDir/src/main/resources"
def wasmVersion = "1.25.3"
def wasmVersion = "1.31.2"
def wasmUrl = "https://unpkg.com/@devcycle/bucketing-assembly-script@$wasmVersion/build/bucketing-lib.release.wasm"
task downloadDVCBucketingWASM(type: Download) {
src wasmUrl
Expand Down Expand Up @@ -113,7 +113,7 @@ ext {
junit_version = "4.13.2"
mockito_core_version = "5.6.0"
protobuf_version = "3.24.4"
openfeature_version = "1.7.0"
openfeature_version = "1.14.0"
eventsource_version = "4.1.1"
}

Expand Down
9 changes: 6 additions & 3 deletions src/examples/java/com/devcycle/examples/LocalExample.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.devcycle.examples;

import com.devcycle.sdk.server.common.logging.SimpleDevCycleLogger;
import com.devcycle.sdk.server.common.model.DevCycleEvent;
import com.devcycle.sdk.server.common.model.DevCycleUser;
import com.devcycle.sdk.server.local.api.DevCycleLocalClient;
import com.devcycle.sdk.server.local.model.DevCycleLocalOptions;
Expand All @@ -24,9 +25,7 @@ public static void main(String[] args) throws InterruptedException {
Boolean defaultValue = false;

DevCycleLocalOptions options = DevCycleLocalOptions.builder()
.configPollingIntervalMS(60000)
.customLogger(new SimpleDevCycleLogger(SimpleDevCycleLogger.Level.DEBUG))
.enableBetaRealtimeUpdates(true)
.build();

// Initialize DevCycle Client
Expand All @@ -50,6 +49,10 @@ public static void main(String[] args) throws InterruptedException {
} else {
System.out.println("feature is NOT enabled");
}
Thread.sleep(10000);

DevCycleEvent event = DevCycleEvent.builder().type("local-test").build();
client.track(user, event);

Thread.sleep(20000);
}
}
26 changes: 15 additions & 11 deletions src/examples/java/com/devcycle/examples/OpenFeatureExample.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.devcycle.examples;

import com.devcycle.sdk.server.common.logging.SimpleDevCycleLogger;
import com.devcycle.sdk.server.local.api.DevCycleLocalClient;
import com.devcycle.sdk.server.local.model.DevCycleLocalOptions;
import dev.openfeature.sdk.*;
Expand All @@ -15,22 +16,16 @@ public static void main(String[] args) throws InterruptedException {
System.exit(1);
}

DevCycleLocalOptions options = DevCycleLocalOptions.builder().configPollingIntervalMS(60000)
.disableAutomaticEventLogging(false).disableCustomEventLogging(false).build();
DevCycleLocalOptions options = DevCycleLocalOptions.builder()
.customLogger(new SimpleDevCycleLogger(SimpleDevCycleLogger.Level.DEBUG))
.build();

// Initialize DevCycle Client
DevCycleLocalClient devCycleClient = new DevCycleLocalClient(server_sdk_key, options);

for (int i = 0; i < 10; i++) {
if (devCycleClient.isInitialized()) {
break;
}
Thread.sleep(500);
}

// Setup OpenFeature with the DevCycle Provider
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProvider(devCycleClient.getOpenFeatureProvider());
api.setProviderAndWait(devCycleClient.getOpenFeatureProvider());

Client openFeatureClient = api.getClient();

Expand All @@ -41,7 +36,7 @@ public static void main(String[] args) throws InterruptedException {
context.add("language", "en");
context.add("country", "CA");
context.add("appVersion", "1.0.0");
context.add("appBuild", "1");
context.add("appBuild", 1.0);
context.add("deviceModel", "Macbook");

// Add Devcycle Custom Data values
Expand Down Expand Up @@ -81,5 +76,14 @@ public static void main(String[] args) throws InterruptedException {
System.out.println("Value: " + details.getValue());
System.out.println("Reason: " + details.getReason());

MutableTrackingEventDetails eventDetails = new MutableTrackingEventDetails(610.1);
eventDetails.add("test-string", "test-value");
eventDetails.add("test-number", 123.456);
eventDetails.add("test-boolean", true);
eventDetails.add("test-json", new Value(Structure.mapToStructure(defaultJsonData)));

openFeatureClient.track("test-of-event", context, eventDetails);

Thread.sleep(20000);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.devcycle.sdk.server.common.api;

import com.devcycle.sdk.server.common.exception.DevCycleException;
import com.devcycle.sdk.server.common.model.DevCycleEvent;
import com.devcycle.sdk.server.common.model.DevCycleUser;
import com.devcycle.sdk.server.common.model.Variable;
import dev.openfeature.sdk.FeatureProvider;
Expand Down Expand Up @@ -32,6 +34,8 @@ public interface IDevCycleClient {
*/
<T> Variable<T> variable(DevCycleUser user, String key, T defaultValue);

void track(DevCycleUser user, DevCycleEvent event) throws DevCycleException;

/**
* Close the client and release any resources.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public class DevCycleUser {
@JsonProperty("sdkVersion")
private String sdkVersion = getPlatformData().getSdkVersion();

@Schema(description = "DevCycle SDK Platform")
@Builder.Default
@JsonProperty("sdkPlatform")
private String sdkPlatform = null;

@Schema(description = "Hostname where the SDK is running")
@Builder.Default
@JsonProperty("hostname")
Expand Down Expand Up @@ -149,13 +154,13 @@ public static DevCycleUser fromEvaluationContext(EvaluationContext ctx) {
throw new TargetingKeyMissingError();
}

DevCycleUser user = DevCycleUser.builder().userId(userId).build();
DevCycleUser user = DevCycleUser.builder().userId(userId).sdkPlatform("java-of").build();

Map<String, Object> customData = new LinkedHashMap<>();
Map<String, Object> privateCustomData = new LinkedHashMap<>();

for (String key : ctx.keySet()) {
if (key.equals("user_id")) {
if (key.equals("user_id") || key.equals("targetingKey")) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,31 @@ public class PlatformData {
@Schema(description = "Platform the SDK is running on")
@Builder.Default
private String platform = "Java";

@Schema(description = "Version of the platform the SDK is running on")
@Builder.Default
private String platformVersion = System.getProperty("java.version");

@Schema(description = "DevCycle SDK type")
@Builder.Default
private PlatformData.SdkTypeEnum sdkType = PlatformData.SdkTypeEnum.SERVER;

@Schema(description = "DevCycle SDK Version")
@Builder.Default
private String sdkVersion = "2.5.0";

@Schema(description = "DevCycle SDK Platform")
private String sdkPlatform = null;

@Schema(description = "Hostname where the SDK is running")
private String hostname;

public PlatformData(String platform, String platformVersion, SdkTypeEnum sdkType, String sdkVersion, String hostname) {
public PlatformData(String platform, String platformVersion, SdkTypeEnum sdkType, String sdkVersion, String sdkPlatform, String hostname) {
this.platform = platform;
this.platformVersion = platformVersion;
this.sdkType = sdkType;
this.sdkVersion = sdkVersion;
this.sdkPlatform = sdkPlatform;
try {
this.hostname = hostname != null ? hostname : InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
Expand All @@ -53,6 +61,9 @@ public String toString() {
platformData.put("platformVersion", platformVersion);
platformData.put("sdkType", sdkType.toString());
platformData.put("sdkVersion", sdkVersion);
if (sdkPlatform != null) {
platformData.put("sdkPlatform", sdkPlatform);
}
platformData.put("hostname", hostname);

String platformDataString = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
public final class DevCycleLocalClient implements IDevCycleClient {

private final String sdkKey;
private final DevCycleProvider openFeatureProvider;
private final LocalBucketing localBucketing = new LocalBucketing();
private final EnvironmentConfigManager configManager;
private EventQueueManager eventQueueManager;
Expand Down Expand Up @@ -61,7 +60,6 @@ public DevCycleLocalClient(String sdkKey, DevCycleLocalOptions dvcOptions) {
} catch (Exception e) {
DevCycleLogger.error("Error creating event queue due to error: " + e.getMessage());
}
this.openFeatureProvider = new DevCycleProvider(this);
}

/**
Expand Down Expand Up @@ -249,12 +247,24 @@ public void close() {
}
}


private static DevCycleProvider openFeatureProvider = null;

/**
* @return the OpenFeature provider for this client.
*/
@Override
public FeatureProvider getOpenFeatureProvider() {
return this.openFeatureProvider;
if (openFeatureProvider == null) {
synchronized (DevCycleLocalClient.class) {
if (openFeatureProvider == null) {
openFeatureProvider = new DevCycleProvider(this);;
}
PlatformData platformData = PlatformData.builder().sdkPlatform("java-of").build();
localBucketing.setPlatformData(platformData.toString());
}
}
return openFeatureProvider;
}

@Override
Expand Down
Loading
Loading