Top Description Inners Fields Constructors Methods
io.undertow.server

public Class DefaultByteBufferPool

extends Object
implements ByteBufferPool
Class Inheritance
All Implemented Interfaces
io.undertow.connector.ByteBufferPool, java.io.Closeable, java.lang.AutoCloseable
Imports
io.undertow.UndertowMessages, io.undertow.connector.ByteBufferPool, .PooledByteBuffer, java.lang.ref.WeakReference, java.nio.ByteBuffer, java.util.ArrayDeque, .ArrayList, .HashMap, .List, .Map, java.util.concurrent.ConcurrentLinkedQueue, java.util.concurrent.atomic.AtomicIntegerFieldUpdater

A byte buffer pool that supports reference counted pools.

Todo

move this somewhere more appropriate

Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private class

Field Summary

Modifier and TypeField and Description
private final DefaultByteBufferPool
private final int
private volatile boolean
private int
private volatile int
private static final AtomicIntegerFieldUpdater<DefaultByteBufferPool>
private final boolean
private final int
private final int
private final ConcurrentLinkedQueue<ByteBuffer>
private volatile int
private static final AtomicIntegerFieldUpdater<DefaultByteBufferPool>
private final DefaultByteBufferPool.ThreadLocalCache
private final int
private final List<WeakReference<DefaultByteBufferPool.ThreadLocalData>>

Constructor Summary

AccessConstructor and Description
public
DefaultByteBufferPool(boolean
If this implementation should use direct buffers
direct
,
int
The buffer size to use
bufferSize
)

public
DefaultByteBufferPool(boolean
If this implementation should use direct buffers
direct
,
int
The buffer size to use
bufferSize
,
int
The maximum pool size, in number of buffers, it does not include buffers in thread local caches
maximumPoolSize
,
int
The maximum number of buffers that can be stored in a thread local cache
threadLocalCacheSize
,
int leakDecetionPercent)

public
DefaultByteBufferPool(boolean
If this implementation should use direct buffers
direct
,
int
The buffer size to use
bufferSize
,
int
The maximum pool size, in number of buffers, it does not include buffers in thread local caches
maximumPoolSize
,
int
The maximum number of buffers that can be stored in a thread local cache
threadLocalCacheSize
)

Method Summary

Modifier and TypeMethod and Description
public PooledByteBuffer
private void
public void
close()

Implements io.undertow.connector.ByteBufferPool.close.

Closes this stream and releases any system resources associated with it.

protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

private void
public ByteBufferPool
getArrayBackedPool()

Implements io.undertow.connector.ByteBufferPool.getArrayBackedPool.

If this byte buffer pool corresponds to an array backed pool then this will return itself.

public int
public boolean
private void
Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

arrayBackedPoolback to summary
private final DefaultByteBufferPool arrayBackedPool
bufferSizeback to summary
private final int bufferSize
closedback to summary
private volatile boolean closed
countback to summary
private int count
currentQueueLengthback to summary
private volatile int currentQueueLength
Annotations
@SuppressWarnings:unused, FieldCanBeLocal
currentQueueLengthUpdaterback to summary
private static final AtomicIntegerFieldUpdater<DefaultByteBufferPool> currentQueueLengthUpdater
directback to summary
private final boolean direct
leakDectionPercentback to summary
private final int leakDectionPercent
maximumPoolSizeback to summary
private final int maximumPoolSize
queueback to summary
private final ConcurrentLinkedQueue<ByteBuffer> queue
reclaimedThreadLocalsback to summary
private volatile int reclaimedThreadLocals
Annotations
@SuppressWarnings:unused, FieldCanBeLocal
reclaimedThreadLocalsUpdaterback to summary
private static final AtomicIntegerFieldUpdater<DefaultByteBufferPool> reclaimedThreadLocalsUpdater
threadLocalCacheback to summary
private final DefaultByteBufferPool.ThreadLocalCache threadLocalCache
threadLocalCacheSizeback to summary
private final int threadLocalCacheSize
threadLocalDataListback to summary
private final List<WeakReference<DefaultByteBufferPool.ThreadLocalData>> threadLocalDataList

Constructor Detail

DefaultByteBufferPoolback to summary
public DefaultByteBufferPool(boolean direct, int bufferSize)
Parameters
direct:boolean

If this implementation should use direct buffers

bufferSize:int

The buffer size to use

DefaultByteBufferPoolback to summary
public DefaultByteBufferPool(boolean direct, int bufferSize, int maximumPoolSize, int threadLocalCacheSize, int leakDecetionPercent)
Parameters
direct:boolean

If this implementation should use direct buffers

bufferSize:int

The buffer size to use

maximumPoolSize:int

The maximum pool size, in number of buffers, it does not include buffers in thread local caches

threadLocalCacheSize:int

The maximum number of buffers that can be stored in a thread local cache

DefaultByteBufferPoolback to summary
public DefaultByteBufferPool(boolean direct, int bufferSize, int maximumPoolSize, int threadLocalCacheSize)
Parameters
direct:boolean

If this implementation should use direct buffers

bufferSize:int

The buffer size to use

maximumPoolSize:int

The maximum pool size, in number of buffers, it does not include buffers in thread local caches

threadLocalCacheSize:int

The maximum number of buffers that can be stored in a thread local cache

Method Detail

allocateback to summary
public PooledByteBuffer allocate()

Implements io.undertow.connector.ByteBufferPool.allocate.

Annotations
@Override
cleanupThreadLocalDataback to summary
private void cleanupThreadLocalData()
closeback to summary
public void close()

Implements io.undertow.connector.ByteBufferPool.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method
freeInternalback to summary
private void freeInternal(ByteBuffer buffer)
getArrayBackedPoolback to summary
public ByteBufferPool getArrayBackedPool()

Implements io.undertow.connector.ByteBufferPool.getArrayBackedPool.

Doc from io.undertow.connector.ByteBufferPool.getArrayBackedPool.

If this byte buffer pool corresponds to an array backed pool then this will return itself. Otherwise it will return an array backed pool that contains buffers of the same size.

Returns:ByteBufferPool

An array backed pool of the same size

Annotations
@Override
getBufferSizeback to summary
public int getBufferSize()

Implements io.undertow.connector.ByteBufferPool.getBufferSize.

Annotations
@Override
isDirectback to summary
public boolean isDirect()

Implements io.undertow.connector.ByteBufferPool.isDirect.

Annotations
@Override
queueIfUnderMaxback to summary
private void queueIfUnderMax(ByteBuffer buffer)
io.undertow.server back to summary

private Class DefaultByteBufferPool.DefaultPooledBuffer

extends Object
implements PooledByteBuffer
Class Inheritance
All Implemented Interfaces
io.undertow.connector.PooledByteBuffer, java.io.Closeable, java.lang.AutoCloseable

Field Summary

Modifier and TypeField and Description
private ByteBuffer
private final DefaultByteBufferPool.LeakDetector
private final DefaultByteBufferPool
private volatile int
private static final AtomicIntegerFieldUpdater<DefaultByteBufferPool.DefaultPooledBuffer>

Constructor Summary

AccessConstructor and Description
pack-priv
DefaultPooledBuffer(DefaultByteBufferPool pool, ByteBuffer buffer, boolean detectLeaks)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements io.undertow.connector.PooledByteBuffer.close.

Closes this resource, relinquishing any underlying resources.

public ByteBuffer
public boolean
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
private ByteBuffer buffer
leakDetectorback to summary
private final DefaultByteBufferPool.LeakDetector leakDetector
poolback to summary
private final DefaultByteBufferPool pool
referenceCountback to summary
private volatile int referenceCount
referenceCountUpdaterback to summary
private static final AtomicIntegerFieldUpdater<DefaultByteBufferPool.DefaultPooledBuffer> referenceCountUpdater

Constructor Detail

DefaultPooledBufferback to summary
pack-priv DefaultPooledBuffer(DefaultByteBufferPool pool, ByteBuffer buffer, boolean detectLeaks)

Method Detail

closeback to summary
public void close()

Implements io.undertow.connector.PooledByteBuffer.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Annotations
@Override
getBufferback to summary
public ByteBuffer getBuffer()

Implements io.undertow.connector.PooledByteBuffer.getBuffer.

Annotations
@Override
isOpenback to summary
public boolean isOpen()

Implements io.undertow.connector.PooledByteBuffer.isOpen.

Annotations
@Override
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

Annotations
@Override
io.undertow.server back to summary

private Class DefaultByteBufferPool.LeakDetector

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Throwable
pack-priv volatile boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allocationPointback to summary
private final Throwable allocationPoint
closedback to summary
pack-priv volatile boolean closed

Constructor Detail

LeakDetectorback to summary
private LeakDetector()

Method Detail

finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method
io.undertow.server back to summary

private Class DefaultByteBufferPool.ThreadLocalCache

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv Map<Thread, DefaultByteBufferPool.ThreadLocalData>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv DefaultByteBufferPool.ThreadLocalData
get()

pack-priv void
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

localsByThreadback to summary
pack-priv Map<Thread, DefaultByteBufferPool.ThreadLocalData> localsByThread

Constructor Detail

ThreadLocalCacheback to summary
private ThreadLocalCache()

Method Detail

getback to summary
pack-priv DefaultByteBufferPool.ThreadLocalData get()
removeback to summary
pack-priv void remove(DefaultByteBufferPool.ThreadLocalData threadLocalData)
setback to summary
pack-priv void set(DefaultByteBufferPool.ThreadLocalData threadLocalData)
io.undertow.server back to summary

private Class DefaultByteBufferPool.ThreadLocalData

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv ArrayDeque<ByteBuffer>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allocationDepthback to summary
pack-priv int allocationDepth
buffersback to summary
pack-priv ArrayDeque<ByteBuffer> buffers

Constructor Detail

ThreadLocalDataback to summary
private ThreadLocalData()

Method Detail

finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method