Skip to content
Open
Prev Previous commit
Next Next commit
remove callback
  • Loading branch information
apuig committed Mar 24, 2025
commit 205e2dee5fa36c06a5bab76252fb133d46c05ce7
22 changes: 0 additions & 22 deletions analytics/src/main/java/com/segment/analytics/Analytics.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public static class Builder {
private int maximumFlushAttempts;
private int maximumQueueSizeInBytes;
private long flushIntervalInMillis;
private List<Callback> callbacks;
private int queueCapacity;
private boolean forceTlsV1 = false;
private GsonBuilder gsonBuilder;
Expand Down Expand Up @@ -318,21 +317,6 @@ public Builder threadFactory(ThreadFactory threadFactory) {
return this;
}

/** Add a {@link Callback} to be notified when an event is processed. */
public Builder callback(Callback callback) {
if (callback == null) {
throw new NullPointerException("Null callback");
}
if (callbacks == null) {
callbacks = new ArrayList<>();
}
if (callbacks.contains(callback)) {
throw new IllegalStateException("Callback is already registered.");
}
callbacks.add(callback);
return this;
}

/** Use a {@link Plugin} to configure the builder. */
@Beta
public Builder plugin(Plugin plugin) {
Expand Down Expand Up @@ -407,11 +391,6 @@ public Analytics build() {
if (threadFactory == null) {
threadFactory = Platform.get().defaultThreadFactory();
}
if (callbacks == null) {
callbacks = Collections.emptyList();
} else {
callbacks = Collections.unmodifiableList(callbacks);
}

HttpLoggingInterceptor interceptor =
new HttpLoggingInterceptor(
Expand Down Expand Up @@ -463,7 +442,6 @@ public void log(String message) {
log,
threadFactory,
networkExecutor,
callbacks,
writeKey,
gson);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public class AnalyticsClient {
private final int maximumRetries;
private final int maximumQueueByteSize;
private final Log log;
private final List<Callback> callbacks;
private final ExecutorService networkExecutor;
private final Thread looperThread;
private final AtomicBoolean isShutDown;
Expand All @@ -76,7 +75,6 @@ public static AnalyticsClient create(
Log log,
ThreadFactory threadFactory,
ExecutorService networkExecutor,
List<Callback> callbacks,
String writeKey,
Gson gsonInstance) {
return new AnalyticsClient(
Expand All @@ -91,7 +89,6 @@ public static AnalyticsClient create(
log,
threadFactory,
networkExecutor,
callbacks,
new AtomicBoolean(false),
writeKey,
gsonInstance);
Expand All @@ -109,7 +106,6 @@ public AnalyticsClient(
Log log,
ThreadFactory threadFactory,
ExecutorService networkExecutor,
List<Callback> callbacks,
AtomicBoolean isShutDown,
String writeKey,
Gson gsonInstance) {
Expand All @@ -122,8 +118,7 @@ public AnalyticsClient(
this.maximumRetries = maximumRetries;
this.maximumQueueByteSize = maximumQueueSizeInBytes;
this.log = log;
this.callbacks = callbacks;
this.looperThread = threadFactory.newThread(new Looper());
this.looperThread = threadFactory.newThread(new Looper());
this.networkExecutor = networkExecutor;
this.isShutDown = isShutDown;
this.writeKey = writeKey;
Expand Down Expand Up @@ -290,11 +285,7 @@ static BatchUploadTask create(AnalyticsClient client, Batch batch, int maxRetrie
}

private void notifyCallbacksWithException(Batch batch, Exception exception) {
for (Message message : batch.batch()) {
for (Callback callback : client.callbacks) {
callback.failure(message, exception);
}
}
// XXX failure
}

/** Returns {@code true} to indicate a batch should be retried. {@code false} otherwise. */
Expand All @@ -308,12 +299,7 @@ boolean upload() {
if (response.isSuccessful()) {
client.log.print(VERBOSE, "Uploaded batch %s.", batch.sequence());

for (Message message : batch.batch()) {
for (Callback callback : client.callbacks) {
callback.success(message);
}
}

// XXX success
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,46 +381,12 @@ public void buildsWithThreadFactory() {
assertThat(analytics).isNotNull();
}

@Test
public void nullCallback() {
try {
builder.callback(null);
fail("Should fail for null callback");
} catch (NullPointerException e) {
assertThat(e).hasMessage("Null callback");
}
}

@Test
public void duplicateCallback() {
Callback callback = mock(Callback.class);
try {
builder.callback(callback).callback(callback);
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Callback is already registered.");
}
}

@Test
public void buildsWithValidCallback() {
Analytics analytics = builder.callback(mock(Callback.class)).build();
assertThat(analytics).isNotNull();
}

@Test
public void buildsWithForceTlsV1() {
Analytics analytics = builder.forceTlsVersion1().build();
assertThat(analytics).isNotNull();
}

@Test
public void multipleCallbacks() {
Analytics analytics =
builder.callback(mock(Callback.class)).callback(mock(Callback.class)).build();

assertThat(analytics).isNotNull();
}

@Test
public void nullPlugin() {
try {
Expand Down
Loading