public interface RequestChunk
The ReqeustChunk and the content it carries stay immutable as long as method
release() is not called. After that, the given instance and the associated
data structure instances (e.g., the ByteBuffer obtained by data())
should not be used. The idea behind this class is to be able to
minimize data copying; ideally, in order to achieve the best performance,
to not copy them at all. However, the implementations may choose otherwise.
The instances of this class are expected to be accessed by a single thread. Calling
the methods of this class (such as data(), release() from different
threads may result in a race condition unless an external synchronization is used.
| Modifier and Type | Method | Description |
|---|---|---|
default byte[] |
bytes() |
Gets the content of the underlying
ByteBuffer as an array of bytes. |
java.nio.ByteBuffer |
data() |
Returns a representation of this chunk as a ByteBuffer.
|
static RequestChunk |
from(byte[] bytes) |
Creates a simple byte array backed request chunk.
|
static RequestChunk |
from(java.nio.ByteBuffer byteBuffer) |
Creates a simple
ByteBuffer backed request chunk. |
default long |
id() |
The tracing ID of this chunk.
|
boolean |
isReleased() |
|
void |
release() |
Releases this chunk.
|
default byte[] bytes()
ByteBuffer as an array of bytes.
If the the ByteBuffer was read, the returned array contains only the part of
data that wasn't read yet. On the other hand, calling this method doesn't cause
the underlying ByteBuffer to be read.
It is expected the returned byte array holds a reference to data that
will become stale upon calling method release(). (For instance,
the memory segment is pooled by the underlying TCP server and is reused
for a subsequent request chunk.) The idea behind this class is to be able to
minimize data copying; ideally, in order to achieve the best performance,
to not copy them at all. However, the implementations may choose otherwise.
Note that the methods of this instance are expected to be called by a single thread; if not, external synchronization must be used.
release() is not calledjava.nio.ByteBuffer data()
data() returns
a buffer that is also already read.
It is expected the returned ByteBuffer holds a reference to data that
will become stale upon calling method release(). (For instance,
the memory segment is pooled by the underlying TCP server and is reused
for a subsequent request chunk.) The idea behind this class is to be able to
minimize data copying; ideally, in order to achieve the best performance,
to not copy them at all. However, the implementations may choose otherwise.
Note that the methods of this instance are expected to be called by a single thread; if not, external synchronization must be used.
release() is not calledboolean isReleased()
data() or bytes()) should not be used.
The implementations may choose to not implement this optimization and to never mutate
the underlying memory; in such case this method does no-op.
Note that the methods of this instance are expected to be called by a single thread; if not, external synchronization must be used.
void release()
bytes() and data() may become stale and should not be used
anymore. The implementations may choose to not implement this optimization and to never mutate
the underlying memory; in such case this method does no-op.
Note that the methods of this instance are expected to be called by a single thread; if not, external synchronization must be used.
default long id()
static RequestChunk from(java.nio.ByteBuffer byteBuffer)
ByteBuffer backed request chunk. The resulting
instance doesn't have any kind of a lifecycle and as such, it doesn't need
to be released.byteBuffer - a byte buffer to create the request chunk fromstatic RequestChunk from(byte[] bytes)
bytes - a byte array to create the request chunk fromCopyright © 2018 Oracle Corporation. All rights reserved.