com.bigdata.io
Class DirectBufferPoolAllocator

java.lang.Object
  extended by com.bigdata.io.DirectBufferPoolAllocator

public class DirectBufferPoolAllocator
extends Object

An allocator for ByteBuffer slices backed by direct ByteBuffers allocated against a DirectBufferPool.

Version:
$Id: DirectBufferPoolAllocator.java 4673 2011-06-09 18:43:36Z thompsonbry $
Author:
Bryan Thompson
TODO:
Make the type of the identifier for the DirectBufferPoolAllocator.IAllocation generic using a factory pattern (we need UUID for scale-out, but the class could be reused for other purposes as well). [The allocation context identifier should continue to be an application specified object.]

Nested Class Summary
static interface DirectBufferPoolAllocator.IAllocation
          An allocation against a direct ByteBuffer.
static interface DirectBufferPoolAllocator.IAllocationContext
          An allocation context links some application specified key with a list of direct ByteBuffers on which allocations have been made by the application.
 
Constructor Summary
DirectBufferPoolAllocator(DirectBufferPool pool)
           
 
Method Summary
 void close()
          Releases all DirectBufferPoolAllocator.IAllocationContexts and all direct ByteBuffer s which they are using.
protected  void finalize()
          Extended to close() the allocator.
 DirectBufferPoolAllocator.IAllocation getAllocation(UUID id)
          Return the allocation associated with that id.
 DirectBufferPoolAllocator.IAllocationContext getAllocationContext(Object key)
          Return an allocation context for the key.
 int getMaxSlotSize()
          The maximum #of bytes in a single DirectBufferPoolAllocator.IAllocation.
static void put(byte[] src, DirectBufferPoolAllocator.IAllocation[] a)
          Copy the caller's data onto the ordered array of allocations.
static void put(ByteBuffer src, DirectBufferPoolAllocator.IAllocation[] a)
          Copy the caller's data onto the ordered array of allocations.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirectBufferPoolAllocator

public DirectBufferPoolAllocator(DirectBufferPool pool)
Parameters:
pool - The pool from which the direct ByteBuffers are allocated.
Method Detail

finalize

protected void finalize()
                 throws Throwable
Extended to close() the allocator.

Overrides:
finalize in class Object
Throws:
Throwable

close

public void close()
Releases all DirectBufferPoolAllocator.IAllocationContexts and all direct ByteBuffer s which they are using.


getMaxSlotSize

public int getMaxSlotSize()
The maximum #of bytes in a single DirectBufferPoolAllocator.IAllocation.


getAllocationContext

public DirectBufferPoolAllocator.IAllocationContext getAllocationContext(Object key)
Return an allocation context for the key. If none exists for that key, then one is atomically created and returned.

Parameters:
key - A key which uniquely identifies that context. The key will be inserted into a hash table and therefore must have appropriate hashCode() and equals() methods.
Returns:
The allocation context.

getAllocation

public DirectBufferPoolAllocator.IAllocation getAllocation(UUID id)
Return the allocation associated with that id.

Parameters:
id - The allocation identifier.
Returns:
The allocation -or- null if there is no such allocation.

put

public static void put(byte[] src,
                       DirectBufferPoolAllocator.IAllocation[] a)
Copy the caller's data onto the ordered array of allocations. The position of each allocation will be advanced by the #of bytes copied into that allocation.

Parameters:
src - The source data.
a - The allocations.
Throws:
BufferOverflowException - if there is not enough room in the allocations for the data to be copied.

put

public static void put(ByteBuffer src,
                       DirectBufferPoolAllocator.IAllocation[] a)
Copy the caller's data onto the ordered array of allocations. The position of each allocation will be advanced by the #of bytes copied into that allocation.

Parameters:
src - The source data.
a - The allocations.
Throws:
BufferOverflowException - if there is not enough room in the allocations for the data to be copied.


Copyright © 2006-2012 SYSTAP, LLC. All Rights Reserved.