Skip to content

Commit f8c0cf3

Browse files
committed
feat(tracker): scaffold module, move event queue classes, add interfaces and tests
- New `tracker` Maven module with EventSender, EventQueueStats, NoopEventQueueStats interfaces - Moved Event, WrappedEvent, EventsStorage*, InMemoryEventsStorage, EventsTask, NoopEventsStorageImp from client to tracker (package unchanged) - InMemoryEventsStorage now takes EventQueueStats instead of TelemetryRuntimeProducer (no Guava) - EventsTask now takes EventSender instead of concrete EventsSender (no Guava) - Added TelemetryEventQueueStats adapter in client to bridge TelemetryRuntimeProducer → EventQueueStats - EventsSender implements EventSender for backward compatibility - 10 unit tests (InMemoryEventsStorageTest x6, EventsTaskTest x4), all passing AI-Session-Id: 4466fe43-9eac-430f-9e06-bb156dfd7edf AI-Tool: claude-code AI-Model: unknown
1 parent 643d36c commit f8c0cf3

21 files changed

Lines changed: 288 additions & 229 deletions

client/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@
167167
</properties>
168168

169169
<dependencies>
170+
<dependency>
171+
<groupId>io.split.client</groupId>
172+
<artifactId>tracker</artifactId>
173+
<version>${project.version}</version>
174+
</dependency>
170175
<dependency>
171176
<groupId>io.split.client</groupId>
172177
<artifactId>targeting-engine</artifactId>

client/src/main/java/io/split/client/SplitFactoryImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import io.split.client.events.EventsTask;
1010
import io.split.client.events.InMemoryEventsStorage;
1111
import io.split.client.events.NoopEventsStorageImp;
12+
import io.split.client.events.EventQueueStats;
13+
import io.split.client.events.TelemetryEventQueueStats;
1214
import io.split.client.impressions.AsynchronousImpressionListener;
1315
import io.split.client.impressions.HttpImpressionsSender;
1416
import io.split.client.impressions.ImpressionCounter;
@@ -254,7 +256,8 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
254256
_impressionsManager = buildImpressionsManager(config, impressionsStorage, impressionsStorage);
255257

256258
// EventClient
257-
EventsStorage eventsStorage = new InMemoryEventsStorage(config.eventsQueueSize(), _telemetryStorageProducer);
259+
EventQueueStats eventsQueueStats = new TelemetryEventQueueStats(_telemetryStorageProducer);
260+
EventsStorage eventsStorage = new InMemoryEventsStorage(config.eventsQueueSize(), eventsQueueStats);
258261
EventsSender eventsSender = EventsSender.create(_splitHttpClient, _eventsRootTarget, _telemetryStorageProducer);
259262
_eventsTask = EventsTask.create(config.eventSendIntervalInMillis(), eventsStorage, eventsSender,
260263
config.getThreadFactory());

client/src/main/java/io/split/client/events/EventsSender.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import static com.google.common.base.Preconditions.checkNotNull;
1616

17-
public class EventsSender {
17+
public class EventsSender implements io.split.client.events.EventSender {
1818

1919
private static final String BULK_ENDPOINT_PATH = "api/events/bulk";
2020
private final URI _bulkEndpoint;
@@ -34,10 +34,15 @@ public static EventsSender create(SplitHttpClient splitHttpclient, URI eventsTar
3434
_httpPostImp = new HttpPostImp(_client, telemetryRuntimeProducer);
3535
}
3636

37-
public void sendEvents(List<Event> _data) {
37+
@Override
38+
public void send(List<Event> _data) {
3839
_httpPostImp.post(_bulkEndpoint, _data, "Events ", HttpParamsWrapper.EVENTS);
3940
}
4041

42+
public void sendEvents(List<Event> _data) {
43+
send(_data);
44+
}
45+
4146
@VisibleForTesting
4247
URI getBulkEndpoint() {
4348
return _bulkEndpoint;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.split.client.events;
2+
3+
import io.split.telemetry.domain.enums.EventsDataRecordsEnum;
4+
import io.split.telemetry.storage.TelemetryRuntimeProducer;
5+
6+
import java.util.Objects;
7+
8+
public class TelemetryEventQueueStats implements EventQueueStats {
9+
10+
private final TelemetryRuntimeProducer _telemetryRuntimeProducer;
11+
12+
public TelemetryEventQueueStats(TelemetryRuntimeProducer telemetryRuntimeProducer) {
13+
_telemetryRuntimeProducer = Objects.requireNonNull(telemetryRuntimeProducer);
14+
}
15+
16+
@Override
17+
public void onQueued(long count) {
18+
_telemetryRuntimeProducer.recordEventStats(EventsDataRecordsEnum.EVENTS_QUEUED, count);
19+
}
20+
21+
@Override
22+
public void onDropped(long count) {
23+
_telemetryRuntimeProducer.recordEventStats(EventsDataRecordsEnum.EVENTS_DROPPED, count);
24+
}
25+
}

client/src/test/java/io/split/client/events/EventsTaskTest.java

Lines changed: 0 additions & 102 deletions
This file was deleted.

client/src/test/java/io/split/client/events/InMemoryEventsStorageTest.java

Lines changed: 0 additions & 85 deletions
This file was deleted.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<module>redis-wrapper</module>
7272
<module>testing</module>
7373
<module>okhttp-modules</module>
74+
<module>tracker</module>
7475
<module>client</module>
7576
</modules>
7677
<build>

tracker/pom.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<parent>
9+
<groupId>io.split.client</groupId>
10+
<artifactId>java-client-parent</artifactId>
11+
<version>4.18.3</version>
12+
</parent>
13+
14+
<artifactId>tracker</artifactId>
15+
<packaging>jar</packaging>
16+
<name>Tracker</name>
17+
<description>Shared event queue, scheduler, and HTTP-injected delivery</description>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>com.google.code.gson</groupId>
22+
<artifactId>gson</artifactId>
23+
<version>2.13.1</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.slf4j</groupId>
27+
<artifactId>slf4j-api</artifactId>
28+
<version>1.7.36</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>junit</groupId>
32+
<artifactId>junit</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.mockito</groupId>
37+
<artifactId>mockito-core</artifactId>
38+
<version>1.10.19</version>
39+
<scope>test</scope>
40+
</dependency>
41+
</dependencies>
42+
</project>

client/src/main/java/io/split/client/dtos/Event.java renamed to tracker/src/main/java/io/split/client/dtos/Event.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.split.client.dtos;
22

3-
import com.google.common.base.Objects;
43
import com.google.gson.annotations.SerializedName;
54

65
import java.util.Map;
6+
import java.util.Objects;
77

88
public class Event {
99

@@ -36,13 +36,13 @@ public boolean equals(Object o) {
3636
Event event = (Event) o;
3737
return Double.compare(event.value, value) == 0 &&
3838
timestamp == event.timestamp &&
39-
Objects.equal(eventTypeId, event.eventTypeId) &&
40-
Objects.equal(trafficTypeName, event.trafficTypeName) &&
41-
Objects.equal(key, event.key);
39+
Objects.equals(eventTypeId, event.eventTypeId) &&
40+
Objects.equals(trafficTypeName, event.trafficTypeName) &&
41+
Objects.equals(key, event.key);
4242
}
4343

4444
@Override
4545
public int hashCode() {
46-
return Objects.hashCode(eventTypeId, trafficTypeName, key, value, timestamp);
46+
return Objects.hash(eventTypeId, trafficTypeName, key, value, timestamp);
4747
}
4848
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.split.client.events;
2+
3+
public interface EventQueueStats {
4+
void onQueued(long count);
5+
void onDropped(long count);
6+
}

0 commit comments

Comments
 (0)