org.glassfish.grizzly.memory
Class DefaultMemoryManager

java.lang.Object
  extended by org.glassfish.grizzly.memory.ByteBufferManager
      extended by org.glassfish.grizzly.memory.ByteBufferViewManager
          extended by org.glassfish.grizzly.memory.DefaultMemoryManager
All Implemented Interfaces:
MemoryManager<ByteBufferWrapper>, WrapperAware<ByteBufferWrapper>

public class DefaultMemoryManager
extends ByteBufferViewManager

Default MemoryManager, used in Grizzly. DefaultMemory has simple Buffer pooling implementation, which makes released Buffer's memory to be reused.

Author:
Alexey Stashok

Nested Class Summary
 class DefaultMemoryManager.BufferInfo
          Information about thread associated memory pool.
 class DefaultMemoryManager.TrimAwareWrapper
          ByteBufferWrapper implementation, which supports triming.
 
Field Summary
static int DEFAULT_MAX_BUFFER_SIZE
           
 
Fields inherited from class org.glassfish.grizzly.memory.ByteBufferViewManager
capacity, DEFAULT_CAPACITY, largeByteBuffer
 
Fields inherited from class org.glassfish.grizzly.memory.ByteBufferManager
isDirect
 
Constructor Summary
DefaultMemoryManager()
           
 
Method Summary
 ByteBufferWrapper allocate(int size)
          Allocates Buffer of required size.
 int getMaxThreadBufferSize()
          Get the maximum size of memory pool for one thread.
 int getReadyThreadBufferSize()
          Get the size of local thread memory pool.
 long getTotalBytesAllocated()
          Get real number of bytes allocated by this MemoryManager.
 boolean isMonitoring()
          Is monotoring enabled.
 ByteBufferWrapper reallocate(ByteBufferWrapper oldBuffer, int newSize)
          Reallocate Buffer to a required size.
 void release(ByteBufferWrapper buffer)
          Release Buffer.
 void setMaxThreadBufferSize(int maxThreadBufferSize)
          Set the maximum size of memory pool for one thread.
 void setMonitoring(boolean isMonitoring)
          Set monotoring mode.
 ByteBufferWrapper wrap(ByteBuffer byteBuffer)
          Returns Buffer, which wraps the ByteBuffer.
 
Methods inherited from class org.glassfish.grizzly.memory.ByteBufferViewManager
slice
 
Methods inherited from class org.glassfish.grizzly.memory.ByteBufferManager
allocate0, isDirect, setDirect, wrap, wrap, wrap, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_BUFFER_SIZE

public static final int DEFAULT_MAX_BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

DefaultMemoryManager

public DefaultMemoryManager()
Method Detail

getMaxThreadBufferSize

public int getMaxThreadBufferSize()
Get the maximum size of memory pool for one thread.

Returns:
the maximum size of memory pool for one thread.

setMaxThreadBufferSize

public void setMaxThreadBufferSize(int maxThreadBufferSize)
Set the maximum size of memory pool for one thread.

Parameters:
maxThreadBufferSize - the maximum size of memory pool for one thread.

isMonitoring

public boolean isMonitoring()
Is monotoring enabled.

Returns:
true, if monitoring is enabled, or false otherwise.

setMonitoring

public void setMonitoring(boolean isMonitoring)
Set monotoring mode.

Parameters:
isMonitoring - true, if monitoring is enabled, or false otherwise.

getTotalBytesAllocated

public long getTotalBytesAllocated()
Get real number of bytes allocated by this MemoryManager. It doesn't count bytes, which were pooled and then reused.

Returns:
real number of bytes allocated by this MemoryManager.

allocate

public ByteBufferWrapper allocate(int size)
Allocates Buffer of required size. First of all DefaultMemoryManager tries to reuse thread local memory pool. If it's not possible - it delegates allocation to ByteBufferViewManager.

Specified by:
allocate in interface MemoryManager<ByteBufferWrapper>
Overrides:
allocate in class ByteBufferViewManager
Parameters:
size - number of bytes to be allocated.
Returns:
allocated ByteBufferWrapper.

reallocate

public ByteBufferWrapper reallocate(ByteBufferWrapper oldBuffer,
                                    int newSize)
Reallocate Buffer to a required size. First of all DefaultMemoryManager tries to reuse thread local memory pool. If it's not possible - it delegates reallocation to ByteBufferViewManager.

Specified by:
reallocate in interface MemoryManager<ByteBufferWrapper>
Overrides:
reallocate in class ByteBufferViewManager
Parameters:
oldBuffer - old Buffer we want to reallocate.
newSize - Buffer required size.
Returns:
reallocated Buffer.

release

public void release(ByteBufferWrapper buffer)
Release Buffer. DefaultMemoryManager will checks if it's possible to return the buffer to thread local pool. If not - let's garbage collector utilize the memory.

Specified by:
release in interface MemoryManager<ByteBufferWrapper>
Overrides:
release in class ByteBufferManager
Parameters:
buffer - Buffer to be released.

getReadyThreadBufferSize

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

Returns:
the size of local thread memory pool.

wrap

public ByteBufferWrapper wrap(ByteBuffer byteBuffer)
Description copied from class: ByteBufferManager
Returns Buffer, which wraps the ByteBuffer.

Specified by:
wrap in interface WrapperAware<ByteBufferWrapper>
Overrides:
wrap in class ByteBufferManager
Parameters:
byteBuffer - ByteBuffer to wrap
Returns:
Buffer wrapper on top of passed ByteBuffer.


Copyright © 2009 SUN Microsystems. All Rights Reserved.