Interface RetainableByteBuffer
- All Superinterfaces:
Retainable
- All Known Implementing Classes:
AbstractRetainableByteBuffer, ArrayByteBufferPool.Tracking.Buffer, RetainableByteBuffer.Wrapper
A pooled ByteBuffer which maintains a reference count that is
incremented with Retainable.retain() and decremented with Retainable.release().
The ByteBuffer is released to a ByteBufferPool
when Retainable.release() is called one more time than Retainable.retain();
in such case, the call to Retainable.release() returns true.
A RetainableByteBuffer can either be:
- in pool; in this case
isRetained()returnsfalseand callingRetainable.release()throwsIllegalStateException - out of pool but not retained; in this case
isRetained()returnsfalseand callingRetainable.release()returnstrue - out of pool and retained; in this case
isRetained()returnstrueand callingRetainable.release()returnsfalse
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface Retainable
Retainable.ReferenceCounter -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RetainableByteBufferA Zero-capacity, non-retainableRetainableByteBuffer. -
Method Summary
Modifier and TypeMethodDescriptiondefault intcapacity()default voidclear()Get the wrapped, notnull,ByteBuffer.default booleandefault booleanisDirect()booleandefault intstatic RetainableByteBufferwrap(ByteBuffer byteBuffer) Returns a non-retainableRetainableByteBufferthat wraps the givenByteBuffer.static RetainableByteBufferwrap(ByteBuffer byteBuffer, Retainable retainable) Methods inherited from interface Retainable
canRetain, release, retain
-
Field Details
-
EMPTY
A Zero-capacity, non-retainableRetainableByteBuffer.
-
-
Method Details
-
wrap
Returns a non-retainable
RetainableByteBufferthat wraps the givenByteBuffer.Use this method to wrap user-provided
ByteBuffers, orByteBuffers that hold constant bytes, to make them look likeRetainableByteBuffers.The returned
RetainableByteBufferRetainable.canRetain()method always returnsfalse.RetainableByteBuffers returned by this method are not suitable to be wrapped in otherRetainableimplementations that may delegate calls toRetainable.retain().- Parameters:
byteBuffer- theByteBufferto wrap- Returns:
- a non-retainable
RetainableByteBuffer - See Also:
-
wrap
Returns a
RetainableByteBufferthat wraps the givenByteBufferandRetainable.- Parameters:
byteBuffer- theByteBufferto wrapretainable- the associatedRetainable.- Returns:
- a
RetainableByteBuffer - See Also:
-
isRetained
boolean isRetained()- Returns:
- whether this instance is retained
- See Also:
-
getByteBuffer
ByteBuffer getByteBuffer()Get the wrapped, notnull,ByteBuffer.- Returns:
- the wrapped, not
null,ByteBuffer
-
isDirect
default boolean isDirect()- Returns:
- whether the
ByteBufferis direct
-
remaining
default int remaining()- Returns:
- the number of remaining bytes in the
ByteBuffer
-
hasRemaining
default boolean hasRemaining()- Returns:
- whether the
ByteBufferhas remaining bytes
-
capacity
default int capacity()- Returns:
- the
ByteBuffercapacity
-
clear
default void clear()- See Also:
-