CircularBuffer (Apache ZooKeeper - Server 3.7.0 API)
Date: 2021-03-17

org.apache.zookeeper.server.util

## Class CircularBuffer<T>

- java.lang.Object
- - org.apache.zookeeper.server.util.CircularBuffer<T>

-     public class CircularBuffer<T>
      extends Object

  Thread safe FIFO CircularBuffer implementation. When the buffer is full write operation overwrites the oldest element. Fun thing @todo, make this lock free as this is called on every quorum message

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CircularBuffer(Class<T> clazz, int capacity)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `isEmpty()`
    `boolean` | `isFull()`
    `T` | `peek()`
    `void` | `reset()`
    `int` | `size()`
    `T` | `take()` Reads from the buffer in a FIFO manner.
    `void` | `write(T element)` Puts elements in the next available index in the array.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CircularBuffer

          public CircularBuffer(Class<T> clazz,
                                int capacity)

  - ### Method Detail

    - #### write

          public void write(T element)

      Puts elements in the next available index in the array. If the array is full the oldest element is replaced with the new value.
      Parameters:
        `element` -

    - #### take

          public T take()

      Reads from the buffer in a FIFO manner. Returns the oldest element in the buffer if the buffer is not empty Returns null if the buffer is empty
      Returns:
        the oldest element in the buffer

    - #### peek

          public T peek()

    - #### size

          public int size()

    - #### isEmpty

          public boolean isEmpty()

    - #### isFull

          public boolean isFull()

    - #### reset

          public void reset()

Copyright © 2008–2021 The Apache Software Foundation. All rights reserved.