Class BatchProcessor
java.lang.Object
codes.grow.packages.betterstack.logging.BatchProcessor
- All Implemented Interfaces:
AutoCloseable
Queues log records and exports them in batches from one background thread (a single-threaded
ScheduledExecutorService).
A batch is exported when maxBatchSize records or maxBatchBytes bytes are
queued, every flushInterval, on flush() and on shutdown. A batch whose
export fails with a retryable SDK exception and nothing accepted is re-attempted up to two times
(100 ms, 200 ms backoff) within the export timeout; partial acceptance is final. Every callback
exception is caught and ignored.
-
Constructor Summary
ConstructorsConstructorDescriptionBatchProcessor(LogExporter exporter) Creates a processor with default options.BatchProcessor(LogExporter exporter, BatchOptions options) Creates a processor and starts its worker thread. -
Method Summary
Modifier and TypeMethodDescriptionbooleanQueues a record.voidclose()Same asshutdown().voidflush()Exports everything queued now, waiting at most the export timeout.voidExports everything queued now.flushAsync(Duration timeout) Exports everything queued now, asynchronously.options()The options.voidshutdown()Drains the queue, shuts the exporter down and stops the worker, waiting at most the export timeout.voidDrains the queue, shuts the exporter down and stops the worker.shutdownAsync(Duration timeout) Asynchronousshutdown(Duration).stats()Current counters.
-
Constructor Details
-
BatchProcessor
Creates a processor with default options.- Parameters:
exporter- the exporter
-
BatchProcessor
Creates a processor and starts its worker thread.- Parameters:
exporter- the exporteroptions- batch options
-
-
Method Details
-
options
The options.- Returns:
- options
-
add
Queues a record. Never blocks unless the drop policy isDropPolicy.BLOCK.- Parameters:
record- the record- Returns:
falsewhen the record was dropped
-
flush
public void flush()Exports everything queued now, waiting at most the export timeout.- Throws:
TimeoutException- when the records are not exported in time
-
flush
Exports everything queued now.- Parameters:
timeout- maximum wait- Throws:
TimeoutException- when the records are not exported in time
-
flushAsync
Exports everything queued now, asynchronously.- Parameters:
timeout- maximum wait; the future fails withTimeoutExceptionafter it- Returns:
- completes when the records queued at call time were exported (or failed)
-
shutdown
public void shutdown()Drains the queue, shuts the exporter down and stops the worker, waiting at most the export timeout. Idempotent.- Throws:
TimeoutException- when draining did not finish in time (remaining records are dropped)
-
shutdown
Drains the queue, shuts the exporter down and stops the worker. Idempotent; lateradd(codes.grow.packages.betterstack.logging.LogRecord)calls drop the record with reasonDropReason.SHUTDOWN.- Parameters:
timeout- maximum wait- Throws:
TimeoutException- when draining did not finish in time (remaining records are dropped)
-
shutdownAsync
Asynchronousshutdown(Duration). Repeated calls return the first call's future.- Parameters:
timeout- maximum wait- Returns:
- completes when the processor stopped
-
close
public void close()Same asshutdown().- Specified by:
closein interfaceAutoCloseable
-
stats
Current counters.- Returns:
- stats snapshot
-