Package org.logevents.observers.batch
Class CooldownBatcher<T>
- java.lang.Object
-
- org.logevents.observers.batch.CooldownBatcher<T>
-
- All Implemented Interfaces:
Batcher<T>
public class CooldownBatcher<T> extends Object implements Batcher<T>
Used to gather up a number of log event to process as a batch.The batch decides when to flush a batch based on
setCooldownTime(Duration)
(minimum time since last processed batch),setIdleThreshold(Duration)
(minimum time between log events in the batch) andsetMaximumWaitTime(Duration)
(maximum time from the first message in a batch was generated until the batch is processed). When processing, theAbstractBatchingLogEventObserver
callsprocessor
with the whole batch to process the log events. Consecutive Log events with the same message pattern and log level are grouped together so the processor can easily ignore duplicate messages.- Author:
- Johannes Brodwall
-
-
Field Summary
Fields Modifier and Type Field Description protected Duration
cooldownTime
protected Duration
idleThreshold
protected Duration
maximumWaitTime
-
Constructor Summary
Constructors Constructor Description CooldownBatcher(Consumer<List<T>> processor, ScheduledExecutorService executor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(T o)
protected void
add(T o, Instant now)
void
configure(Configuration configuration, String prefix)
ReadidleThreshold
,cooldownTime
andmaximumWaitTime
from configurationvoid
flush()
List<T>
getCurrentBatch()
protected void
scheduleFlush(Duration delay)
void
setCooldownTime(Duration cooldownTime)
Minimum time from a flush until the next flushvoid
setIdleThreshold(Duration idleThreshold)
Minimum time from a flush until the next flushvoid
setMaximumWaitTime(Duration maximumWaitTime)
Maximum time from the first event in a batch until the batch is flushedvoid
shutdown()
protected List<T>
takeCurrentBatch()
-
-
-
Constructor Detail
-
CooldownBatcher
public CooldownBatcher(Consumer<List<T>> processor, ScheduledExecutorService executor)
-
-
Method Detail
-
configure
public void configure(Configuration configuration, String prefix)
ReadidleThreshold
,cooldownTime
andmaximumWaitTime
from configuration
-
setCooldownTime
public void setCooldownTime(Duration cooldownTime)
Minimum time from a flush until the next flush
-
setIdleThreshold
public void setIdleThreshold(Duration idleThreshold)
Minimum time from a flush until the next flush
-
setMaximumWaitTime
public void setMaximumWaitTime(Duration maximumWaitTime)
Maximum time from the first event in a batch until the batch is flushed
-
scheduleFlush
protected void scheduleFlush(Duration delay)
-
shutdown
public void shutdown()
-
getCurrentBatch
public List<T> getCurrentBatch()
- Specified by:
getCurrentBatch
in interfaceBatcher<T>
-
-