Top Description Fields Methods
org.glassfish.grizzly.memory

public Interface MemoryManager<E extends Buffer>

extends MonitoringAware<MemoryProbe>
Known Direct Implementers
org.glassfish.grizzly.memory.PooledMemoryManager, org.glassfish.grizzly.memory.AbstractMemoryManager
Imports
org.glassfish.grizzly.Buffer, org.glassfish.grizzly.monitoring.MonitoringAware

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

Modifier and TypeField and Description
public static final MemoryManager<E extends Buffer>
DEFAULT_MEMORY_MANAGER

The default MemoryManager implementation used by all created builder instances.

Method Summary

Modifier and TypeMethod and Description
public E

Returns:

allocated Buffer.
allocate
(int
Buffer size to be allocated.
size
)

Allocated Buffer of the required size.

public E

Returns:

allocated Buffer.
allocateAtLeast
(int
the min Buffer size to be allocated.
size
)

Allocated Buffer at least of the provided size.

public E

Returns:

reallocated Buffer.
reallocate
(E
old Buffer to be reallocated.
oldBuffer
,
int
new Buffer required size.
newSize
)

Reallocate Buffer to a required size.

public void
release(E
Buffer to be released.
buffer
)

Release Buffer.

public 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 java.nio.ByteBuffer, or false otherwise.

Inherited from org.glassfish.grizzly.monitoring.MonitoringAware:
getMonitoringConfig

Field Detail

DEFAULT_MEMORY_MANAGERback to summary
public static final MemoryManager<E extends Buffer> 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 org.glassfish.grizzly.memory.DefaultMemoryManagerFactory interface. Note that this class must be public and have a public no-arg constructor.

Method Detail

allocateback to summary
public E allocate(int size)

Allocated Buffer of the required size.

Parameters
size:int

Buffer size to be allocated.

Returns:E

allocated Buffer.

allocateAtLeastback to summary
public 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:int

the min Buffer size to be allocated.

Returns:E

allocated Buffer.

reallocateback to summary
public 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:E

old Buffer to be reallocated.

newSize:int

new Buffer required size.

Returns:E

reallocated Buffer.

releaseback to summary
public 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:E

Buffer to be released.

willAllocateDirectback to summary
public 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 java.nio.ByteBuffer, or false otherwise.