Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.sentry.logger;

import io.sentry.ISentryClient;
import io.sentry.ISentryExecutorService;
import io.sentry.ISentryLifecycleToken;
import io.sentry.SentryExecutorService;
import io.sentry.SentryLogEvent;
import io.sentry.SentryLogEvents;
import io.sentry.SentryOptions;
Expand All @@ -22,6 +24,7 @@ public final class LoggerBatchProcessor implements ILoggerBatchProcessor {
private final @NotNull SentryOptions options;
private final @NotNull ISentryClient client;
private final @NotNull Queue<SentryLogEvent> queue;
private final @NotNull ISentryExecutorService executorService;
private volatile @Nullable Future<?> scheduledFlush;
private static final @NotNull AutoClosableReentrantLock scheduleLock =
new AutoClosableReentrantLock();
Expand All @@ -31,6 +34,7 @@ public LoggerBatchProcessor(
this.options = options;
this.client = client;
this.queue = new ConcurrentLinkedQueue<>();
this.executorService = new SentryExecutorService();
}

@Override
Expand All @@ -39,11 +43,14 @@ public void add(final @NotNull SentryLogEvent logEvent) {
maybeSchedule(false, false);
}

@SuppressWarnings("FutureReturnValueIgnored")
@Override
public void close(final boolean isRestarting) {
if (isRestarting) {
maybeSchedule(true, true);
executorService.submit(() -> executorService.close(options.getShutdownTimeoutMillis()));
} else {
executorService.close(options.getShutdownTimeoutMillis());
while (!queue.isEmpty()) {
flushBatch();
}
Expand All @@ -58,7 +65,7 @@ private void maybeSchedule(boolean forceSchedule, boolean immediately) {
|| latestScheduledFlush.isDone()
|| latestScheduledFlush.isCancelled()) {
final int flushAfterMs = immediately ? 0 : FLUSH_AFTER_MS;
scheduledFlush = options.getExecutorService().schedule(new BatchRunnable(), flushAfterMs);
scheduledFlush = executorService.schedule(new BatchRunnable(), flushAfterMs);
}
}
}
Expand Down
Loading