org.apache.log4j.helpers

Class BoundedFIFO


public class BoundedFIFO
extends Object

BoundedFIFO serves as the bounded first-in-first-out buffer heavily used by the AsyncAppender.
Author:
Ceki Gülcü
Since:
version 0.9.1

Constructor Summary

BoundedFIFO(int maxSize)
Instantiate a new BoundedFIFO with a maximum size passed as argument.

Method Summary

LoggingEvent
get()
Get the first element in the buffer.
int
getMaxSize()
Get the maximum size of the buffer.
boolean
isFull()
Return true if the buffer is full, that is, whether the number of elements in the buffer equals the buffer size.
int
length()
Get the number of elements in the buffer.
void
put(LoggingEvent o)
Place a LoggingEvent in the buffer.
void
resize(int newSize)
Resize the buffer to a new size.
boolean
wasEmpty()
Returns true if there is just one element in the buffer.
boolean
wasFull()
Returns true if the number of elements in the buffer plus 1 equals the maximum buffer size, returns false otherwise.

Constructor Details

BoundedFIFO

public BoundedFIFO(int maxSize)
Instantiate a new BoundedFIFO with a maximum size passed as argument.

Method Details

get

public LoggingEvent get()
Get the first element in the buffer. Returns null if there are no elements in the buffer.

getMaxSize

public int getMaxSize()
Get the maximum size of the buffer.

isFull

public boolean isFull()
Return true if the buffer is full, that is, whether the number of elements in the buffer equals the buffer size.

length

public int length()
Get the number of elements in the buffer. This number is guaranteed to be in the range 0 to maxSize (inclusive).

put

public void put(LoggingEvent o)
Place a LoggingEvent in the buffer. If the buffer is full then the event is silently dropped. It is the caller's responsability to make sure that the buffer has free space.

resize

public void resize(int newSize)
Resize the buffer to a new size. If the new size is smaller than the old size events might be lost.
Since:
1.1

wasEmpty

public boolean wasEmpty()

wasFull

public boolean wasFull()
Returns true if the number of elements in the buffer plus 1 equals the maximum buffer size, returns false otherwise.

Copyright 2000-2005 Apache Software Foundation.