Skip to content

Commit

Permalink
Rename serverKey to sdkKey to be consistent with other SDKs (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathannorris authored Feb 17, 2023
1 parent 2369d92 commit 2df450c
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class MyClass {
private DVCCloudClient dvcCloudClient;

public MyClass() {
dvcCloudClient = new DVCCloudClient("your_server_key");
dvcCloudClient = new DVCCloudClient("YOUR_DVC_SERVER_SDK_KEY");
}
}
```
Expand All @@ -62,7 +62,7 @@ public class MyClass {
private DVCLocalClient dvcLocalClient;

public MyClass() {
dvcLocalClient = new DVCLocalClient("your_server_key");
dvcLocalClient = new DVCLocalClient("YOUR_DVC_SERVER_SDK_KEY");
}
}
```
Expand Down
8 changes: 4 additions & 4 deletions docs/DVC.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class MyClass {
private DVCClient dvcClient;

public MyClass() {
dvcClient = new DVCClient("your_server_key");
dvcClient = new DVCClient("YOUR_DVC_SERVER_SDK_KEY");
}

public void allFeatures() {
Expand Down Expand Up @@ -61,7 +61,7 @@ public class MyClass {
private DVCClient dvcClient;

public MyClass() {
dvcClient = new DVCClient("your_server_key");
dvcClient = new DVCClient("YOUR_DVC_SERVER_SDK_KEY");
}

public void setFlag() {
Expand Down Expand Up @@ -109,7 +109,7 @@ public class MyClass {
private DVCClient dvcClient;

public MyClass() {
dvcClient = new DVCClient("your_server_key");
dvcClient = new DVCClient("YOUR_DVC_SERVER_SDK_KEY");
}

public void allVariables() {
Expand Down Expand Up @@ -148,7 +148,7 @@ public class MyClass {
private DVCClient dvcClient;

public MyClass() {
dvcClient = new DVCClient("your_server_key");
dvcClient = new DVCClient("YOUR_DVC_SERVER_SDK_KEY");
}

public void addAnEvent() {
Expand Down
2 changes: 1 addition & 1 deletion example-cloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ being used

Rerun the example after creating a feature and a variable and that will be shown

replace application.properties devcycle.serverKey with your server SDK key
replace application.properties devcycle.sdkKey with your server SDK key
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
@ConfigurationProperties(prefix = "devcycle")
public class HelloWorldConfiguration {

private String serverKey;
private String sdkKey;

@Bean("devcycleServerKey")
public String getServerKey() {
return serverKey;
@Bean("devcycleSDKKey")
public String getSdkKey() {
return sdkKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class HelloWorld {

private DVCCloudOptions dvcCloudOptions = DVCCloudOptions.builder().enableEdgeDB(false).build();

public HelloWorld(@Qualifier("devcycleServerKey") String serverKey) {
dvcCloud = new DVCCloudClient(serverKey, dvcCloudOptions);
public HelloWorld(@Qualifier("devcycleSDKKey") String sdkKey) {
dvcCloud = new DVCCloudClient(sdkKey, dvcCloudOptions);
}

@Value("${spring.application.name}")
Expand Down
2 changes: 1 addition & 1 deletion example-cloud/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ spring.thymeleaf.suffix=.html
spring.application.name=Default Flag
spring.application.oops=Default Flag when variation could not be fetched

devcycle.serverKey=your SDK Key
devcycle.sdkKey=your SDK Key
2 changes: 1 addition & 1 deletion example-local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ being used

Rerun the example after creating a feature and a variable and that will be shown

replace application.properties devcycle.serverKey with your server SDK key
replace application.properties devcycle.sdkKey with your server SDK key
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
@ConfigurationProperties(prefix = "devcycle")
public class HelloWorldConfiguration {

private String serverKey;
private String sdkKey;

@Bean("devcycleServerKey")
public String getServerKey() {
return serverKey;
@Bean("devcycleSDKKey")
public String getSdkKey() {
return sdkKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class HelloWorld {
.eventFlushIntervalMS(5000)
.build();

public HelloWorld(@Qualifier("devcycleServerKey") String serverKey) {
dvcClient = new DVCLocalClient(serverKey, dvcLocalOptions);
public HelloWorld(@Qualifier("devcycleSDKKey") String sdkKey) {
dvcClient = new DVCLocalClient(sdkKey, dvcLocalOptions);
}

@Value("${spring.application.name}")
Expand Down
2 changes: 1 addition & 1 deletion example-local/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ spring.thymeleaf.suffix=.html
spring.application.name=Default Flag
spring.application.oops=Default Flag when variation could not be fetched

devcycle.serverKey=your SDK Key
devcycle.sdkKey=your SDK Key
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public final class DVCCloudClient {

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

public DVCCloudClient(String serverKey) {
this(serverKey, DVCCloudOptions.builder().build());
public DVCCloudClient(String sdkKey) {
this(sdkKey, DVCCloudOptions.builder().build());
}

public DVCCloudClient(String serverKey, DVCCloudOptions options) {
public DVCCloudClient(String sdkKey, DVCCloudOptions options) {
this.dvcOptions = options;
api = new DVCCloudApiClient(serverKey, options).initialize();
api = new DVCCloudApiClient(sdkKey, options).initialize();
OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private DVCLocalApiClient(DVCLocalOptions options) {
.addConverterFactory(JacksonConverterFactory.create());
}

public DVCLocalApiClient(String serverKey, DVCLocalOptions options) {
public DVCLocalApiClient(String sdkKey, DVCLocalOptions options) {
this(options);
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/devcycle/sdk/server/local/api/DVCLocalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ public final class DVCLocalClient {

private EnvironmentConfigManager configManager;

private final String serverKey;
private final String sdkKey;

private EventQueueManager eventQueueManager;

public DVCLocalClient(String serverKey) {
this(serverKey, DVCLocalOptions.builder().build());
public DVCLocalClient(String sdkKey) {
this(sdkKey, DVCLocalOptions.builder().build());
}

public DVCLocalClient(String serverKey, DVCLocalOptions dvcOptions) {
public DVCLocalClient(String sdkKey, DVCLocalOptions dvcOptions) {
localBucketing.setPlatformData(PlatformData.builder().build().toString());

configManager = new EnvironmentConfigManager(serverKey, localBucketing, dvcOptions);
this.serverKey = serverKey;
configManager = new EnvironmentConfigManager(sdkKey, localBucketing, dvcOptions);
this.sdkKey = sdkKey;
try {
eventQueueManager = new EventQueueManager(serverKey, localBucketing, dvcOptions);
eventQueueManager = new EventQueueManager(sdkKey, localBucketing, dvcOptions);
} catch (Exception e) {
System.out.printf("Error creating event queue due to error: %s%n", e.getMessage());
}
Expand All @@ -47,7 +47,7 @@ public Map<String, Feature> allFeatures(User user) {
BucketedUserConfig bucketedUserConfig = null;

try {
bucketedUserConfig = localBucketing.generateBucketedConfig(serverKey, user);
bucketedUserConfig = localBucketing.generateBucketedConfig(sdkKey, user);
} catch (JsonProcessingException e) {
System.out.printf("Unable to parse JSON for allFeatures due to error: %s%n", e.getMessage());
return Collections.emptyMap();
Expand Down Expand Up @@ -87,7 +87,7 @@ public <T> Variable<T> variable(User user, String key, T defaultValue) {
.build();

try {
BucketedUserConfig bucketedUserConfig = localBucketing.generateBucketedConfig(serverKey, user);
BucketedUserConfig bucketedUserConfig = localBucketing.generateBucketedConfig(sdkKey, user);
if (bucketedUserConfig.variables.containsKey(key)) {
Variable<T> variable = bucketedUserConfig.variables.get(key);
variable.setIsDefaulted(false);
Expand Down Expand Up @@ -119,7 +119,7 @@ public Map<String, Variable> allVariables(User user) {

BucketedUserConfig bucketedUserConfig = null;
try {
bucketedUserConfig = localBucketing.generateBucketedConfig(serverKey, user);
bucketedUserConfig = localBucketing.generateBucketedConfig(sdkKey, user);
} catch (JsonProcessingException e) {
System.out.printf("Unable to parse JSON for allVariables due to error: %s%n", e.getMessage());
return Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ private DVCLocalEventsApiClient(DVCLocalOptions options) {
.addConverterFactory(JacksonConverterFactory.create());
}

public DVCLocalEventsApiClient(String serverKey, DVCLocalOptions options) {
public DVCLocalEventsApiClient(String sdkKey, DVCLocalOptions options) {
this(options);
okBuilder.addInterceptor(new AuthorizationHeaderInterceptor(serverKey));
okBuilder.addInterceptor(new AuthorizationHeaderInterceptor(sdkKey));
}

public IDVCApi initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public final class EnvironmentConfigManager {
private ProjectConfig config;
private String configETag = "";

private String serverKey;
private String sdkKey;
private int pollingIntervalMS;

public EnvironmentConfigManager(String serverKey, LocalBucketing localBucketing, DVCLocalOptions options) {
this.serverKey = serverKey;
public EnvironmentConfigManager(String sdkKey, LocalBucketing localBucketing, DVCLocalOptions options) {
this.sdkKey = sdkKey;
this.localBucketing = localBucketing;

configApiClient = new DVCLocalApiClient(serverKey, options).initialize();
configApiClient = new DVCLocalApiClient(sdkKey, options).initialize();

int configPollingIntervalMS = options.getConfigPollingIntervalMS();
pollingIntervalMS = configPollingIntervalMS >= MIN_INTERVALS_MS ? configPollingIntervalMS
Expand Down Expand Up @@ -66,7 +66,7 @@ public boolean isConfigInitialized() {
}

private ProjectConfig getConfig() throws DVCException, JsonProcessingException {
Call<ProjectConfig> config = this.configApiClient.getConfig(this.serverKey, this.configETag);
Call<ProjectConfig> config = this.configApiClient.getConfig(this.sdkKey, this.configETag);

this.config = getConfigResponse(config);
return this.config;
Expand All @@ -91,7 +91,7 @@ private ProjectConfig getConfigResponse(Call<ProjectConfig> call) throws DVCExce
ProjectConfig config = response.body();
try {
ObjectMapper mapper = new ObjectMapper();
localBucketing.storeConfig(serverKey, mapper.writeValueAsString(config));
localBucketing.storeConfig(sdkKey, mapper.writeValueAsString(config));
} catch (JsonProcessingException e) {
if (this.config != null) {
System.out.printf("Unable to parse config with etag: %s. Using cache, etag %s%n", currentETag, this.configETag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class EventQueueManager {

private LocalBucketing localBucketing;
private final String serverKey;
private final String sdkKey;
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private IDVCApi eventsApiClient;
private int eventFlushIntervalMS;
Expand All @@ -28,18 +28,18 @@ public class EventQueueManager {
private int flushEventQueueSize;
private int maxEventQueueSize;

public EventQueueManager(String serverKey, LocalBucketing localBucketing, DVCLocalOptions options) throws Exception {
public EventQueueManager(String sdkKey, LocalBucketing localBucketing, DVCLocalOptions options) throws Exception {
this.localBucketing = localBucketing;
this.serverKey = serverKey;
this.sdkKey = sdkKey;
eventFlushIntervalMS = options.getEventFlushIntervalMS();
flushEventQueueSize = options.getFlushEventQueueSize();
maxEventQueueSize = options.getMaxEventQueueSize();

eventsApiClient = new DVCLocalEventsApiClient(serverKey, options).initialize();
eventsApiClient = new DVCLocalEventsApiClient(sdkKey, options).initialize();

OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);

this.localBucketing.initEventQueue(serverKey, OBJECT_MAPPER.writeValueAsString(options));
this.localBucketing.initEventQueue(sdkKey, OBJECT_MAPPER.writeValueAsString(options));

setupScheduler();
}
Expand All @@ -64,13 +64,13 @@ public void run() {
public void flushEvents() throws Exception {
if (isFlushingEvents) return;

if (serverKey == null || serverKey.equals("")) {
if (sdkKey == null || sdkKey.equals("")) {
throw new Exception("DevCycle is not yet initialized to publish events.");
}

FlushPayload[] flushPayloads = new FlushPayload[0];
try {
flushPayloads = this.localBucketing.flushEventQueue(this.serverKey);
flushPayloads = this.localBucketing.flushEventQueue(this.sdkKey);
} catch (Exception e) {
System.out.printf("DVC Error Flushing Events: %s%n", e.getMessage());
}
Expand All @@ -82,7 +82,7 @@ public void flushEvents() throws Exception {
isFlushingEvents = true;
for (FlushPayload payload: flushPayloads) {
eventCount += payload.eventCount;
publishEvents(this.serverKey, payload);
publishEvents(this.sdkKey, payload);
}
isFlushingEvents = false;
System.out.printf("DVC Flush %d AS Events, for %d Users%n", eventCount, flushPayloads.length);
Expand All @@ -97,7 +97,7 @@ public void queueEvent(User user, Event event) throws Exception {
return;
}

this.localBucketing.queueEvent(this.serverKey, OBJECT_MAPPER.writeValueAsString(user), OBJECT_MAPPER.writeValueAsString(event));
this.localBucketing.queueEvent(this.sdkKey, OBJECT_MAPPER.writeValueAsString(user), OBJECT_MAPPER.writeValueAsString(event));
}

/**
Expand All @@ -111,24 +111,24 @@ public void queueAggregateEvent(Event event, BucketedUserConfig bucketedConfig)
}

if (bucketedConfig != null) {
this.localBucketing.queueAggregateEvent(this.serverKey, OBJECT_MAPPER.writeValueAsString(event), OBJECT_MAPPER.writeValueAsString(bucketedConfig.variableVariationMap));
this.localBucketing.queueAggregateEvent(this.sdkKey, OBJECT_MAPPER.writeValueAsString(event), OBJECT_MAPPER.writeValueAsString(bucketedConfig.variableVariationMap));
} else {
this.localBucketing.queueAggregateEvent(this.serverKey, OBJECT_MAPPER.writeValueAsString(event), "{}");
this.localBucketing.queueAggregateEvent(this.sdkKey, OBJECT_MAPPER.writeValueAsString(event), "{}");
}
}

private void publishEvents(String serverKey, FlushPayload flushPayload) throws InterruptedException {
private void publishEvents(String sdkKey, FlushPayload flushPayload) throws InterruptedException {
Thread publishEventsThread = new Thread(new Runnable() {
@Override
public void run() {
Call<DVCResponse> response = eventsApiClient.publishEvents(EventsBatch.builder().batch(flushPayload.records).build());
int responseCode = getResponse(response);

if (responseCode == 201) {
localBucketing.onPayloadSuccess(serverKey, flushPayload.payloadId);
localBucketing.onPayloadSuccess(sdkKey, flushPayload.payloadId);
} else {
System.out.printf("DVC Error Publishing Events: %d%n", responseCode);
localBucketing.onPayloadFailure(serverKey, flushPayload.payloadId, responseCode >= 500);
localBucketing.onPayloadFailure(sdkKey, flushPayload.payloadId, responseCode >= 500);
}
}
});
Expand Down Expand Up @@ -158,7 +158,7 @@ private int getResponse(Call call) {
* Flushes events if event queue size is equal or greater to flushEventQueueSize
*/
private boolean checkEventQueueSize() throws Exception {
int queueSize = localBucketing.getEventQueueSize(serverKey);
int queueSize = localBucketing.getEventQueueSize(sdkKey);

if (queueSize >= flushEventQueueSize) {
if (!isFlushingEvents) {
Expand Down

0 comments on commit 2df450c

Please sign in to comment.