Package io.undertow.util
Class ReferenceCountedPooled
- java.lang.Object
-
- io.undertow.util.ReferenceCountedPooled
-
- All Implemented Interfaces:
PooledByteBuffer,java.io.Closeable,java.lang.AutoCloseable
public class ReferenceCountedPooled extends java.lang.Object implements 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 Class Summary
Nested Classes Modifier and Type Class Description static interfaceReferenceCountedPooled.FreeNotifier
-
Constructor Summary
Constructors Constructor Description ReferenceCountedPooled(PooledByteBuffer underlying, int referenceCount)ReferenceCountedPooled(PooledByteBuffer underlying, int referenceCount, ReferenceCountedPooled.FreeNotifier freeNotifier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()PooledByteBuffercreateView()PooledByteBuffercreateView(int viewSize)java.nio.ByteBuffergetBuffer()voidincreaseReferenceCount()booleanisFreed()booleanisOpen()java.lang.StringtoString()booleantryUnfree()
-
-
-
Constructor Detail
-
ReferenceCountedPooled
public ReferenceCountedPooled(PooledByteBuffer underlying, int referenceCount)
-
ReferenceCountedPooled
public ReferenceCountedPooled(PooledByteBuffer underlying, int referenceCount, ReferenceCountedPooled.FreeNotifier freeNotifier)
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfacePooledByteBuffer
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacePooledByteBuffer
-
isFreed
public boolean isFreed()
-
tryUnfree
public boolean tryUnfree()
-
getBuffer
public java.nio.ByteBuffer getBuffer() throws java.lang.IllegalStateException- Specified by:
getBufferin interfacePooledByteBuffer- Throws:
java.lang.IllegalStateException
-
createView
public PooledByteBuffer createView(int viewSize)
-
createView
public PooledByteBuffer createView()
-
increaseReferenceCount
public void increaseReferenceCount()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-