com.sun.grizzly.memory
Class ByteBufferViewManager

java.lang.Object
  extended by com.sun.grizzly.memory.ByteBufferManager
      extended by com.sun.grizzly.memory.ByteBufferViewManager
All Implemented Interfaces:
MemoryManager<ByteBufferWrapper>, WrapperAware<ByteBufferWrapper>
Direct Known Subclasses:
DefaultMemoryManager

public class ByteBufferViewManager
extends ByteBufferManager

The ByteBufferManager implementation, which doesn't allocate ByteBuffers each time allocate is called. Instead of this, implementation preallocates large ByteBuffer pool, and returns ByteBuffer view of required size for each allocate method call.

Author:
Jean-Francois Arcand, Alexey Stashok
See Also:
MemoryManager, ByteBufferManager, ByteBuffer

Field Summary
protected  int capacity
          Capacity of the large ByteBuffer pool.
static int DEFAULT_CAPACITY
          The default capacity of the ByteBuffer from which views will be created.
protected  ByteBuffer largeByteBuffer
          Large ByteBuffer pool.
 
Fields inherited from class com.sun.grizzly.memory.ByteBufferManager
isDirect
 
Constructor Summary
ByteBufferViewManager()
           
ByteBufferViewManager(boolean isDirect)
           
ByteBufferViewManager(boolean isDirect, int capacity)
           
 
Method Summary
 ByteBufferWrapper allocate(int size)
          Allocates Buffer of required size, which is actually sliced from large preallocated ByteBuffer pool.
 ByteBufferWrapper reallocate(ByteBufferWrapper oldBuffer, int newSize)
          Reallocate Buffer to a required size.
protected static ByteBuffer slice(ByteBuffer chunk, int size)
          Slice ByteBuffer of required size from big chunk.
 
Methods inherited from class com.sun.grizzly.memory.ByteBufferManager
allocate0, isDirect, release, setDirect, wrap, 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_CAPACITY

public static final int DEFAULT_CAPACITY
The default capacity of the ByteBuffer from which views will be created.

See Also:
Constant Field Values

largeByteBuffer

protected ByteBuffer largeByteBuffer
Large ByteBuffer pool.


capacity

protected int capacity
Capacity of the large ByteBuffer pool.

Constructor Detail

ByteBufferViewManager

public ByteBufferViewManager()

ByteBufferViewManager

public ByteBufferViewManager(boolean isDirect)

ByteBufferViewManager

public ByteBufferViewManager(boolean isDirect,
                             int capacity)
Method Detail

allocate

public ByteBufferWrapper allocate(int size)
Allocates Buffer of required size, which is actually sliced from large preallocated ByteBuffer pool.

Specified by:
allocate in interface MemoryManager<ByteBufferWrapper>
Overrides:
allocate in class ByteBufferManager
Parameters:
size - size of the Buffer to be allocated.
Returns:
Buffer of required size, which is actualled sliced from large preallocated ByteBuffer pool.

reallocate

public ByteBufferWrapper reallocate(ByteBufferWrapper 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.

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

slice

protected static ByteBuffer slice(ByteBuffer chunk,
                                  int size)
Slice ByteBuffer of required size from big chunk.

Parameters:
chunk - big ByteBuffer pool.
size - required slice size.
Returns:
sliced ByteBuffer of required size.


Copyright © 2009 SUN Microsystems. All Rights Reserved.