Class 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) and setMaximumWaitTime(Duration) (maximum time from the first message in a batch was generated until the batch is processed). When processing, the AbstractBatchingLogEventObserver calls processor 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 Detail

      • cooldownTime

        protected Duration cooldownTime
      • maximumWaitTime

        protected Duration maximumWaitTime
      • idleThreshold

        protected Duration idleThreshold
    • Method Detail

      • configure

        public void configure​(Configuration configuration,
                              String prefix)
        Read idleThreshold, cooldownTime and maximumWaitTime 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
      • accept

        public void accept​(T o)
        Specified by:
        accept in interface Batcher<T>
      • add

        protected void add​(T o,
                           Instant now)
      • scheduleFlush

        protected void scheduleFlush​(Duration delay)
      • flush

        public void flush()
        Specified by:
        flush in interface Batcher<T>
      • shutdown

        public void shutdown()
      • takeCurrentBatch

        protected List<T> takeCurrentBatch()