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

Commit

Permalink
Merge pull request #144 from launchdarkly/eb/ch53906/stream-json-events
Browse files Browse the repository at this point in the history
don't use intermediate objects and reflection when encoding events to JSON
  • Loading branch information
eli-darkly authored Oct 25, 2019
2 parents 9e1602d + 90a66ef commit fdf8ea6
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 224 deletions.
17 changes: 9 additions & 8 deletions src/main/java/com/launchdarkly/client/DefaultEventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.StringWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -489,7 +490,7 @@ private static final class SendEventsTask implements Runnable {
private final BlockingQueue<FlushPayload> payloadQueue;
private final AtomicInteger activeFlushWorkersCount;
private final AtomicBoolean stopping;
private final EventOutput.Formatter formatter;
private final EventOutputFormatter formatter;
private final Thread thread;
private final SimpleDateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz"); // need one instance per task because the date parser isn't thread-safe

Expand All @@ -499,7 +500,7 @@ private static final class SendEventsTask implements Runnable {
this.sdkKey = sdkKey;
this.config = config;
this.httpClient = httpClient;
this.formatter = new EventOutput.Formatter(config.inlineUsersInEvents);
this.formatter = new EventOutputFormatter(config);
this.responseListener = responseListener;
this.payloadQueue = payloadQueue;
this.activeFlushWorkersCount = activeFlushWorkersCount;
Expand All @@ -518,9 +519,10 @@ public void run() {
continue;
}
try {
List<EventOutput> eventsOut = formatter.makeOutputEvents(payload.events, payload.summary);
if (!eventsOut.isEmpty()) {
postEvents(eventsOut);
StringWriter stringWriter = new StringWriter();
int outputEventCount = formatter.writeOutputEvents(payload.events, payload.summary, stringWriter);
if (outputEventCount > 0) {
postEvents(stringWriter.toString(), outputEventCount);
}
} catch (Exception e) {
logger.error("Unexpected error in event processor: {}", e.toString());
Expand All @@ -538,12 +540,11 @@ void stop() {
thread.interrupt();
}

private void postEvents(List<EventOutput> eventsOut) {
String json = config.gson.toJson(eventsOut);
private void postEvents(String json, int outputEventCount) {
String uriStr = config.eventsURI.toString() + "/bulk";

logger.debug("Posting {} event(s) to {} with payload: {}",
eventsOut.size(), uriStr, json);
outputEventCount, uriStr, json);

for (int attempt = 0; attempt < 2; attempt++) {
if (attempt > 0) {
Expand Down
207 changes: 0 additions & 207 deletions src/main/java/com/launchdarkly/client/EventOutput.java

This file was deleted.

Loading

0 comments on commit fdf8ea6

Please sign in to comment.