Interface RetainableByteBuffer
- All Superinterfaces:
Retainable
- All Known Implementing Classes:
AbstractRetainableByteBuffer
,ArrayByteBufferPool.Tracking.Buffer
,NonRetainableByteBuffer
,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()
returnsfalse
and callingRetainable.release()
throwsIllegalStateException
- out of pool but not retained; in this case
isRetained()
returnsfalse
and callingRetainable.release()
returnstrue
- out of pool and retained; in this case
isRetained()
returnstrue
and callingRetainable.release()
returnsfalse
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Retainable
Retainable.ReferenceCounter
-
Field Summary
Modifier and TypeFieldDescriptionstatic final RetainableByteBuffer
A Zero-capacity, non-retainableRetainableByteBuffer
. -
Method Summary
Modifier and TypeMethodDescriptiondefault int
capacity()
default void
clear()
Get the wrapped, notnull
,ByteBuffer
.default boolean
default boolean
isDirect()
boolean
default int
static RetainableByteBuffer
wrap
(ByteBuffer byteBuffer) Returns a non-retainableRetainableByteBuffer
that wraps the givenByteBuffer
.static RetainableByteBuffer
wrap
(ByteBuffer byteBuffer, Retainable retainable) Methods inherited from interface org.eclipse.jetty.io.Retainable
canRetain, release, retain
-
Field Details
-
EMPTY
A Zero-capacity, non-retainableRetainableByteBuffer
.
-
-
Method Details
-
wrap
Returns a non-retainable
RetainableByteBuffer
that wraps the givenByteBuffer
.Use this method to wrap user-provided
ByteBuffer
s, orByteBuffer
s that hold constant bytes, to make them look likeRetainableByteBuffer
s.The returned
RetainableByteBuffer
Retainable.canRetain()
method always returnsfalse
.RetainableByteBuffer
s returned by this method are not suitable to be wrapped in otherRetainable
implementations that may delegate calls toRetainable.retain()
.- Parameters:
byteBuffer
- theByteBuffer
to wrap- Returns:
- a non-retainable
RetainableByteBuffer
- See Also:
-
wrap
Returns a
RetainableByteBuffer
that wraps the givenByteBuffer
andRetainable
.- Parameters:
byteBuffer
- theByteBuffer
to 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
ByteBuffer
is direct
-
remaining
default int remaining()- Returns:
- the number of remaining bytes in the
ByteBuffer
-
hasRemaining
default boolean hasRemaining()- Returns:
- whether the
ByteBuffer
has remaining bytes
-
capacity
default int capacity()- Returns:
- the
ByteBuffer
capacity
-
clear
default void clear()- See Also:
-