java.lang.Object
org.glassfish.grizzly.memory.AbstractMemoryManager<HeapBuffer>
org.glassfish.grizzly.memory.HeapMemoryManager
- All Implemented Interfaces:
MemoryManager<HeapBuffer>,ThreadLocalPoolProvider,WrapperAware,MonitoringAware<MemoryProbe>
- Since:
- 2.0
-
Nested Class Summary
Nested classes/interfaces inherited from class org.glassfish.grizzly.memory.AbstractMemoryManager
AbstractMemoryManager.TrimAware -
Field Summary
Fields inherited from class org.glassfish.grizzly.memory.AbstractMemoryManager
DEFAULT_MAX_BUFFER_SIZE, maxBufferSize, monitoringConfigFields inherited from interface org.glassfish.grizzly.memory.MemoryManager
DEFAULT_MEMORY_MANAGER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionallocate(int size) AllocatedBufferof the required size.allocateAtLeast(int size) AllocatedBufferat least of the provided size.protected HeapBufferallocateHeapBuffer(int size) Creates a new HeapBuffer with a a specified size.protected HeapBufferallocateHeapBufferAtLeast(int size) protected ObjectReturn the object associatedMonitoringConfig.reallocate(HeapBuffer oldBuffer, int newSize) ReallocateBufferto a required size.protected HeapBufferreallocateHeapBuffer(HeapBuffer oldHeapBuffer, int newSize) voidrelease(HeapBuffer buffer) ReleaseBuffer.protected final voidreleaseHeapBuffer(HeapBuffer heapBuffer) booleanwillAllocateDirect(int size) Return true if nextMemoryManager.allocate(int)orMemoryManager.allocateAtLeast(int)call, made in the current thread for the given memory size, going to return aBufferbased on directByteBuffer, or false otherwise.wrap(byte[] data) ReturnsBuffer, which wraps the byte array.wrap(byte[] data, int offset, int length) ReturnsBuffer, which wraps the part of byte array with specific offset and length.wrap(ByteBuffer byteBuffer) ReturnsBuffer, which wraps theByteBuffer.Methods inherited from class org.glassfish.grizzly.memory.AbstractMemoryManager
allocateFromPool, getMaxBufferSize, getReadyThreadBufferSize, getThreadLocalPool
-
Constructor Details
-
HeapMemoryManager
public HeapMemoryManager() -
HeapMemoryManager
public HeapMemoryManager(int maxBufferSize)
-
-
Method Details
-
allocate
AllocatedBufferof the required size.- Specified by:
allocatein interfaceMemoryManager<HeapBuffer>- Parameters:
size-Buffersize to be allocated.- Returns:
- allocated
Buffer.
-
allocateAtLeast
AllocatedBufferat 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.- Specified by:
allocateAtLeastin interfaceMemoryManager<HeapBuffer>- Parameters:
size- the minBuffersize to be allocated.- Returns:
- allocated
Buffer.
-
reallocate
ReallocateBufferto a required size. Implementation may choose the way, how reallocation could be done, either by allocating newBufferof required size and copying oldBuffercontent there, or perform more complex logic related to memory pooling etc.- Specified by:
reallocatein interfaceMemoryManager<HeapBuffer>- Parameters:
oldBuffer- oldBufferto be reallocated.newSize- newBufferrequired size.- Returns:
- reallocated
Buffer.
-
release
ReleaseBuffer. Implementation may ignore releasing and let JVM Garbage collector to take care about theBuffer, or returnBufferto pool, in case of more complex MemoryManager implementation.- Specified by:
releasein interfaceMemoryManager<HeapBuffer>- Parameters:
buffer-Bufferto be released.
-
willAllocateDirect
public boolean willAllocateDirect(int size) Return true if nextMemoryManager.allocate(int)orMemoryManager.allocateAtLeast(int)call, made in the current thread for the given memory size, going to return aBufferbased on directByteBuffer, or false otherwise.- Specified by:
willAllocateDirectin interfaceMemoryManager<HeapBuffer>- Returns:
-
getMonitoringConfig
Return the object associatedMonitoringConfig.- Specified by:
getMonitoringConfigin interfaceMonitoringAware<MemoryProbe>- Returns:
- the object associated
MonitoringConfig.
-
createThreadLocalPool
- Specified by:
createThreadLocalPoolin interfaceThreadLocalPoolProvider- Returns:
- a new
ThreadLocalPoolimplementation. This method must return a newThreadLocalPoolinstance per invocation.
-
createJmxManagementObject
- Specified by:
createJmxManagementObjectin classAbstractMemoryManager<HeapBuffer>- Returns:
- the JMX
Objectused to register/deregister with the JMX runtime.
-
wrap
ReturnsBuffer, which wraps the byte array.- Specified by:
wrapin interfaceWrapperAware- Parameters:
data- byte array to wrap- Returns:
Bufferwrapper on top of passed byte array.
-
wrap
ReturnsBuffer, which wraps the part of byte array with specific offset and length.- Specified by:
wrapin interfaceWrapperAware- Parameters:
data- byte array to wrapoffset- byte buffer offsetlength- byte buffer length- Returns:
Bufferwrapper on top of passed byte array.
-
wrap
- Specified by:
wrapin interfaceWrapperAware- Parameters:
s-String- Returns:
Bufferwrapper on top of passedString.
-
wrap
-
wrap
ReturnsBuffer, which wraps theByteBuffer.- Specified by:
wrapin interfaceWrapperAware- Parameters:
byteBuffer-ByteBufferto wrap- Returns:
Bufferwrapper on top of passedByteBuffer.
-
allocateHeapBuffer
Creates a new HeapBuffer with a a specified size.- Parameters:
size- size of buffer created- Returns:
-
allocateHeapBufferAtLeast
-
reallocateHeapBuffer
-
releaseHeapBuffer
-