java.lang.Object
uno.xifan.id.generator.distributed.segmentid.concurrent.RingBuffer<T>

public class RingBuffer<T> extends Object
环形缓冲区(RingBuffer)实现 支持线程安全的读写操作
  • Constructor Summary

    Constructors
    Constructor
    Description
    RingBuffer(int capacity)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    检查缓冲区是否为空
    boolean
    检查缓冲区是否已满
    boolean
    offer(T item)
    非阻塞方式尝试写入元素 如果缓冲区已满,返回false
    非阻塞方式尝试读取元素 如果缓冲区为空,返回null
    void
    put(T item)
    向缓冲区写入一个元素 如果缓冲区已满,则阻塞直到有空间可用
    int
    获取当前缓冲区中的元素数量
    从缓冲区读取一个元素 如果缓冲区为空,则阻塞直到有元素可用

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RingBuffer

      public RingBuffer(int capacity)
  • Method Details

    • put

      public void put(T item) throws InterruptedException
      向缓冲区写入一个元素 如果缓冲区已满,则阻塞直到有空间可用
      Throws:
      InterruptedException
    • take

      public T take() throws InterruptedException
      从缓冲区读取一个元素 如果缓冲区为空,则阻塞直到有元素可用
      Throws:
      InterruptedException
    • offer

      public boolean offer(T item)
      非阻塞方式尝试写入元素 如果缓冲区已满,返回false
    • poll

      public T poll()
      非阻塞方式尝试读取元素 如果缓冲区为空,返回null
    • size

      public int size()
      获取当前缓冲区中的元素数量
    • isEmpty

      public boolean isEmpty()
      检查缓冲区是否为空
    • isFull

      public boolean isFull()
      检查缓冲区是否已满