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, monitoringConfig
Fields inherited from interface org.glassfish.grizzly.memory.MemoryManager
DEFAULT_MEMORY_MANAGER
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionallocate
(int size) AllocatedBuffer
of the required size.allocateAtLeast
(int size) AllocatedBuffer
at least of the provided size.protected HeapBuffer
allocateHeapBuffer
(int size) Creates a new HeapBuffer with a a specified size.protected HeapBuffer
allocateHeapBufferAtLeast
(int size) protected Object
Return the object associatedMonitoringConfig
.reallocate
(HeapBuffer oldBuffer, int newSize) ReallocateBuffer
to a required size.protected HeapBuffer
reallocateHeapBuffer
(HeapBuffer oldHeapBuffer, int newSize) void
release
(HeapBuffer buffer) ReleaseBuffer
.protected final void
releaseHeapBuffer
(HeapBuffer heapBuffer) 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 aBuffer
based 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
AllocatedBuffer
of the required size.- Specified by:
allocate
in interfaceMemoryManager<HeapBuffer>
- Parameters:
size
-Buffer
size to be allocated.- Returns:
- allocated
Buffer
.
-
allocateAtLeast
AllocatedBuffer
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.- Specified by:
allocateAtLeast
in interfaceMemoryManager<HeapBuffer>
- Parameters:
size
- the minBuffer
size to be allocated.- Returns:
- allocated
Buffer
.
-
reallocate
ReallocateBuffer
to a required size. Implementation may choose the way, how reallocation could be done, either by allocating newBuffer
of required size and copying oldBuffer
content there, or perform more complex logic related to memory pooling etc.- Specified by:
reallocate
in interfaceMemoryManager<HeapBuffer>
- Parameters:
oldBuffer
- oldBuffer
to be reallocated.newSize
- newBuffer
required size.- Returns:
- reallocated
Buffer
.
-
release
ReleaseBuffer
. Implementation may ignore releasing and let JVM Garbage collector to take care about theBuffer
, or returnBuffer
to pool, in case of more complex MemoryManager implementation.- Specified by:
release
in interfaceMemoryManager<HeapBuffer>
- Parameters:
buffer
-Buffer
to 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 aBuffer
based on directByteBuffer
, or false otherwise.- Specified by:
willAllocateDirect
in interfaceMemoryManager<HeapBuffer>
- Returns:
-
getMonitoringConfig
Return the object associatedMonitoringConfig
.- Specified by:
getMonitoringConfig
in interfaceMonitoringAware<MemoryProbe>
- Returns:
- the object associated
MonitoringConfig
.
-
createThreadLocalPool
- Specified by:
createThreadLocalPool
in interfaceThreadLocalPoolProvider
- Returns:
- a new
ThreadLocalPool
implementation. This method must return a newThreadLocalPool
instance per invocation.
-
createJmxManagementObject
- Specified by:
createJmxManagementObject
in classAbstractMemoryManager<HeapBuffer>
- Returns:
- the JMX
Object
used to register/deregister with the JMX runtime.
-
wrap
ReturnsBuffer
, which wraps the byte array.- Specified by:
wrap
in interfaceWrapperAware
- Parameters:
data
- byte array to wrap- Returns:
Buffer
wrapper on top of passed byte array.
-
wrap
ReturnsBuffer
, which wraps the part of byte array with specific offset and length.- Specified by:
wrap
in interfaceWrapperAware
- Parameters:
data
- byte array to wrapoffset
- byte buffer offsetlength
- byte buffer length- Returns:
Buffer
wrapper on top of passed byte array.
-
wrap
- Specified by:
wrap
in interfaceWrapperAware
- Parameters:
s
-String
- Returns:
Buffer
wrapper on top of passedString
.
-
wrap
-
wrap
ReturnsBuffer
, which wraps theByteBuffer
.- Specified by:
wrap
in interfaceWrapperAware
- Parameters:
byteBuffer
-ByteBuffer
to wrap- Returns:
Buffer
wrapper on top of passedByteBuffer
.
-
allocateHeapBuffer
Creates a new HeapBuffer with a a specified size.- Parameters:
size
- size of buffer created- Returns:
-
allocateHeapBufferAtLeast
-
reallocateHeapBuffer
-
releaseHeapBuffer
-