BufferHolder type.
BufferHolder is an abstract class that simplifies the implementation of objects that themselves contain
a Buffer instance.
The BufferHolder can only hold on to a single buffer, so objects and classes that need to hold on to multiple
buffers will have to do their implementation from scratch, though they can use the code of the BufferHolder
as inspiration. Alternatively, multiple buffers can be
composed into a single buffer, which can then be put
in a buffer holder.
If you just want an object that is a reference to a buffer, then the BufferRef can be used for that purpose.
If you have an advanced use case where you wish to implement Resource, and tightly control lifetimes, then
ResourceSupport can be of help.
| Access | Constructor and Description |
|---|---|
| protected | BufferHolder(Buffer
The buffer to be held by this holder. buf)Create a new |
| protected | BufferHolder(Send<Buffer>
The buffer to be held by this holder. send)Create a new |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public boolean | Returns: true if this object is the same as the obj argument; false otherwise.The reference object with which to compare. other)Overrides java. equals operation is restricted to work only with instances of the same class.
|
| protected final Buffer | |
| protected final Buffer | |
| public int | |
| public boolean | |
| protected abstract T | receive(Buffer
The buf)Buffer that is received by the recipient,
and needs to be wrapped in a new BufferHolder instance.Called when a sent |
| protected final void | replaceBuffer(Send<Buffer>
The new send)Buffer instance that is replacing the currently held buffer.Replace the underlying referenced buffer with the given buffer. |
| protected final void | replaceBufferVolatile(Send<Buffer> send)
Replace the underlying referenced buffer with the given buffer. |
| public Send | send()
Implements io. |
| public T | touch(Object
An optional hint about this access and its context. May be hint)null.Overrides default io. |
| BUF | back to summary |
|---|---|
| private static final VarHandle BUF | |
| buf | back to summary |
|---|---|
| private Buffer buf | |
| BufferHolder | back to summary |
|---|---|
| protected BufferHolder(Buffer buf) Create a new | |
| BufferHolder | back to summary |
|---|---|
| protected BufferHolder(Send<Buffer> send) Create a new
The | |
| close | back to summary |
|---|---|
| public void close() Implements io. Doc from io. Close the resource, making it inaccessible. Note, this method is not thread-safe unless otherwise specified.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides java. This implementation of the | |
| getBuffer | back to summary |
|---|---|
| protected final Buffer getBuffer() Access the held The access is performed using a plain load.
| |
| getBufferVolatile | back to summary |
|---|---|
| protected final Buffer getBufferVolatile() Access the held The access is performed using a volatile load.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isAccessible | back to summary |
|---|---|
| public boolean isAccessible() Implements io. Doc from io. Check if this object is accessible. | |
| receive | back to summary |
|---|---|
| protected abstract T receive(Buffer buf) Called when a sent
| |
| replaceBuffer | back to summary |
|---|---|
| protected final void replaceBuffer(Send<Buffer> send) Replace the underlying referenced buffer with the given buffer.
This method is protected to permit advanced use cases of Note This method closes the current buffer, and takes exclusive ownership of the received buffer. The buffer assignment is performed using a plain store. | |
| replaceBufferVolatile | back to summary |
|---|---|
| protected final void replaceBufferVolatile(Send<Buffer> send) Replace the underlying referenced buffer with the given buffer.
This method is protected to permit advanced use cases of Note this method closes the current buffer, and takes exclusive ownership of the received buffer. The buffer assignment is performed using a volatile store. | |
| send | back to summary |
|---|---|
| public Send Implements io. Doc from io. Send this object instance to another Thread, transferring the ownership to the recipient. The object must be in a state where it can be sent, which includes at least being accessible. When sent, this instance will immediately become inaccessible, as if by closing it. All attempts at accessing an object that has been sent, even if that object has not yet been received, should cause an exception to be thrown.
Calling
| |
| touch | back to summary |
|---|---|
| public T touch(Object hint) Overrides default io. Doc from io. Record the current access location for debugging purposes. This information may be included if the resource throws a life-cycle related exception, or if it leaks. If this resource has already been closed, then this method has no effect.
| |