Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 55fafbb

Browse files
authored
Merge pull request #102 from samhaldane/master
Only log a warn on the first event that overflows the event buffer.
2 parents c40b53a + 823c686 commit 55fafbb

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/main/java/com/launchdarkly/client/LDClient.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.concurrent.Future;
2121
import java.util.concurrent.TimeUnit;
2222
import java.util.concurrent.TimeoutException;
23+
import java.util.concurrent.atomic.AtomicBoolean;
2324
import java.util.jar.Attributes;
2425
import java.util.jar.Manifest;
2526

@@ -38,6 +39,8 @@ public class LDClient implements LDClientInterface {
3839
private final EventProcessor eventProcessor;
3940
private UpdateProcessor updateProcessor;
4041

42+
private final AtomicBoolean eventCapacityExceeded = new AtomicBoolean(false);
43+
4144
/**
4245
* Creates a new client instance that connects to LaunchDarkly with the default configuration. In most
4346
* cases, you should use this constructor.
@@ -134,10 +137,7 @@ public void track(String eventName, LDUser user, JsonElement data) {
134137
if (user == null || user.getKey() == null) {
135138
logger.warn("Track called with null user or null user key!");
136139
}
137-
boolean processed = eventProcessor.sendEvent(new CustomEvent(eventName, user, data));
138-
if (!processed) {
139-
logger.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.");
140-
}
140+
sendEvent(new CustomEvent(eventName, user, data));
141141
}
142142

143143
/**
@@ -167,21 +167,24 @@ public void identify(LDUser user) {
167167
if (user == null || user.getKey() == null) {
168168
logger.warn("Identify called with null user or null user key!");
169169
}
170-
boolean processed = eventProcessor.sendEvent(new IdentifyEvent(user));
171-
if (!processed) {
172-
logger.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.");
173-
}
170+
sendEvent(new IdentifyEvent(user));
174171
}
175172

176173
private void sendFlagRequestEvent(String featureKey, LDUser user, JsonElement value, JsonElement defaultValue, Integer version) {
177174
if (isOffline()) {
178175
return;
179176
}
180-
boolean processed = eventProcessor.sendEvent(new FeatureRequestEvent(featureKey, user, value, defaultValue, version, null));
181-
if (!processed) {
177+
sendEvent(new FeatureRequestEvent(featureKey, user, value, defaultValue, version, null));
178+
NewRelicReflector.annotateTransaction(featureKey, String.valueOf(value));
179+
}
180+
181+
private void sendEvent(Event event) {
182+
boolean processed = eventProcessor.sendEvent(event);
183+
if (processed) {
184+
eventCapacityExceeded.compareAndSet(true, false);
185+
} else if (eventCapacityExceeded.compareAndSet(false, true)) {
182186
logger.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.");
183187
}
184-
NewRelicReflector.annotateTransaction(featureKey, String.valueOf(value));
185188
}
186189

187190
/**

0 commit comments

Comments
 (0)