Top Description Inners Fields Constructors Methods
io.undertow.util

public Class ReferenceCountedPooled

extends Object
implements PooledByteBuffer
Class Inheritance
All Implemented Interfaces
io.undertow.connector.PooledByteBuffer, java.io.Closeable, java.lang.AutoCloseable
Imports
java.nio.ByteBuffer, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, io.undertow.UndertowMessages, io.undertow.connector.PooledByteBuffer

A reference counted pooled implementation, that basically consists of a main buffer, that can be sliced off into smaller buffers, and the underlying buffer will not be freed until all the slices and the main buffer itself have also been freed. This also supports the notion of un-freeing the main buffer. Basically this allows the buffer be re-used, so if only a small slice of the buffer was used for read operations the main buffer can potentially be re-used. This prevents buffer exhaustion attacks where content is sent in many small packets, and you end up allocating a large number of buffers to hold a small amount of data.
Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Field Summary

Modifier and TypeField and Description
private final ReferenceCountedPooled.FreeNotifier
pack-priv boolean
private volatile int
private static final AtomicIntegerFieldUpdater<ReferenceCountedPooled>
private ByteBuffer
private final PooledByteBuffer

Constructor Summary

AccessConstructor and Description
public
ReferenceCountedPooled(PooledByteBuffer underlying, int referenceCount)

public
ReferenceCountedPooled(PooledByteBuffer underlying, int referenceCount, ReferenceCountedPooled.FreeNotifier freeNotifier)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements io.undertow.connector.PooledByteBuffer.close.

Closes this resource, relinquishing any underlying resources.

public PooledByteBuffer
createView(int viewSize)

public PooledByteBuffer
private void
public ByteBuffer
public void
public boolean
public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

freeNotifierback to summary
private final ReferenceCountedPooled.FreeNotifier freeNotifier
mainFreedback to summary
pack-priv boolean mainFreed
referenceCountback to summary
private volatile int referenceCount
Annotations
@SuppressWarnings:unused
referenceCountUpdaterback to summary
private static final AtomicIntegerFieldUpdater<ReferenceCountedPooled> referenceCountUpdater
sliceback to summary
private ByteBuffer slice
underlyingback to summary
private final PooledByteBuffer underlying

Constructor Detail

ReferenceCountedPooledback to summary
public ReferenceCountedPooled(PooledByteBuffer underlying, int referenceCount)
ReferenceCountedPooledback to summary
public ReferenceCountedPooled(PooledByteBuffer underlying, int referenceCount, ReferenceCountedPooled.FreeNotifier freeNotifier)

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
createViewback to summary
public PooledByteBuffer createView(int viewSize)
createViewback to summary
public PooledByteBuffer createView()
freeInternalback to summary
private void freeInternal()
getBufferback to summary
public ByteBuffer getBuffer() throws IllegalStateException

Implements io.undertow.connector.PooledByteBuffer.getBuffer.

Annotations
@Override
increaseReferenceCountback to summary
public void increaseReferenceCount()
isFreedback to summary
public boolean isFreed()
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
tryUnfreeback to summary
public boolean tryUnfree()
io.undertow.util back to summary

public Interface ReferenceCountedPooled.FreeNotifier


Method Summary

Modifier and TypeMethod and Description
public void

Method Detail

freedback to summary
public void freed()