Package org.elasticsearch.nio
Class InboundChannelBuffer
- java.lang.Object
-
- org.elasticsearch.nio.InboundChannelBuffer
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public final class InboundChannelBuffer extends java.lang.Object implements java.lang.AutoCloseableThis is a channel byte buffer composed internally of 16kb pages. When an entire message has been read and consumed, therelease(long)method releases the bytes from the head of the buffer and closes the pages internally. If more space is needed at the end of the bufferensureCapacity(long)can be called and the buffer will expand using the supplier provided.
-
-
Field Summary
Fields Modifier and Type Field Description static intPAGE_SIZE
-
Constructor Summary
Constructors Constructor Description InboundChannelBuffer(java.util.function.IntFunction<Page> pageAllocator)
-
Method Summary
Modifier and Type Method Description static InboundChannelBufferallocatingInstance()voidclose()voidensureCapacity(long requiredCapacity)longgetCapacity()longgetIndex()longgetRemaining()voidincrementIndex(long delta)voidrelease(long bytesToRelease)This method will release bytes from the head of this buffer.Page[]sliceAndRetainPagesTo(long to)This method will return an array ofPagerepresenting the bytes from the beginning of this buffer up through the index argument that was passed.java.nio.ByteBuffer[]sliceBuffersFrom(long from)This method will return an array ofByteBufferrepresenting the bytes from the index passed through the end of this buffer.java.nio.ByteBuffer[]sliceBuffersTo(long to)This method will return an array ofByteBufferrepresenting the bytes from the beginning of this buffer up through the index argument that was passed.
-
-
-
Field Detail
-
PAGE_SIZE
public static final int PAGE_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InboundChannelBuffer
public InboundChannelBuffer(java.util.function.IntFunction<Page> pageAllocator)
-
-
Method Detail
-
allocatingInstance
public static InboundChannelBuffer allocatingInstance()
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
ensureCapacity
public void ensureCapacity(long requiredCapacity)
-
release
public void release(long bytesToRelease)
This method will release bytes from the head of this buffer. If you release bytes past the current index the index is truncated to zero.- Parameters:
bytesToRelease- number of bytes to drop
-
sliceBuffersTo
public java.nio.ByteBuffer[] sliceBuffersTo(long to)
This method will return an array ofByteBufferrepresenting the bytes from the beginning of this buffer up through the index argument that was passed. The buffers will be duplicates of the internal buffers, so any modifications to the markersBuffer.position(),Buffer.limit(), etc will not modify the this class.- Parameters:
to- the index to slice up to- Returns:
- the byte buffers
-
sliceAndRetainPagesTo
public Page[] sliceAndRetainPagesTo(long to)
This method will return an array ofPagerepresenting the bytes from the beginning of this buffer up through the index argument that was passed. The pages and buffers will be duplicates of the internal components, so any modifications to the markersBuffer.position(),Buffer.limit(), etc will not modify the this class. Additionally, this will internally retain the underlying pages, so the pages returned by this method must be closed.- Parameters:
to- the index to slice up to- Returns:
- the pages
-
sliceBuffersFrom
public java.nio.ByteBuffer[] sliceBuffersFrom(long from)
This method will return an array ofByteBufferrepresenting the bytes from the index passed through the end of this buffer. The buffers will be duplicates of the internal buffers, so any modifications to the markersBuffer.position(),Buffer.limit(), etc will not modify the this class.- Parameters:
from- the index to slice from- Returns:
- the byte buffers
-
incrementIndex
public void incrementIndex(long delta)
-
getIndex
public long getIndex()
-
getCapacity
public long getCapacity()
-
getRemaining
public long getRemaining()
-
-