public class ByteBufferManager extends AbstractMemoryManager<ByteBufferWrapper> implements WrapperAware, ByteBufferAware
ByteBuffers. It's possible to work either with direct or heap
ByteBuffers.MemoryManager,
ByteBuffer| Modifier and Type | Class and Description |
|---|---|
protected class |
ByteBufferManager.SmallByteBufferWrapper
ByteBufferWrapper implementation, which supports trimming. |
AbstractMemoryManager.TrimAware| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_SMALL_BUFFER_SIZE
TODO: Document
|
protected boolean |
isDirect
Is direct ByteBuffer should be used?
|
protected int |
maxSmallBufferSize |
DEFAULT_MAX_BUFFER_SIZE, maxBufferSize, monitoringConfigDEFAULT_MEMORY_MANAGER| Constructor and Description |
|---|
ByteBufferManager() |
ByteBufferManager(boolean isDirect) |
ByteBufferManager(boolean isDirect,
int maxBufferSize,
int maxSmallBufferSize) |
| Modifier and Type | Method and Description |
|---|---|
ByteBufferWrapper |
allocate(int size)
Allocated
Buffer of the required size. |
ByteBufferWrapper |
allocateAtLeast(int size)
Allocated
Buffer at least of the provided size. |
ByteBuffer |
allocateByteBuffer(int size)
Allocates
ByteBuffer of required size. |
protected ByteBuffer |
allocateByteBuffer0(int size) |
ByteBuffer |
allocateByteBufferAtLeast(int size)
Allocates
ByteBuffer of required size. |
protected Object |
createJmxManagementObject()
Create the Memory Manager JMX management object.
|
protected ByteBufferManager.SmallByteBufferWrapper |
createSmallBuffer() |
ThreadLocalPool |
createThreadLocalPool() |
int |
getMaxSmallBufferSize() |
MonitoringConfig<MemoryProbe> |
getMonitoringConfig()
Return the object associated
MonitoringConfig. |
boolean |
isDirect()
Returns true, if ByteBufferManager works with direct
ByteBuffers, or false otherwise. |
ByteBufferWrapper |
reallocate(ByteBufferWrapper oldBuffer,
int newSize)
Reallocate
Buffer to a required size. |
ByteBuffer |
reallocateByteBuffer(ByteBuffer oldByteBuffer,
int newSize) |
void |
release(ByteBufferWrapper buffer)
Lets JVM Garbage collector to release buffer.
|
void |
releaseByteBuffer(ByteBuffer byteBuffer) |
void |
setDirect(boolean isDirect)
Set true, if ByteBufferManager works with direct
ByteBuffers, or false otherwise. |
boolean |
willAllocateDirect(int size)
Return true if next
MemoryManager.allocate(int) or MemoryManager.allocateAtLeast(int) call,
made in the current thread for the given memory size, going to return a Buffer based
on direct ByteBuffer, or false otherwise. |
ByteBufferWrapper |
wrap(byte[] data)
Returns
Buffer, which wraps the byte array. |
ByteBufferWrapper |
wrap(byte[] data,
int offset,
int length)
Returns
Buffer, which wraps the part of byte array with
specific offset and length. |
ByteBufferWrapper |
wrap(ByteBuffer byteBuffer)
Returns
Buffer, which wraps the ByteBuffer. |
ByteBufferWrapper |
wrap(String s)
|
ByteBufferWrapper |
wrap(String s,
Charset charset)
|
allocateFromPool, getMaxBufferSize, getReadyThreadBufferSize, getThreadLocalPoolpublic static final int DEFAULT_SMALL_BUFFER_SIZE
protected boolean isDirect
protected final int maxSmallBufferSize
public ByteBufferManager()
public ByteBufferManager(boolean isDirect)
public ByteBufferManager(boolean isDirect,
int maxBufferSize,
int maxSmallBufferSize)
public int getMaxSmallBufferSize()
public ByteBufferWrapper allocate(int size)
Buffer of the required size.allocate in interface MemoryManager<ByteBufferWrapper>size - Buffer size to be allocated.Buffer.public ByteBufferWrapper allocateAtLeast(int size)
Buffer at least of the provided size.
This could be useful for usecases like Socket.read(...), where
we're not sure how many bytes are available, but want to read as
much as possible.allocateAtLeast in interface MemoryManager<ByteBufferWrapper>size - the min Buffer size to be allocated.Buffer.public ByteBufferWrapper reallocate(ByteBufferWrapper oldBuffer, int newSize)
Buffer to a required size.
Implementation may choose the way, how reallocation could be done, either
by allocating new Buffer of required size and copying old
Buffer content there, or perform more complex logic related to
memory pooling etc.reallocate in interface MemoryManager<ByteBufferWrapper>oldBuffer - old Buffer to be reallocated.newSize - new Buffer required size.Buffer.public void release(ByteBufferWrapper buffer)
release in interface MemoryManager<ByteBufferWrapper>buffer - Buffer to be released.public boolean isDirect()
ByteBuffers, or false otherwise.ByteBuffers, or false otherwise.public void setDirect(boolean isDirect)
ByteBuffers, or false otherwise.isDirect - true, if ByteBufferManager works with
direct ByteBuffers, or false otherwise.public boolean willAllocateDirect(int size)
MemoryManager.allocate(int) or MemoryManager.allocateAtLeast(int) call,
made in the current thread for the given memory size, going to return a Buffer based
on direct ByteBuffer, or false otherwise.willAllocateDirect in interface MemoryManager<ByteBufferWrapper>public ByteBufferWrapper wrap(byte[] data)
Buffer, which wraps the byte array.wrap in interface WrapperAwaredata - byte array to wrapBuffer wrapper on top of passed byte array.public ByteBufferWrapper wrap(byte[] data, int offset, int length)
Buffer, which wraps the part of byte array with
specific offset and length.wrap in interface WrapperAwaredata - byte array to wrapoffset - byte buffer offsetlength - byte buffer lengthBuffer wrapper on top of passed byte array.public ByteBufferWrapper wrap(String s)
wrap in interface WrapperAwares - StringBuffer wrapper on top of passed String.public ByteBufferWrapper wrap(String s, Charset charset)
public ThreadLocalPool createThreadLocalPool()
createThreadLocalPool in interface ThreadLocalPoolProviderThreadLocalPool implementation. This method
must return a new ThreadLocalPool instance per invocation.public ByteBufferWrapper wrap(ByteBuffer byteBuffer)
Buffer, which wraps the ByteBuffer.wrap in interface WrapperAwarebyteBuffer - ByteBuffer to wrapBuffer wrapper on top of passed ByteBuffer.public ByteBuffer allocateByteBuffer(int size)
ByteBuffer of required size.allocateByteBuffer in interface ByteBufferAwaresize - ByteBuffer size.ByteBuffer.public ByteBuffer allocateByteBufferAtLeast(int size)
ByteBuffer of required size.allocateByteBufferAtLeast in interface ByteBufferAwaresize - ByteBuffer size.ByteBuffer.public ByteBuffer reallocateByteBuffer(ByteBuffer oldByteBuffer, int newSize)
reallocateByteBuffer in interface ByteBufferAwarepublic void releaseByteBuffer(ByteBuffer byteBuffer)
releaseByteBuffer in interface ByteBufferAwareprotected ByteBufferManager.SmallByteBufferWrapper createSmallBuffer()
public MonitoringConfig<MemoryProbe> getMonitoringConfig()
MonitoringAwareMonitoringConfig.getMonitoringConfig in interface MonitoringAware<MemoryProbe>MonitoringConfig.protected Object createJmxManagementObject()
createJmxManagementObject in class AbstractMemoryManager<ByteBufferWrapper>protected final ByteBuffer allocateByteBuffer0(int size)
Copyright © 2016 Oracle Corporation. All Rights Reserved.