Class BoundedFIFO


  • public class BoundedFIFO
    extends java.lang.Object
    Bounded first-in-first-out buffer.
    Since:
    version 0.9.1
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) LoggingEvent[] buf  
      (package private) int first  
      (package private) int maxSize  
      (package private) int next  
      (package private) int numElements  
    • Constructor Summary

      Constructors 
      Constructor Description
      BoundedFIFO​(int maxSize)
      Constructs a new instance with a maximum size passed as argument.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      LoggingEvent get()
      Gets the first element in the buffer.
      int getMaxSize()
      Gets the maximum size of the buffer.
      boolean isFull()
      Returns true if the buffer is full, that is, whether the number of elements in the buffer equals the buffer size.
      int length()
      Gets the number of elements in the buffer.
      (package private) int min​(int a, int b)  
      void put​(LoggingEvent o)
      Puts a LoggingEvent in the buffer.
      void resize​(int newSize)
      Resizes 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • numElements

        int numElements
      • first

        int first
      • next

        int next
      • maxSize

        int maxSize
    • Constructor Detail

      • BoundedFIFO

        public BoundedFIFO​(int maxSize)
        Constructs a new instance with a maximum size passed as argument.
    • Method Detail

      • get

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

        public int getMaxSize()
        Gets the maximum size of the buffer.
      • isFull

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

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

        int min​(int a,
                int b)
      • put

        public void put​(LoggingEvent o)
        Puts 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)
        Resizes 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()
        Returns true if there is just one element in the buffer. In other words, if there were no elements before the last put(org.apache.log4j.spi.LoggingEvent) operation completed.
      • wasFull

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