org.apache.directmemory.memory.allocator
Class SlabByteBufferAllocatorImpl

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

public class SlabByteBufferAllocatorImpl
extends AbstractByteBufferAllocator

ByteBufferAllocator implementation that uses FixedSizeByteBufferAllocatorImpl of different size to allocate best matching's size ByteBuffer

Since:
0.6

Field Summary
 
Fields inherited from class org.apache.directmemory.memory.allocator.AbstractByteBufferAllocator
logger
 
Constructor Summary
SlabByteBufferAllocatorImpl(int number, Collection<FixedSizeByteBufferAllocatorImpl> slabs, boolean allowAllocationToBiggerSlab)
          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()
           
 void free(ByteBuffer byteBuffer)
          Returns the given ByteBuffer making it available for a future usage.
 int getCapacity()
           
 
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

SlabByteBufferAllocatorImpl

public SlabByteBufferAllocatorImpl(int number,
                                   Collection<FixedSizeByteBufferAllocatorImpl> slabs,
                                   boolean allowAllocationToBiggerSlab)
Constructor.

Parameters:
number - : internal allocator identifier
slabs - : FixedSizeByteBufferAllocatorImpl to use for allocation
allowAllocationToBiggerSlab - : tells if it is allowed to look in a bigger slab to perform the request.
Method Detail

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.

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()
           throws IOException
Throws:
IOException


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