Class ThreadAwareByteBufferPool

java.lang.Object
org.restheart.buffers.ThreadAwareByteBufferPool
All Implemented Interfaces:
io.undertow.connector.ByteBufferPool, Closeable, AutoCloseable

public class ThreadAwareByteBufferPool extends Object implements io.undertow.connector.ByteBufferPool
A byte buffer pool that delegates to specific implementations based on the thread type.

For IO threads, it utilizes the undertow.DefaultByteBufferPool to pool resources efficiently. For virtual worker threads, it uses the NotPoolingByteBufferPool, which doesn't pool resources, to optimize performance given the unique characteristics of virtual threads.

Author:
Andrea Di Cesare
  • Constructor Details

    • ThreadAwareByteBufferPool

      public ThreadAwareByteBufferPool(boolean direct, int bufferSize, boolean enablePooling)
      Parameters:
      direct - If io threads implementation should use direct buffers
      bufferSize - The buffer size to use
      enablePooling - true to enable pooling for platform threads
  • Method Details

    • getBufferSize

      public int getBufferSize()
      Specified by:
      getBufferSize in interface io.undertow.connector.ByteBufferPool
    • isDirect

      public boolean isDirect()
      Specified by:
      isDirect in interface io.undertow.connector.ByteBufferPool
    • allocate

      public io.undertow.connector.PooledByteBuffer allocate()
      Specified by:
      allocate in interface io.undertow.connector.ByteBufferPool
    • getArrayBackedPool

      public io.undertow.connector.ByteBufferPool getArrayBackedPool()
      Specified by:
      getArrayBackedPool in interface io.undertow.connector.ByteBufferPool
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface io.undertow.connector.ByteBufferPool
      Specified by:
      close in interface Closeable