Module org.glassfish.grizzly
Package org.glassfish.grizzly.memory
Interface MemoryManager<E extends Buffer>
- All Superinterfaces:
MonitoringAware<MemoryProbe>
- All Known Implementing Classes:
AbstractMemoryManager
,ByteBufferManager
,HeapMemoryManager
,PooledMemoryManager
MemoryManager, responsible for allocating and releasing memory, required during application runtime.
MemoryManager implementations work with Grizzly
Buffer
s.- Author:
- Alexey Stashok
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final MemoryManager
The defaultMemoryManager
implementation used by all created builder instances. -
Method Summary
Modifier and TypeMethodDescriptionallocate
(int size) AllocatedBuffer
of the required size.allocateAtLeast
(int size) AllocatedBuffer
at least of the provided size.reallocate
(E oldBuffer, int newSize) ReallocateBuffer
to a required size.void
ReleaseBuffer
.boolean
willAllocateDirect
(int size) Return true if nextallocate(int)
orallocateAtLeast(int)
call, made in the current thread for the given memory size, going to return aBuffer
based on directByteBuffer
, or false otherwise.Methods inherited from interface org.glassfish.grizzly.monitoring.MonitoringAware
getMonitoringConfig
-
Field Details
-
DEFAULT_MEMORY_MANAGER
The default
MemoryManager
implementation used by all created builder instances.The default may be changed by one of two methods:
- Setting the system property "org.glassfish.grizzly.DEFAULT_MEMORY_MANAGER" with the fully qualified name of the class that implements the MemoryManager interface. Note that this class must be public and have a public no-arg constructor.
- Setting the system property "org.glassfish.grizzly.MEMORY_MANAGER_FACTORY" with the fully qualified name of
the class that implements the
DefaultMemoryManagerFactory
interface. Note that this class must be public and have a public no-arg constructor.
-
-
Method Details
-
allocate
AllocatedBuffer
of the required size. -
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. -
reallocate
-
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.- Parameters:
buffer
-Buffer
to be released.
-
willAllocateDirect
boolean willAllocateDirect(int size) Return true if nextallocate(int)
orallocateAtLeast(int)
call, made in the current thread for the given memory size, going to return aBuffer
based on directByteBuffer
, or false otherwise.- Parameters:
size
-- Returns:
-