Package org.apache.log4j.helpers
Class CyclicBuffer
- java.lang.Object
-
- org.apache.log4j.helpers.CyclicBuffer
-
public class CyclicBuffer extends java.lang.ObjectCyclicBuffer is used by other appenders to holdLoggingEventsfor immediate or differed display.This buffer gives read access to any element in the buffer not just the first or last element.
- Since:
- 0.9.0
- Author:
- Ceki Gülcü
-
-
Constructor Summary
Constructors Constructor Description CyclicBuffer(int maxSize)Instantiate a new CyclicBuffer of at mostmaxSizeevents.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(LoggingEvent event)Add aneventas the last event in the buffer.LoggingEventget()Get the oldest (first) element in the buffer.LoggingEventget(int i)Get the ith oldest event currently in the buffer.intgetMaxSize()intlength()Get the number of elements in the buffer.voidresize(int newSize)Resize the cyclic buffer tonewSize.
-
-
-
Constructor Detail
-
CyclicBuffer
public CyclicBuffer(int maxSize) throws java.lang.IllegalArgumentExceptionInstantiate a new CyclicBuffer of at mostmaxSizeevents.The
maxSizeargument must a positive integer.- Parameters:
maxSize- The maximum number of elements in the buffer.- Throws:
java.lang.IllegalArgumentException
-
-
Method Detail
-
add
public void add(LoggingEvent event)
Add aneventas the last event in the buffer.
-
get
public LoggingEvent get(int i)
Get the ith oldest event currently in the buffer. If i is outside the range 0 to the number of elements currently in the buffer, thennullis returned.
-
getMaxSize
public int getMaxSize()
-
get
public LoggingEvent get()
Get the oldest (first) element in the buffer. The oldest element is removed from the buffer.
-
length
public int length()
Get the number of elements in the buffer. This number is guaranteed to be in the range 0 tomaxSize(inclusive).
-
resize
public void resize(int newSize)
Resize the cyclic buffer tonewSize.- Throws:
java.lang.IllegalArgumentException- ifnewSizeis negative.
-
-