org.apache.directmemory.memory.allocator
Class FixedSizeByteBufferAllocatorImpl

java.lang.Object
  extended by org.apache.directmemory.memory.allocator.AbstractByteBufferAllocator
      extended by org.apache.directmemory.memory.allocator.FixedSizeByteBufferAllocatorImpl
All Implemented Interfaces:
Closeable, ByteBufferAllocator

public class FixedSizeByteBufferAllocatorImpl
extends AbstractByteBufferAllocator

ByteBufferAllocator implementation that instantiate ByteBuffers of fixed size, called slices.

Since:
0.6

Field Summary
 
Fields inherited from class org.apache.directmemory.memory.allocator.AbstractByteBufferAllocator
logger
 
Constructor Summary
FixedSizeByteBufferAllocatorImpl(int number, int totalSize, int sliceSize, int numberOfSegments)
          Constructor.
 
Method Summary
 ByteBuffer allocate(int size)
          Allocates and returns a ByteBuffer with Buffer.limit() set to the given size.
 void clear()
          Clear all allocated ByteBuffer, resulting in a empty and ready to deserve ByteBufferAllocator
 void close()
           
protected  ByteBuffer findFreeBuffer(int capacity)
           
 void free(ByteBuffer byteBuffer)
          Returns the given ByteBuffer making it available for a future usage.
 int getCapacity()
           
 int getSliceSize()
           
protected  void init(int numberOfSegments)
           
 
Methods inherited from class org.apache.directmemory.memory.allocator.AbstractByteBufferAllocator
getHash, getLogger, getNumber, isClosed, setClosed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedSizeByteBufferAllocatorImpl

public FixedSizeByteBufferAllocatorImpl(int number,
                                        int totalSize,
                                        int sliceSize,
                                        int numberOfSegments)
Constructor.

Parameters:
number - : internal identifier of the allocator
totalSize - : the internal buffer
sliceSize - : arbitrary number of the buffer.
numberOfSegments - : number of parent ByteBuffer to allocate.
Method Detail

init

protected void init(int numberOfSegments)

findFreeBuffer

protected ByteBuffer findFreeBuffer(int capacity)

free

public void free(ByteBuffer byteBuffer)
Description copied from interface: ByteBufferAllocator
Returns the given ByteBuffer making it available for a future usage. Returning twice a ByteBuffer won't throw an exception.

Parameters:
byteBuffer - : the ByteBuffer to return

allocate

public ByteBuffer allocate(int size)
Description copied from interface: ByteBufferAllocator
Allocates and returns a ByteBuffer with Buffer.limit() set to the given size. When the allocation fails, it returns either null or throws an BufferOverflowException, depending on the implementation.

Parameters:
size - : the size in byte to allocate
Returns:
a ByteBuffer of the given size, or either return null or throw an BufferOverflowException when the allocation fails.

getSliceSize

public int getSliceSize()

clear

public void clear()
Description copied from interface: ByteBufferAllocator
Clear all allocated ByteBuffer, resulting in a empty and ready to deserve ByteBufferAllocator


getCapacity

public int getCapacity()
Returns:
the internal total size that can be allocated

close

public void close()


Copyright © 2011-2012 The Apache Software Foundation. All Rights Reserved.