Package net.officefloor.server.stream
Interface StreamBufferPool<B>
-
- Type Parameters:
B
- Type of buffer being pooled.
- All Superinterfaces:
java.lang.AutoCloseable
- All Known Implementing Classes:
AbstractStreamBufferPool
,MockStreamBufferPool
,NettyBufferPool
,ThreadLocalStreamBufferPool
public interface StreamBufferPool<B> extends java.lang.AutoCloseable
Provides interface to wrap buffer pooling implementations.- Author:
- Daniel Sagenschneider
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Closes pool releasing allStreamBuffer
instances.StreamBuffer<B>
getFileStreamBuffer(java.nio.channels.FileChannel file, long position, long count, FileCompleteCallback callback)
Obtains aStreamBuffer
for theFileChannel
content.StreamBuffer<B>
getPooledStreamBuffer()
Obtains aStreamBuffer
.StreamBuffer<B>
getUnpooledStreamBuffer(java.nio.ByteBuffer buffer)
Obtains anStreamBuffer
that is not pooled.
-
-
-
Method Detail
-
getPooledStreamBuffer
StreamBuffer<B> getPooledStreamBuffer()
Obtains aStreamBuffer
.- Returns:
StreamBuffer
.
-
getUnpooledStreamBuffer
StreamBuffer<B> getUnpooledStreamBuffer(java.nio.ByteBuffer buffer)
Obtains an
StreamBuffer
that is not pooled. This is forByteBuffer
instances that are managed outside the BufferPool.Typical use is to create
StreamBuffer
for some read-only cached content within aByteBuffer
.- Parameters:
buffer
-ByteBuffer
.- Returns:
StreamBuffer
for the unpooledByteBuffer
.
-
getFileStreamBuffer
StreamBuffer<B> getFileStreamBuffer(java.nio.channels.FileChannel file, long position, long count, FileCompleteCallback callback) throws java.io.IOException
Obtains a
StreamBuffer
for theFileChannel
content.This enables efficient writing (ie DMA) of
FileChannel
content.To write the entire
FileChannel
contents, invokewrite(file, 0, -1)
.Note that the underlying implementation will need to support
FileChannel
efficiencies.- Parameters:
file
-FileChannel
.position
- Position within theFileChannel
to 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 remainingFileChannel
content from the position.callback
- OptionalFileCompleteCallback
. May benull
.- Returns:
StreamBuffer
for theFileChannel
.- Throws:
java.io.IOException
- If fails to create theStreamBuffer
for theFileChannel
. Typically, this is because the underlying implementation does not support DMA and copies the data from theFileChannel
.
-
close
void close()
Closes pool releasing allStreamBuffer
instances.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-