org.glassfish.grizzly.memory
Class AbstractMemoryManager<E extends Buffer>

java.lang.Object
  extended by org.glassfish.grizzly.memory.AbstractMemoryManager<E>
All Implemented Interfaces:
MemoryManager<E>, ThreadLocalPoolProvider, JmxMonitoringAware<MemoryProbe>, MonitoringAware<MemoryProbe>
Direct Known Subclasses:
ByteBufferManager, HeapMemoryManager

public abstract class AbstractMemoryManager<E extends Buffer>
extends Object
implements MemoryManager<E>, ThreadLocalPoolProvider

A MemoryManager abstraction to provide utilities that may be useful across different MemoryManager implementations.

Since:
2.0

Nested Class Summary
protected static interface AbstractMemoryManager.TrimAware
          This is a marker interface indicating a particular Buffer implementation can be trimmed.
 
Field Summary
static int DEFAULT_MAX_BUFFER_SIZE
          The maximum size of the memory pool that is to be maintained by either the MemoryManager itself or any ThreadLocalPools.
protected  int maxBufferSize
           
protected  AbstractJmxMonitoringConfig<MemoryProbe> monitoringConfig
          Basic monitoring support.
 
Fields inherited from interface org.glassfish.grizzly.memory.MemoryManager
DEFAULT_MEMORY_MANAGER
 
Constructor Summary
AbstractMemoryManager()
          Creates a new AbstractMemoryManager using a max buffer size of 65536.
AbstractMemoryManager(int maxBufferSize)
          Creates a new AbstractMemoryManager using the specified buffer size.
 
Method Summary
protected  Object allocateFromPool(ThreadLocalPool threadLocalCache, int size)
          Allocate a Buffer using the provided ThreadLocalPool.
protected abstract  JmxObject createJmxManagementObject()
           
 int getMaxBufferSize()
           
 int getReadyThreadBufferSize()
          Get the size of local thread memory pool.
protected static ThreadLocalPool getThreadLocalPool()
          Get thread associated buffer pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.glassfish.grizzly.memory.MemoryManager
allocate, allocateAtLeast, reallocate, release, willAllocateDirect
 
Methods inherited from interface org.glassfish.grizzly.monitoring.jmx.JmxMonitoringAware
getMonitoringConfig
 
Methods inherited from interface org.glassfish.grizzly.memory.ThreadLocalPoolProvider
createThreadLocalPool
 

Field Detail

DEFAULT_MAX_BUFFER_SIZE

public static final int DEFAULT_MAX_BUFFER_SIZE
The maximum size of the memory pool that is to be maintained by either the MemoryManager itself or any ThreadLocalPools.

See Also:
Constant Field Values

monitoringConfig

protected final AbstractJmxMonitoringConfig<MemoryProbe> monitoringConfig
Basic monitoring support. Concrete implementations of this class need only to implement the createJmxManagementObject() method to plug into the Grizzly 2.0 JMX framework.


maxBufferSize

protected final int maxBufferSize
Constructor Detail

AbstractMemoryManager

public AbstractMemoryManager()
Creates a new AbstractMemoryManager using a max buffer size of 65536.


AbstractMemoryManager

public AbstractMemoryManager(int maxBufferSize)
Creates a new AbstractMemoryManager using the specified buffer size.

Parameters:
maxBufferSize - max size of the maintained buffer.
Method Detail

getReadyThreadBufferSize

public int getReadyThreadBufferSize()
Get the size of local thread memory pool.

Returns:
the size of local thread memory pool.

getMaxBufferSize

public int getMaxBufferSize()
Returns:
the max size of the buffer maintained by this AbstractMemoryManager.

allocateFromPool

protected Object allocateFromPool(ThreadLocalPool threadLocalCache,
                                  int size)
Allocate a Buffer using the provided ThreadLocalPool.

Parameters:
threadLocalCache - the ThreadLocalPool to allocate from.
size - the amount to allocate.
Returns:
an memory buffer, or null if the requested size exceeds the remaining free memory of the ThreadLocalPool.

createJmxManagementObject

protected abstract JmxObject createJmxManagementObject()
Returns:
the JmxObject used to register/deregister with the JMX runtime.

getThreadLocalPool

protected static ThreadLocalPool getThreadLocalPool()
Get thread associated buffer pool.

Returns:
thread associated buffer pool. This method may return null if the current thread doesn't have a buffer pool associated with it.


Copyright © 2012 Oracle Corporation. All Rights Reserved.