Class MemoryLimitedCompressingFifoRingBuffer

java.lang.Object
org.graylog2.log4j.MemoryLimitedCompressingFifoRingBuffer

public class MemoryLimitedCompressingFifoRingBuffer extends Object
MemoryLimitedCompressingFifoRingBuffer is a first-in first-out buffer that is limited by the memory it can consume. If the memory limit is exceeded, it will evict the oldest elements, before it adds a new element. Elements are compressed using Zstd. To achieve better compression the elements are compressed in batches of BATCHSIZE. This means that the if the buffer is full, old elements are evicted in full batches. Not single elements.
  • Field Details

  • Constructor Details

    • MemoryLimitedCompressingFifoRingBuffer

      public MemoryLimitedCompressingFifoRingBuffer(long memLimit)
      Construct a new MemoryLimitedCompressingFifoRingBuffer with the default Zstd compression level of DEFAULT_ZSTD_COMPRESSION_LEVEL
      Parameters:
      memLimit - the memory limit of the Buffer in bytes
    • MemoryLimitedCompressingFifoRingBuffer

      public MemoryLimitedCompressingFifoRingBuffer(long memLimit, int zStdCompressionLevel)
      Construct a new MemoryLimitedCompressingFifoRingBuffer
      Parameters:
      memLimit - the memory limit of the Buffer in bytes
      zStdCompressionLevel - the Zstd compression level to use
  • Method Details

    • add

      public void add(byte[] element) throws IOException
      Throws:
      IOException
    • streamContent

      public void streamContent(OutputStream outputStream, int limit)
      Write the buffer content into the provided OutputStream.
      Parameters:
      outputStream - The OutputStream to write the entries into.
      limit - limit the returned entries. This is only a rough estimate and will be rounded to the nearest batch size.
    • clear

      public void clear() throws IOException
      Throws:
      IOException
    • getLogsSize

      public long getLogsSize()
      Returns an estimate of the size in bytes
      Returns:
      the estimated buffer content size in bytes