Skip to content

Commit 6c244fa

Browse files
committed
Minor code cleanup.
1 parent 3a0f579 commit 6c244fa

File tree

3 files changed

+40
-45
lines changed

3 files changed

+40
-45
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99

1010
/**
1111
* Aggregates events from all contexts into a single summary event.
12-
* This provides a unified interface for both aggregated and per-context summarization,
13-
* eliminating conditional branching in the event processor.
1412
* <p>
1513
* This implementation combines all flag evaluations across all contexts into one
16-
* summary event (without context information), which is the traditional behavior.
14+
* summary event (without context information), which is the behavior for server-side SDKs.
1715
* <p>
1816
* Note that the methods of this class are deliberately not thread-safe, because they should
1917
* always be called from EventProcessor's single message-processing thread.
@@ -27,13 +25,13 @@ final class AggregatedEventSummarizer implements EventSummarizerInterface {
2725

2826
@Override
2927
public void summarizeEvent(
30-
long timestamp,
31-
String flagKey,
32-
int flagVersion,
33-
int variation,
34-
LDValue value,
35-
LDValue defaultValue,
36-
LDContext context
28+
long timestamp,
29+
String flagKey,
30+
int flagVersion,
31+
int variation,
32+
LDValue value,
33+
LDValue defaultValue,
34+
LDContext context
3735
) {
3836
summarizer.summarizeEvent(timestamp, flagKey, flagVersion, variation, value, defaultValue, context);
3937
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ interface EventSummarizerInterface {
1717
/**
1818
* Adds information about an evaluation to the summary.
1919
*
20-
* @param timestamp the millisecond timestamp
21-
* @param flagKey the flag key
22-
* @param flagVersion the flag version, or -1 if the flag is unknown
23-
* @param variation the result variation, or -1 if none
24-
* @param value the result value
20+
* @param timestamp the millisecond timestamp
21+
* @param flagKey the flag key
22+
* @param flagVersion the flag version, or -1 if the flag is unknown
23+
* @param variation the result variation, or -1 if none
24+
* @param value the result value
2525
* @param defaultValue the application default value
26-
* @param context the evaluation context
26+
* @param context the evaluation context
2727
*/
2828
void summarizeEvent(
29-
long timestamp,
30-
String flagKey,
31-
int flagVersion,
32-
int variation,
33-
LDValue value,
34-
LDValue defaultValue,
35-
LDContext context
29+
long timestamp,
30+
String flagKey,
31+
int flagVersion,
32+
int variation,
33+
LDValue value,
34+
LDValue defaultValue,
35+
LDContext context
3636
);
3737

3838
/**
@@ -44,7 +44,7 @@ void summarizeEvent(
4444

4545
/**
4646
* Restores the summarizer state from a previous snapshot. This is used when a flush
47-
* operation fails and we need to keep the summary data for the next attempt.
47+
* operation fails, and we need to keep the summary data for the next attempt.
4848
*
4949
* @param previousSummaries the list of summaries to restore
5050
*/

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

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/**
1212
* Generates separate summary events per context. Maintains separate EventSummarizer instances
1313
* for each unique context, allowing generation of multiple summary events per flush interval.
14+
* This implementation is intended for use by client-side SDKs.
1415
* <p>
1516
* This implementation creates one summary event per context, each including the context
1617
* information, enabling "who got what when" analytics.
@@ -28,30 +29,26 @@ final class PerContextEventSummarizer implements EventSummarizerInterface {
2829
/**
2930
* Adds information about an evaluation to the appropriate context's summarizer.
3031
*
31-
* @param timestamp the millisecond timestamp
32-
* @param flagKey the flag key
33-
* @param flagVersion the flag version, or -1 if the flag is unknown
34-
* @param variation the result variation, or -1 if none
35-
* @param value the result value
32+
* @param timestamp the millisecond timestamp
33+
* @param flagKey the flag key
34+
* @param flagVersion the flag version, or -1 if the flag is unknown
35+
* @param variation the result variation, or -1 if none
36+
* @param value the result value
3637
* @param defaultValue the application default value
37-
* @param context the evaluation context
38+
* @param context the evaluation context
3839
*/
3940
@Override
4041
public void summarizeEvent(
41-
long timestamp,
42-
String flagKey,
43-
int flagVersion,
44-
int variation,
45-
LDValue value,
46-
LDValue defaultValue,
47-
LDContext context
48-
) {
42+
long timestamp,
43+
String flagKey,
44+
int flagVersion,
45+
int variation,
46+
LDValue value,
47+
LDValue defaultValue,
48+
LDContext context
49+
) {
4950
// Get or create summarizer for this context
50-
EventSummarizer summarizer = summarizersByContext.get(context);
51-
if (summarizer == null) {
52-
summarizer = new EventSummarizer(context);
53-
summarizersByContext.put(context, summarizer);
54-
}
51+
EventSummarizer summarizer = summarizersByContext.computeIfAbsent(context, EventSummarizer::new);
5552

5653
// Delegate to the per-context summarizer
5754
summarizer.summarizeEvent(timestamp, flagKey, flagVersion, variation, value, defaultValue, context);
@@ -77,7 +74,7 @@ public List<EventSummarizer.EventSummary> getSummariesAndReset() {
7774

7875
/**
7976
* Restores the summarizer state from a previous snapshot. This is used when a flush
80-
* operation fails and we need to keep the summary data for the next attempt.
77+
* operation fails, and we need to keep the summary data for the next attempt.
8178
*
8279
* @param previousSummaries the list of summaries to restore
8380
*/
@@ -96,7 +93,7 @@ public void restoreTo(List<EventSummarizer.EventSummary> previousSummaries) {
9693
/**
9794
* Returns true if there is no summary data for any context.
9895
*
99-
* @return true if all contexts have empty state
96+
* @return true if all contexts have are empty
10097
*/
10198
@Override
10299
public boolean isEmpty() {

0 commit comments

Comments
 (0)