Top Description Inners Fields Constructors Methods
org.xnio

public final Class ByteBufferSlicePool

extends Object
implements Pool<ByteBuffer>
Class Inheritance
All Implemented Interfaces
org.xnio.Pool
Imports
java.lang.ref.WeakReference, java.nio.ByteBuffer, java.security.AccessController, java.util.ArrayDeque, .ArrayList, .Collections, .HashSet, .List, .Queue, .Set, java.util.concurrent.ConcurrentLinkedQueue

Deprecated

See ByteBufferPool.

A buffer pooled allocator. This pool uses a series of buffer regions to back the returned pooled buffers. When the buffer is no longer needed, it should be freed back into the pool; failure to do so will cause the corresponding buffer area to be unavailable until the buffer is garbage-collected. If the buffer pool is no longer used, it is advisable to invoke clean() to make sure that direct allocated buffers can be reused by a future instance.
Authors
David M. Lloyd, Flavia Rainone

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
ByteBufferSlicePool.PooledByteBuffer

References Deprecated Pooled is deprecated or references (maybe indirectly) at least one deprecated element.
pack-priv class
ByteBufferSlicePool.Ref

References Deprecated AutomaticReference is deprecated or references (maybe indirectly) at least one deprecated element.
private static class
pack-priv static class
private static class

Field Summary

Modifier and TypeField and Description
private final BufferAllocator<ByteBuffer>
private final int
private final int
private final List<ByteBuffer>
private static final Queue<ByteBuffer>
private static final int
private final ThreadLocal<ByteBufferSlicePool.ThreadLocalCache>
private final Set<ByteBufferSlicePool.Ref>
private final Queue<ByteBufferSlicePool.Slice>
private final int

Constructor Summary

AccessConstructor and Description
public
ByteBufferSlicePool(final BufferAllocator<ByteBuffer>
the buffer allocator to use
allocator
,
final int
the size of each buffer
bufferSize
,
final int
the maximum region size for each backing buffer
maxRegionSize
,
final int
the number of buffers to cache on each thread
threadLocalQueueSize
)

Construct a new instance.

public
ByteBufferSlicePool(final BufferAllocator<ByteBuffer>
the buffer allocator to use
allocator
,
final int
the size of each buffer
bufferSize
,
final int
the maximum region size for each backing buffer
maxRegionSize
)

Construct a new instance.

public
ByteBufferSlicePool(final int
the size of each buffer
bufferSize
,
final int
the maximum region size for each backing buffer
maxRegionSize
)

Construct a new instance, using a direct buffer allocator.

Method Summary

Modifier and TypeMethod and Description
public Pooled<ByteBuffer>
allocate()

Implements org.xnio.Pool.allocate.

References Deprecated Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

Allocate a resource from the pool.

private ByteBufferSlicePool.Slice
allocateSlices(final int buffersPerRegion, final int bufferSize)

public void
clean()

Cleans the pool, removing references to any buffers inside it.

private ByteBufferSlicePool.ThreadLocalCache
private void
private void
public int
getBufferSize()

Return the size of the ByteBuffers that are returned by allocate().

private ByteBufferSlicePool.Slice
sliceAllocatedBuffer(final ByteBuffer region, final int buffersPerRegion, final int bufferSize)

private ByteBufferSlicePool.Slice
sliceReusedBuffer(final ByteBuffer region, final int buffersPerRegion, final int bufferSize)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allocatorback to summary
private final BufferAllocator<ByteBuffer> allocator
bufferSizeback to summary
private final int bufferSize
buffersPerRegionback to summary
private final int buffersPerRegion
directBuffersback to summary
private final List<ByteBuffer> directBuffers
FREE_DIRECT_BUFFERSback to summary
private static final Queue<ByteBuffer> FREE_DIRECT_BUFFERS
LOCAL_LENGTHback to summary
private static final int LOCAL_LENGTH
localQueueHolderback to summary
private final ThreadLocal<ByteBufferSlicePool.ThreadLocalCache> localQueueHolder
refSetback to summary
private final Set<ByteBufferSlicePool.Ref> refSet
sliceQueueback to summary
private final Queue<ByteBufferSlicePool.Slice> sliceQueue
threadLocalQueueSizeback to summary
private final int threadLocalQueueSize

Constructor Detail

ByteBufferSlicePoolback to summary
public ByteBufferSlicePool(final BufferAllocator<ByteBuffer> allocator, final int bufferSize, final int maxRegionSize, final int threadLocalQueueSize)

Construct a new instance.

Parameters
allocator:BufferAllocator<ByteBuffer>

the buffer allocator to use

bufferSize:int

the size of each buffer

maxRegionSize:int

the maximum region size for each backing buffer

threadLocalQueueSize:int

the number of buffers to cache on each thread

ByteBufferSlicePoolback to summary
public ByteBufferSlicePool(final BufferAllocator<ByteBuffer> allocator, final int bufferSize, final int maxRegionSize)

Construct a new instance.

Parameters
allocator:BufferAllocator<ByteBuffer>

the buffer allocator to use

bufferSize:int

the size of each buffer

maxRegionSize:int

the maximum region size for each backing buffer

ByteBufferSlicePoolback to summary
public ByteBufferSlicePool(final int bufferSize, final int maxRegionSize)

Construct a new instance, using a direct buffer allocator.

Parameters
bufferSize:int

the size of each buffer

maxRegionSize:int

the maximum region size for each backing buffer

Method Detail

allocateback to summary
public Pooled<ByteBuffer> allocate()

Implements org.xnio.Pool.allocate.

Doc from org.xnio.Pool.allocate.

References Deprecated

Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Allocate a resource from the pool.

Returns:Pooled<ByteBuffer>

the resource

allocateSlicesback to summary
private ByteBufferSlicePool.Slice allocateSlices(final int buffersPerRegion, final int bufferSize)
cleanback to summary
public void clean()

Cleans the pool, removing references to any buffers inside it. Should be invoked on pool disposal, when the pool will no longer be used.

createThreadLocalCacheback to summary
private ByteBufferSlicePool.ThreadLocalCache createThreadLocalCache()
doFreeback to summary
private void doFree(ByteBufferSlicePool.Slice region)
freeThreadLocalCacheback to summary
private void freeThreadLocalCache(ByteBufferSlicePool.ThreadLocalCache cache)
getBufferSizeback to summary
public int getBufferSize()

Return the size of the ByteBuffers that are returned by allocate().

sliceAllocatedBufferback to summary
private ByteBufferSlicePool.Slice sliceAllocatedBuffer(final ByteBuffer region, final int buffersPerRegion, final int bufferSize)
sliceReusedBufferback to summary
private ByteBufferSlicePool.Slice sliceReusedBuffer(final ByteBuffer region, final int buffersPerRegion, final int bufferSize)
org.xnio back to summary

private final Class ByteBufferSlicePool.PooledByteBuffer

extends Object
implements Pooled<ByteBuffer>
Class Inheritance
All Implemented Interfaces
org.xnio.Pooled, java.lang.AutoCloseable

References Deprecated

Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Field Summary

Modifier and TypeField and Description
pack-priv ByteBuffer
private final ByteBufferSlicePool.Slice

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements org.xnio.Pooled.close.

Delegates to free().

public void
discard()

Implements org.xnio.Pooled.discard.

Discard this resource.

public void
free()

Implements org.xnio.Pooled.free.

Free this resource for immediate re-use.

public ByteBuffer
getResource()

Implements org.xnio.Pooled.getResource.

Get the pooled resource.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

bufferback to summary
pack-priv ByteBuffer buffer
regionback to summary
private final ByteBufferSlicePool.Slice region

Constructor Detail

PooledByteBufferback to summary
pack-priv PooledByteBuffer(final ByteBufferSlicePool.Slice region, final ByteBuffer buffer)

Method Detail

closeback to summary
public void close()

Implements org.xnio.Pooled.close.

Doc from org.xnio.Pooled.close.

Delegates to free().

discardback to summary
public void discard()

Implements org.xnio.Pooled.discard.

Doc from org.xnio.Pooled.discard.

Discard this resource. Any backing resources corresponding to this pooled resource will be rendered unavailable until the pooled resource has been garbage-collected.

freeback to summary
public void free()

Implements org.xnio.Pooled.free.

Doc from org.xnio.Pooled.free.

Free this resource for immediate re-use. The resource must not be accessed again after calling this method; if it is possible that an instance is still in use, you must call discard() instead.

getResourceback to summary
public ByteBuffer getResource()

Implements org.xnio.Pooled.getResource.

Doc from org.xnio.Pooled.getResource.

Get the pooled resource.

Returns:ByteBuffer

the pooled resource

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

org.xnio back to summary

pack-priv final Class ByteBufferSlicePool.Ref

extends AutomaticReference<ByteBuffer>
Class Inheritance

References Deprecated

AutomaticReference is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Field Summary

Modifier and TypeField and Description
private final ByteBufferSlicePool.Slice
Inherited from org.xnio.AutomaticReference:
PERMIT

Constructor Summary

AccessConstructor and Description
private
Ref(final ByteBuffer referent, final ByteBufferSlicePool.Slice region)

Method Summary

Modifier and TypeMethod and Description
protected void
free()

Implements abstract org.xnio.AutomaticReference.free.

Free this reference.

Inherited from org.xnio.AutomaticReference:
clearenqueuegetgetPermitisEnqueued

Field Detail

regionback to summary
private final ByteBufferSlicePool.Slice region

Constructor Detail

Refback to summary
private Ref(final ByteBuffer referent, final ByteBufferSlicePool.Slice region)

Method Detail

freeback to summary
protected void free()

Implements abstract org.xnio.AutomaticReference.free.

Doc from org.xnio.AutomaticReference.free.

Free this reference. This method will be called from a dedicated thread or threads so this method should execute as quickly as possible.

org.xnio back to summary

private final Class ByteBufferSlicePool.Slice

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ByteBuffer

Constructor Summary

AccessConstructor and Description
private
Slice(final ByteBuffer parent, final int start, final int size)

Method Summary

Modifier and TypeMethod and Description
pack-priv ByteBuffer
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

parentback to summary
private final ByteBuffer parent

Constructor Detail

Sliceback to summary
private Slice(final ByteBuffer parent, final int start, final int size)

Method Detail

sliceback to summary
pack-priv ByteBuffer slice()
org.xnio back to summary

pack-priv final Class ByteBufferSlicePool.ThreadLocalCache

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv final WeakReference<ByteBufferSlicePool>
pack-priv final ArrayDeque<ByteBufferSlicePool.Slice>

Constructor Summary

AccessConstructor and Description
pack-priv
ThreadLocalCache(ByteBufferSlicePool pool)
References Deprecated ByteBufferSlicePool is deprecated or references (maybe indirectly) at least one deprecated element.

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

outstandingback to summary
pack-priv int outstanding
poolback to summary
pack-priv final WeakReference<ByteBufferSlicePool> pool
queueback to summary
pack-priv final ArrayDeque<ByteBufferSlicePool.Slice> queue

Constructor Detail

ThreadLocalCacheback to summary
pack-priv ThreadLocalCache(ByteBufferSlicePool pool)

References Deprecated

ByteBufferSlicePool is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

org.xnio back to summary

private Class ByteBufferSlicePool.ThreadLocalCacheWrapper

extends ThreadLocal<ByteBufferSlicePool.ThreadLocalCache>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final WeakReference<ByteBufferSlicePool>

Constructor Summary

AccessConstructor and Description
pack-priv
ThreadLocalCacheWrapper(ByteBufferSlicePool pool)
References Deprecated ByteBufferSlicePool is deprecated or references (maybe indirectly) at least one deprecated element.

Method Summary

Modifier and TypeMethod and Description
protected ByteBufferSlicePool.ThreadLocalCache
initialValue()

Overrides java.lang.ThreadLocal.initialValue.

Returns the current thread's "initial value" for this thread-local variable.

public void
remove()

Overrides java.lang.ThreadLocal.remove.

Removes the current thread's value for this thread-local variable.

Inherited from java.lang.ThreadLocal:
getsetwithInitial

Field Detail

poolback to summary
private final WeakReference<ByteBufferSlicePool> pool

Constructor Detail

ThreadLocalCacheWrapperback to summary
pack-priv ThreadLocalCacheWrapper(ByteBufferSlicePool pool)

References Deprecated

ByteBufferSlicePool is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Method Detail

initialValueback to summary
protected ByteBufferSlicePool.ThreadLocalCache initialValue()

Overrides java.lang.ThreadLocal.initialValue.

Doc from java.lang.ThreadLocal.initialValue.

Returns the current thread's "initial value" for this thread-local variable. This method will be invoked the first time a thread accesses the variable with the get method, unless the thread previously invoked the set method, in which case the initialValue method will not be invoked for the thread. Normally, this method is invoked at most once per thread, but it may be invoked again in case of subsequent invocations of remove followed by get.

Returns:ByteBufferSlicePool.ThreadLocalCache

the initial value for this thread-local

removeback to summary
public void remove()

Overrides java.lang.ThreadLocal.remove.

Doc from java.lang.ThreadLocal.remove.

Removes the current thread's value for this thread-local variable. If this thread-local variable is subsequently read by the current thread, its value will be reinitialized by invoking its initialValue method, unless its value is set by the current thread in the interim. This may result in multiple invocations of the initialValue method in the current thread.