Skip to content

Commit e7e3e7c

Browse files
authored
chore: update to use v2 config (#161)
* chore: update to use v2 config * chore: updated local bucketing
1 parent 6922acb commit e7e3e7c

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ sourceCompatibility = JavaVersion.VERSION_11
112112
targetCompatibility = JavaVersion.VERSION_11
113113

114114
def wasmResourcePath = "$projectDir/src/main/resources"
115-
def wasmVersion = "1.21.0"
115+
def wasmVersion = "1.25.3"
116116
def wasmUrl = "https://unpkg.com/@devcycle/bucketing-assembly-script@$wasmVersion/build/bucketing-lib.release.wasm"
117117
task downloadDVCBucketingWASM(type: Download) {
118118
src wasmUrl

src/main/java/com/devcycle/sdk/server/common/api/IDevCycleApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public interface IDevCycleApi {
6161
* @return Call<ProjectConfig>
6262
*/
6363
@Headers({"Content-Type:application/json"})
64-
@GET("config/v1/server/{sdkToken}.json")
64+
@GET("config/v2/server/{sdkToken}.json")
6565
Call<ProjectConfig> getConfig(@Path("sdkToken") String sdkToken, @Header("If-None-Match") String etag, @Header("If-Modified-Since") String lastModified);
6666

6767
/**

src/main/java/com/devcycle/sdk/server/local/api/DevCycleLocalClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.Collections;
2222
import java.util.Map;
23+
import java.util.UUID;
2324

2425
public final class DevCycleLocalClient implements IDevCycleClient {
2526

@@ -28,12 +29,14 @@ public final class DevCycleLocalClient implements IDevCycleClient {
2829
private final LocalBucketing localBucketing = new LocalBucketing();
2930
private final EnvironmentConfigManager configManager;
3031
private EventQueueManager eventQueueManager;
32+
private final String clientUUID;
3133

3234
public DevCycleLocalClient(String sdkKey) {
3335
this(sdkKey, DevCycleLocalOptions.builder().build());
3436
}
3537

3638
public DevCycleLocalClient(String sdkKey, DevCycleLocalOptions dvcOptions) {
39+
clientUUID = UUID.randomUUID().toString();
3740
if (sdkKey == null || sdkKey.equals("")) {
3841
throw new IllegalArgumentException("Missing SDK key! Call initialize with a valid SDK key");
3942
}
@@ -54,7 +57,7 @@ public DevCycleLocalClient(String sdkKey, DevCycleLocalOptions dvcOptions) {
5457
configManager = new EnvironmentConfigManager(sdkKey, localBucketing, dvcOptions);
5558
this.sdkKey = sdkKey;
5659
try {
57-
eventQueueManager = new EventQueueManager(sdkKey, localBucketing, dvcOptions);
60+
eventQueueManager = new EventQueueManager(sdkKey, localBucketing, clientUUID, dvcOptions);
5861
} catch (Exception e) {
5962
DevCycleLogger.error("Error creating event queue due to error: " + e.getMessage());
6063
}

src/main/java/com/devcycle/sdk/server/local/bucketing/LocalBucketing.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,15 @@ public synchronized byte[] getVariableForUserProtobuf(byte[] serializedParams) {
260260
return varBytes;
261261
}
262262

263-
public synchronized void initEventQueue(String sdkKey, String options) {
263+
public synchronized void initEventQueue(String sdkKey, String clientUUID, String options) {
264264
unpinAll();
265265
int sdkKeyAddress = getSDKKeyAddress(sdkKey);
266+
int clientUUIDAddress = newWasmString(clientUUID);
266267
int optionsAddress = newWasmString(options);
267268

268269
Func initEventQueuePtr = linker.get(store, "", "initEventQueue").get().func();
269-
WasmFunctions.Consumer2<Integer, Integer> fn = WasmFunctions.consumer(store, initEventQueuePtr, I32, I32);
270-
fn.accept(sdkKeyAddress, optionsAddress);
270+
WasmFunctions.Consumer3<Integer, Integer, Integer> fn = WasmFunctions.consumer(store, initEventQueuePtr, I32, I32, I32);
271+
fn.accept(sdkKeyAddress, clientUUIDAddress, optionsAddress);
271272
}
272273

273274
public synchronized void queueEvent(String sdkKey, String user, String event) {

src/main/java/com/devcycle/sdk/server/local/managers/EventQueueManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class EventQueueManager {
3434
private final int flushEventQueueSize;
3535
private final int maxEventQueueSize;
3636

37-
public EventQueueManager(String sdkKey, LocalBucketing localBucketing, DevCycleLocalOptions options) throws Exception {
37+
public EventQueueManager(String sdkKey, LocalBucketing localBucketing, String clientUUID, DevCycleLocalOptions options) throws Exception {
3838
this.localBucketing = localBucketing;
3939
this.sdkKey = sdkKey;
4040
eventFlushIntervalMS = options.getEventFlushIntervalMS();
@@ -45,7 +45,7 @@ public EventQueueManager(String sdkKey, LocalBucketing localBucketing, DevCycleL
4545

4646
OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
4747

48-
this.localBucketing.initEventQueue(sdkKey, OBJECT_MAPPER.writeValueAsString(options));
48+
this.localBucketing.initEventQueue(sdkKey, clientUUID, OBJECT_MAPPER.writeValueAsString(options));
4949

5050
setupScheduler();
5151
}

src/test/java/com/devcycle/sdk/server/local/LocalBucketingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void testStoreConfig() {
7575
public void testEventQueue() throws JsonProcessingException {
7676
DevCycleEvent event = DevCycleEvent.builder().type("test").target("target").build();
7777

78-
localBucketing.initEventQueue(apiKey, "{}");
78+
localBucketing.initEventQueue(apiKey, UUID.randomUUID().toString(),"{}");
7979

8080
// Add 2 events, aggregated by same target (should create 1 event with eventCount 2)
8181
localBucketing.queueEvent(apiKey, mapper.writeValueAsString(getUser()), mapper.writeValueAsString(event));

0 commit comments

Comments
 (0)