Package org.eclipse.jetty.io
Class RetainableByteBuffer
java.lang.Object
org.eclipse.jetty.io.RetainableByteBuffer
- All Implemented Interfaces:
Retainable
- Direct Known Subclasses:
ArrayRetainableByteBufferPool.Tracking.Buffer
A pooled ByteBuffer which maintains a reference count that is
incremented with retain()
and decremented with release()
. The buffer
is released to the pool when release()
is called one more time than retain()
.
A RetainableByteBuffer
can either be:
- in pool; in this case
isRetained()
returnsfalse
and callingrelease()
throwsIllegalStateException
- out of pool but not retained; in this case
isRetained()
returnsfalse
and callingrelease()
returnstrue
- out of pool and retained; in this case
isRetained()
returnstrue
and callingrelease()
returnsfalse
Calling release()
on a out of pool and retained instance does not re-pool it while that re-pools it on a out of pool but not retained instance.
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
acquire()
Increments the retained counter of this buffer.int
capacity()
void
clear()
long
boolean
boolean
isDirect()
boolean
isEmpty()
boolean
boolean
release()
Decrements the retained counter of this buffer.int
void
retain()
Increments the retained counter of this buffer.toString()
-
Method Details
-
capacity
public int capacity() -
getBuffer
-
getLastUpdate
public long getLastUpdate() -
isRetained
public boolean isRetained()- Returns:
- true if this buffer is retained, false otherwise.
-
isDirect
public boolean isDirect() -
acquire
protected void acquire()Increments the retained counter of this buffer. It must be done internally by the pool right after creation and after each un-pooling. The reason why this method exists on top ofretain()
is to be able to have some safety checks that must know why the ref counter is being incremented. -
retain
public void retain()Increments the retained counter of this buffer.- Specified by:
retain
in interfaceRetainable
-
release
public boolean release()Decrements the retained counter of this buffer.- Returns:
- true if the buffer was re-pooled, false otherwise.
-
remaining
public int remaining() -
hasRemaining
public boolean hasRemaining() -
isEmpty
public boolean isEmpty() -
clear
public void clear() -
toString
-