Top Description Inners Methods
org.eclipse.jetty.io

public Interface ByteBufferPool

Known Direct Implementers
org.eclipse.jetty.io.ByteBufferPool.Wrapper, org.eclipse.jetty.io.ByteBufferPool.NonPooling, org.eclipse.jetty.io.ArrayByteBufferPool
Imports
java.nio.ByteBuffer, java.util.ArrayList, .List, org.eclipse.jetty.util.BufferUtil

A pool for RetainableByteBuffer instances.

RetainableByteBuffer that are acquired must be released by calling RetainableByteBuffer#release() otherwise the memory they hold will be leaked.

API NOTE

This interface does not have a symmetric release(RetainableByteBuffer) method, because it will be confusing to use due to the fact that the acquired instance is-a Retainable.

Imagine this (hypothetical) code sequence:

RetainableByteBuffer buffer = pool.acquire(size, direct);
buffer.retain();
pool.release(buffer);

The hypothetical call to release(RetainableByteBuffer) would appear to release the buffer to the pool, but in fact the buffer is retained one more time (and therefore still in use) and not really released to the pool. For this reason there is no release(RetainableByteBuffer) method.

Therefore, in order to track acquire/release counts both the pool and the buffer returned by acquire(int, boolean) must be wrapped, see RetainableByteBuffer.Wrapper

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ByteBufferPool.Accumulator

Accumulates a sequence of RetainableByteBuffer that are typically created during the generation of protocol bytes.

public static class
public static class
ByteBufferPool.Wrapper

A wrapper for ByteBufferPool instances.

Method Summary

Modifier and TypeMethod and Description
public RetainableByteBuffer

Returns:

a RetainableByteBuffer with position and limit set to 0.
acquire
(int
The size of the buffer. The returned buffer will have at least this capacity.
size
,
boolean
true if a direct memory buffer is needed, false otherwise.
direct
)

Acquires a RetainableByteBuffer from this pool.

public void
clear()

Removes all non-retained pooled instances from this pool.

Method Detail

acquireback to summary
public RetainableByteBuffer acquire(int size, boolean direct)

Acquires a RetainableByteBuffer from this pool.

Parameters
size:int

The size of the buffer. The returned buffer will have at least this capacity.

direct:boolean

true if a direct memory buffer is needed, false otherwise.

Returns:RetainableByteBuffer

a RetainableByteBuffer with position and limit set to 0.

clearback to summary
public void clear()

Removes all non-retained pooled instances from this pool.

org.eclipse.jetty.io back to summary

public Class ByteBufferPool.Accumulator

extends Object
Class Inheritance

Accumulates a sequence of RetainableByteBuffer that are typically created during the generation of protocol bytes.

RetainableByteBuffers can be either appended to the sequence, or inserted at a specific position in the sequence, and then released when they are consumed.

Field Summary

Modifier and TypeField and Description
private final List<RetainableByteBuffer>
private final List<ByteBuffer>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public List<ByteBuffer>
public int
public long
public void
insert(int index, RetainableByteBuffer buffer)

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

buffersback to summary
private final List<RetainableByteBuffer> buffers
byteBuffersback to summary
private final List<ByteBuffer> byteBuffers

Constructor Detail

Accumulatorback to summary
public Accumulator()

Method Detail

appendback to summary
public void append(RetainableByteBuffer buffer)
getByteBuffersback to summary
public List<ByteBuffer> getByteBuffers()
getSizeback to summary
public int getSize()
getTotalLengthback to summary
public long getTotalLength()
insertback to summary
public void insert(int index, RetainableByteBuffer buffer)
releaseback to summary
public void release()
org.eclipse.jetty.io back to summary

public Class ByteBufferPool.NonPooling

extends Object
implements ByteBufferPool
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.io.ByteBufferPool

A ByteBufferPool that does not pool its RetainableByteBuffers.

The returned RetainableByteBuffers are reference counted.

RetainableByteBuffers returned by this class are suitable to be wrapped in other Retainable implementations that may delegate calls to Retainable#retain().

See Also
RetainableByteBuffer#wrap(ByteBuffer)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public RetainableByteBuffer
acquire(int
The size of the buffer. The returned buffer will have at least this capacity.
size
,
boolean
true if a direct memory buffer is needed, false otherwise.
direct
)

Implements org.eclipse.jetty.io.ByteBufferPool.acquire.

Acquires a RetainableByteBuffer from this pool.

public void
clear()

Implements org.eclipse.jetty.io.ByteBufferPool.clear.

Removes all non-retained pooled instances from this pool.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NonPoolingback to summary
public NonPooling()

Method Detail

acquireback to summary
public RetainableByteBuffer acquire(int size, boolean direct)

Implements org.eclipse.jetty.io.ByteBufferPool.acquire.

Doc from org.eclipse.jetty.io.ByteBufferPool.acquire.

Acquires a RetainableByteBuffer from this pool.

Parameters
size:int

The size of the buffer. The returned buffer will have at least this capacity.

direct:boolean

true if a direct memory buffer is needed, false otherwise.

Returns:RetainableByteBuffer

a RetainableByteBuffer with position and limit set to 0.

Annotations
@Override
clearback to summary
public void clear()

Implements org.eclipse.jetty.io.ByteBufferPool.clear.

Doc from org.eclipse.jetty.io.ByteBufferPool.clear.

Removes all non-retained pooled instances from this pool.

Annotations
@Override
org.eclipse.jetty.io back to summary

private Class ByteBufferPool.NonPooling.Buffer

extends AbstractRetainableByteBuffer
Class Inheritance

Constructor Summary

AccessConstructor and Description
private
Buffer(ByteBuffer byteBuffer)

Constructor Detail

Bufferback to summary
private Buffer(ByteBuffer byteBuffer)
org.eclipse.jetty.io back to summary

public Class ByteBufferPool.Wrapper

extends Object
implements ByteBufferPool
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.io.ByteBufferPool

A wrapper for ByteBufferPool instances.

Field Summary

Modifier and TypeField and Description
private final ByteBufferPool

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public RetainableByteBuffer
acquire(int
The size of the buffer. The returned buffer will have at least this capacity.
size
,
boolean
true if a direct memory buffer is needed, false otherwise.
direct
)

Implements org.eclipse.jetty.io.ByteBufferPool.acquire.

Acquires a RetainableByteBuffer from this pool.

public void
clear()

Implements org.eclipse.jetty.io.ByteBufferPool.clear.

Removes all non-retained pooled instances from this pool.

public ByteBufferPool
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

wrappedback to summary
private final ByteBufferPool wrapped

Constructor Detail

Wrapperback to summary
public Wrapper(ByteBufferPool wrapped)

Method Detail

acquireback to summary
public RetainableByteBuffer acquire(int size, boolean direct)

Implements org.eclipse.jetty.io.ByteBufferPool.acquire.

Doc from org.eclipse.jetty.io.ByteBufferPool.acquire.

Acquires a RetainableByteBuffer from this pool.

Parameters
size:int

The size of the buffer. The returned buffer will have at least this capacity.

direct:boolean

true if a direct memory buffer is needed, false otherwise.

Returns:RetainableByteBuffer

a RetainableByteBuffer with position and limit set to 0.

Annotations
@Override
clearback to summary
public void clear()

Implements org.eclipse.jetty.io.ByteBufferPool.clear.

Doc from org.eclipse.jetty.io.ByteBufferPool.clear.

Removes all non-retained pooled instances from this pool.

Annotations
@Override
getWrappedback to summary
public ByteBufferPool getWrapped()