org.glassfish.grizzly.memory
Interface MemoryManager<E extends Buffer>

All Superinterfaces:
JmxMonitoringAware<MemoryProbe>, MonitoringAware<MemoryProbe>
All Known Implementing Classes:
AbstractMemoryManager, ByteBufferManager, HeapMemoryManager

public interface MemoryManager<E extends Buffer>
extends JmxMonitoringAware<MemoryProbe>

MemoryManager, responsible for allocating and releasing memory, required during application runtime. MemoryManager implementations work with Grizzly Buffers.

Author:
Alexey Stashok
See Also:
Buffer

Field Summary
static MemoryManager DEFAULT_MEMORY_MANAGER
           The default MemoryManager implementation used by all created builder instances.
 
Method Summary
 E allocate(int size)
          Allocated Buffer of the required size.
 E allocateAtLeast(int size)
          Allocated Buffer at least of the provided size.
 E reallocate(E oldBuffer, int newSize)
          Reallocate Buffer to a required size.
 void release(E buffer)
          Release Buffer.
 boolean willAllocateDirect(int size)
          Return true if next allocate(int) or 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.
 
Methods inherited from interface org.glassfish.grizzly.monitoring.jmx.JmxMonitoringAware
getMonitoringConfig
 

Field Detail

DEFAULT_MEMORY_MANAGER

static final MemoryManager DEFAULT_MEMORY_MANAGER

The default MemoryManager implementation used by all created builder instances.

The default may be changed by 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.

Method Detail

allocate

E allocate(int size)
Allocated Buffer of the required size.

Parameters:
size - Buffer size to be allocated.
Returns:
allocated Buffer.

allocateAtLeast

E allocateAtLeast(int size)
Allocated 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.

Parameters:
size - the min Buffer size to be allocated.
Returns:
allocated Buffer.

reallocate

E reallocate(E oldBuffer,
             int newSize)
Reallocate 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.

Parameters:
oldBuffer - old Buffer to be reallocated.
newSize - new Buffer required size.
Returns:
reallocated Buffer.

release

void release(E buffer)
Release Buffer. Implementation may ignore releasing and let JVM Garbage collector to take care about the Buffer, or return Buffer to pool, in case of more complex MemoryManager implementation.

Parameters:
buffer - Buffer to be released.

willAllocateDirect

boolean willAllocateDirect(int size)
Return true if next allocate(int) or 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.

Parameters:
size -
Returns:


Copyright © 2012 Oracle Corporation. All Rights Reserved.