Class NettyBufferPool
- java.lang.Object
-
- net.officefloor.server.stream.StreamBuffer<io.netty.buffer.ByteBuf>
-
- net.officefloor.server.http.netty.NettyBufferPool
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,StreamBufferPool<io.netty.buffer.ByteBuf>
public class NettyBufferPool extends StreamBuffer<io.netty.buffer.ByteBuf> implements StreamBufferPool<io.netty.buffer.ByteBuf>
NettyStreamBufferPool
.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.officefloor.server.stream.StreamBuffer
StreamBuffer.FileBuffer
-
-
Field Summary
-
Fields inherited from class net.officefloor.server.stream.StreamBuffer
fileBuffer, next, pooledBuffer, unpooledByteBuffer
-
-
Constructor Summary
Constructors Constructor Description NettyBufferPool(io.netty.handler.codec.http.FullHttpResponse response)
Instantiate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes pool releasing allStreamBuffer
instances.StreamBuffer<io.netty.buffer.ByteBuf>
getFileStreamBuffer(java.nio.channels.FileChannel file, long position, long count, FileCompleteCallback callback)
Obtains aStreamBuffer
for theFileChannel
content.StreamBuffer<io.netty.buffer.ByteBuf>
getPooledStreamBuffer()
Obtains aStreamBuffer
.StreamBuffer<io.netty.buffer.ByteBuf>
getUnpooledStreamBuffer(java.nio.ByteBuffer buffer)
Obtains anStreamBuffer
that is not pooled.void
release()
Releases thisStreamBuffer
for re-use.boolean
write(byte datum)
Writes a byte to the pooled buffer.int
write(byte[] data, int offset, int length)
Writes the data to the pooled buffer.-
Methods inherited from class net.officefloor.server.stream.StreamBuffer
getAppendable, getWriteStreamBuffer, write, write, write, write, write, write, writeByte
-
-
-
-
Method Detail
-
getPooledStreamBuffer
public StreamBuffer<io.netty.buffer.ByteBuf> getPooledStreamBuffer()
Description copied from interface:StreamBufferPool
Obtains aStreamBuffer
.- Specified by:
getPooledStreamBuffer
in interfaceStreamBufferPool<io.netty.buffer.ByteBuf>
- Returns:
StreamBuffer
.
-
getUnpooledStreamBuffer
public StreamBuffer<io.netty.buffer.ByteBuf> getUnpooledStreamBuffer(java.nio.ByteBuffer buffer)
Description copied from interface:StreamBufferPool
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
.- Specified by:
getUnpooledStreamBuffer
in interfaceStreamBufferPool<io.netty.buffer.ByteBuf>
- Parameters:
buffer
-ByteBuffer
.- Returns:
StreamBuffer
for the unpooledByteBuffer
.
-
getFileStreamBuffer
public StreamBuffer<io.netty.buffer.ByteBuf> getFileStreamBuffer(java.nio.channels.FileChannel file, long position, long count, FileCompleteCallback callback) throws java.io.IOException
Description copied from interface:StreamBufferPool
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.- Specified by:
getFileStreamBuffer
in interfaceStreamBufferPool<io.netty.buffer.ByteBuf>
- 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
public void close()
Description copied from interface:StreamBufferPool
Closes pool releasing allStreamBuffer
instances.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceStreamBufferPool<io.netty.buffer.ByteBuf>
-
write
public boolean write(byte datum)
Description copied from class:StreamBuffer
Writes a byte to the pooled buffer.- Specified by:
write
in classStreamBuffer<io.netty.buffer.ByteBuf>
- Parameters:
datum
- Byte value.- Returns:
true
if written value to buffer.false
indicates the pooled buffer is full.
-
write
public int write(byte[] data, int offset, int length)
Description copied from class:StreamBuffer
Writes the data to the pooled buffer.- Specified by:
write
in classStreamBuffer<io.netty.buffer.ByteBuf>
- Parameters:
data
- Data to write to the pooled buffer.offset
- Offset within the data to write the data.length
- Length of data to write the data.- Returns:
- Number of bytes written.
-
release
public void release()
Description copied from class:StreamBuffer
Releases thisStreamBuffer
for re-use.- Specified by:
release
in classStreamBuffer<io.netty.buffer.ByteBuf>
-
-