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 voidclose()Closes pool releasing allStreamBufferinstances.StreamBuffer<io.netty.buffer.ByteBuf>getFileStreamBuffer(java.nio.channels.FileChannel file, long position, long count, FileCompleteCallback callback)Obtains aStreamBufferfor theFileChannelcontent.StreamBuffer<io.netty.buffer.ByteBuf>getPooledStreamBuffer()Obtains aStreamBuffer.StreamBuffer<io.netty.buffer.ByteBuf>getUnpooledStreamBuffer(java.nio.ByteBuffer buffer)Obtains anStreamBufferthat is not pooled.voidrelease()Releases thisStreamBufferfor re-use.booleanwrite(byte datum)Writes a byte to the pooled buffer.intwrite(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:StreamBufferPoolObtains aStreamBuffer.- Specified by:
getPooledStreamBufferin interfaceStreamBufferPool<io.netty.buffer.ByteBuf>- Returns:
StreamBuffer.
-
getUnpooledStreamBuffer
public StreamBuffer<io.netty.buffer.ByteBuf> getUnpooledStreamBuffer(java.nio.ByteBuffer buffer)
Description copied from interface:StreamBufferPoolObtains 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.- Specified by:
getUnpooledStreamBufferin interfaceStreamBufferPool<io.netty.buffer.ByteBuf>- Parameters:
buffer-ByteBuffer.- Returns:
StreamBufferfor 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:StreamBufferPoolObtains 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.- Specified by:
getFileStreamBufferin interfaceStreamBufferPool<io.netty.buffer.ByteBuf>- 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:
java.io.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
public void close()
Description copied from interface:StreamBufferPoolCloses pool releasing allStreamBufferinstances.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceStreamBufferPool<io.netty.buffer.ByteBuf>
-
write
public boolean write(byte datum)
Description copied from class:StreamBufferWrites a byte to the pooled buffer.- Specified by:
writein classStreamBuffer<io.netty.buffer.ByteBuf>- Parameters:
datum- Byte value.- Returns:
trueif written value to buffer.falseindicates the pooled buffer is full.
-
write
public int write(byte[] data, int offset, int length)Description copied from class:StreamBufferWrites the data to the pooled buffer.- Specified by:
writein 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:StreamBufferReleases thisStreamBufferfor re-use.- Specified by:
releasein classStreamBuffer<io.netty.buffer.ByteBuf>
-
-