Package net.officefloor.server.stream
Interface StreamBufferPool<B>
- Type Parameters:
B- Type of buffer being pooled.
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractStreamBufferPool,MockStreamBufferPool,NettyBufferPool,ThreadLocalStreamBufferPool,VertxBufferPool
Provides interface to wrap buffer pooling implementations.
- Author:
- Daniel Sagenschneider
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes pool releasing allStreamBufferinstances.getFileStreamBuffer(FileChannel file, long position, long count, FileCompleteCallback callback) Obtains aStreamBufferfor theFileChannelcontent.Obtains aStreamBuffer.getUnpooledStreamBuffer(ByteBuffer buffer) Obtains anStreamBufferthat is not pooled.
-
Method Details
-
getPooledStreamBuffer
StreamBuffer<B> getPooledStreamBuffer()Obtains aStreamBuffer.- Returns:
StreamBuffer.
-
getUnpooledStreamBuffer
Obtains an
StreamBufferthat is not pooled. This is forByteBufferinstances that are managed outside the BufferPool.Typical use is to create
StreamBufferfor some read-only cached content within aByteBuffer.- Parameters:
buffer-ByteBuffer.- Returns:
StreamBufferfor the unpooledByteBuffer.
-
getFileStreamBuffer
StreamBuffer<B> getFileStreamBuffer(FileChannel file, long position, long count, FileCompleteCallback callback) throws IOException Obtains a
StreamBufferfor theFileChannelcontent.This enables efficient writing (ie DMA) of
FileChannelcontent.To write the entire
FileChannelcontents, invokewrite(file, 0, -1).Note that the underlying implementation will need to support
FileChannelefficiencies.- Parameters:
file-FileChannel.position- Position within theFileChannelto start writing content. Must be non-negative number.count- Count of bytes to write from theFileChannel. A negative value (typically-1) indicates to write the remainingFileChannelcontent from the position.callback- OptionalFileCompleteCallback. May benull.- Returns:
StreamBufferfor theFileChannel.- Throws:
IOException- If fails to create theStreamBufferfor theFileChannel. Typically, this is because the underlying implementation does not support DMA and copies the data from theFileChannel.
-
close
void close()Closes pool releasing allStreamBufferinstances.- Specified by:
closein interfaceAutoCloseable
-