Package org.graylog2.log4j
Class MemoryLimitedCompressingFifoRingBuffer
java.lang.Object
org.graylog2.log4j.MemoryLimitedCompressingFifoRingBuffer
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionMemoryLimitedCompressingFifoRingBuffer(long memLimit) Construct a new MemoryLimitedCompressingFifoRingBuffer with the default Zstd compression level ofDEFAULT_ZSTD_COMPRESSION_LEVELMemoryLimitedCompressingFifoRingBuffer(long memLimit, int zStdCompressionLevel) Construct a new MemoryLimitedCompressingFifoRingBuffer -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(byte[] element) voidclear()longReturns an estimate of the size in bytesvoidstreamContent(OutputStream outputStream, int limit) Write the buffer content into the provided OutputStream.
-
Field Details
-
DEFAULT_ZSTD_COMPRESSION_LEVEL
public static final int DEFAULT_ZSTD_COMPRESSION_LEVEL- See Also:
-
BATCHSIZE
public static final int BATCHSIZE- See Also:
-
-
Constructor Details
-
MemoryLimitedCompressingFifoRingBuffer
public MemoryLimitedCompressingFifoRingBuffer(long memLimit) Construct a new MemoryLimitedCompressingFifoRingBuffer with the default Zstd compression level ofDEFAULT_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 byteszStdCompressionLevel- the Zstd compression level to use
-
-
Method Details
-
add
- Throws:
IOException
-
streamContent
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
- Throws:
IOException
-
getLogsSize
public long getLogsSize()Returns an estimate of the size in bytes- Returns:
- the estimated buffer content size in bytes
-