Skip to content

Commit d409fc7

Browse files
feat(events): make event serialization usable from another package
The Android SDK's event durability work summarizes and serializes events on the recording thread, in front of the bounded queue DefaultEventProcessor keeps. It therefore needs the summarizers and the output formatter directly, and there is no public way to hand java-sdk-internal a summary that has already been aggregated. Today the Android SDK reaches them by declaring a class in this package, which is a split package across two artifacts. Widening these five declarations lets it use its own package instead and keeps one implementation of the wire format rather than a second copy that could drift. Visibility only. No behavior changes, and every member that was package-private stays that way except the two constructors and the one method the caller needs: EventOutputFormatter class, constructor, writeOutputEvents EventSummarizerInterface interface AggregatedEventSummarizer class, constructor PerContextEventSummarizer class, constructor EventSummarizer class only, so EventSummary can be named EventSummarizer.EventSummary class only; an opaque token to a caller Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 85d1f7d commit d409fc7

5 files changed

Lines changed: 34 additions & 10 deletions

File tree

‎lib/shared/internal/src/main/java/com/launchdarkly/sdk/internal/events/AggregatedEventSummarizer.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
* Note that the methods of this class are deliberately not thread-safe, because they should
1717
* always be called from EventProcessor's single message-processing thread.
1818
*/
19-
final class AggregatedEventSummarizer implements EventSummarizerInterface {
19+
public final class AggregatedEventSummarizer implements EventSummarizerInterface {
2020
private final EventSummarizer summarizer;
2121

22-
AggregatedEventSummarizer() {
22+
/**
23+
* Creates an instance.
24+
*/
25+
public AggregatedEventSummarizer() {
2326
this.summarizer = new EventSummarizer();
2427
}
2528

‎lib/shared/internal/src/main/java/com/launchdarkly/sdk/internal/events/EventOutputFormatter.java‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,33 @@
2525
* handling of context data and private attribute redaction is implemented in EventContextFormatter
2626
* and tested in more detail in EventContextFormatterTest.
2727
*/
28-
final class EventOutputFormatter {
28+
public final class EventOutputFormatter {
2929
private final EventContextFormatter contextFormatter;
3030
private final boolean redactAnonymousAllEvents;
3131

32-
EventOutputFormatter(EventsConfiguration config) {
32+
/**
33+
* Creates an instance.
34+
*
35+
* @param config the events configuration; only the private-attribute settings affect the output
36+
*/
37+
public EventOutputFormatter(EventsConfiguration config) {
3338
this.contextFormatter = new EventContextFormatter(
3439
config.allAttributesPrivate,
3540
config.privateAttributes.toArray(new AttributeRef[config.privateAttributes.size()]));
3641
this.redactAnonymousAllEvents = config.redactAnonymousAllEvents;
3742
}
3843

39-
int writeOutputEvents(Event[] events, List<EventSummarizer.EventSummary> summaries, Writer writer) throws IOException {
44+
/**
45+
* Writes events and summaries as the JSON array that makes up a request body.
46+
*
47+
* @param events the individual events to write
48+
* @param summaries the summaries to write; empty ones are skipped
49+
* @param writer where to write the JSON
50+
* @return how many output events were written, counting each summary as one
51+
* @throws IOException if the writer failed
52+
*/
53+
public int writeOutputEvents(Event[] events, List<EventSummarizer.EventSummary> summaries, Writer writer)
54+
throws IOException {
4055
int count = 0;
4156
JsonWriter jsonWriter = new JsonWriter(writer);
4257
jsonWriter.beginArray();

‎lib/shared/internal/src/main/java/com/launchdarkly/sdk/internal/events/EventSummarizer.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* methods of this class are deliberately not thread-safe, because they should always
1515
* be called from EventProcessor's single message-processing thread.
1616
*/
17-
final class EventSummarizer {
17+
public final class EventSummarizer {
1818
private EventSummary eventsState;
1919
private final LDContext context; // nullable - only set for per-context summarization
2020

@@ -85,7 +85,10 @@ void clear() {
8585
eventsState = new EventSummary(context);
8686
}
8787

88-
static final class EventSummary {
88+
/**
89+
* A snapshot of the evaluations counted since the last reset.
90+
*/
91+
public static final class EventSummary {
8992
final Map<String, FlagInfo> counters;
9093
long startDate;
9194
long endDate;

‎lib/shared/internal/src/main/java/com/launchdarkly/sdk/internal/events/EventSummarizerInterface.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Note that implementations are deliberately not thread-safe, as they should always
1414
* be called from EventProcessor's single message-processing thread.
1515
*/
16-
interface EventSummarizerInterface {
16+
public interface EventSummarizerInterface {
1717
/**
1818
* Adds information about an evaluation to the summary.
1919
*

‎lib/shared/internal/src/main/java/com/launchdarkly/sdk/internal/events/PerContextEventSummarizer.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
* Note that the methods of this class are deliberately not thread-safe, because they should
2020
* always be called from EventProcessor's single message-processing thread.
2121
*/
22-
final class PerContextEventSummarizer implements EventSummarizerInterface {
22+
public final class PerContextEventSummarizer implements EventSummarizerInterface {
2323
private final Map<LDContext, EventSummarizer> summarizersByContext;
2424

25-
PerContextEventSummarizer() {
25+
/**
26+
* Creates an instance.
27+
*/
28+
public PerContextEventSummarizer() {
2629
this.summarizersByContext = new HashMap<>();
2730
}
2831

0 commit comments

Comments
 (0)