org.apache.lucene.util
Class RecyclingByteBlockAllocator

java.lang.Object
  extended by org.apache.lucene.util.ByteBlockPool.Allocator
      extended by org.apache.lucene.util.RecyclingByteBlockAllocator

public final class RecyclingByteBlockAllocator
extends ByteBlockPool.Allocator

A ByteBlockPool.Allocator implementation that recycles unused byte blocks in a buffer and reuses them in subsequent calls to getByteBlock().

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

Field Summary
static int DEFAULT_BUFFERED_BLOCKS
           
 
Fields inherited from class org.apache.lucene.util.ByteBlockPool.Allocator
blockSize
 
Constructor Summary
RecyclingByteBlockAllocator()
          Creates a new RecyclingByteBlockAllocator with a block size of ByteBlockPool.BYTE_BLOCK_SIZE, upper buffered docs limit of DEFAULT_BUFFERED_BLOCKS (64) and a DummyConcurrentLock instance.
RecyclingByteBlockAllocator(int blockSize, int maxBufferedBlocks)
          Creates a new RecyclingByteBlockAllocator with a DummyConcurrentLock instance.
RecyclingByteBlockAllocator(int blockSize, int maxBufferedBlocks, AtomicLong bytesUsed)
          Creates a new RecyclingByteBlockAllocator
 
Method Summary
 long bytesUsed()
           
 int freeBlocks(int num)
          Removes the given number of byte blocks from the buffer if possible.
 byte[] getByteBlock()
           
 int maxBufferedBlocks()
           
 int numBufferedBlocks()
           
 void recycleByteBlocks(byte[][] blocks, int start, int end)
           
 
Methods inherited from class org.apache.lucene.util.ByteBlockPool.Allocator
recycleByteBlocks
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFERED_BLOCKS

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

RecyclingByteBlockAllocator

public RecyclingByteBlockAllocator(int blockSize,
                                   int maxBufferedBlocks,
                                   AtomicLong bytesUsed)
Creates a new RecyclingByteBlockAllocator

Parameters:
blockSize - the block size in bytes
maxBufferedBlocks - maximum number of buffered byte block
bytesUsed - AtomicLong reference counting internally allocated bytes
See Also:
DummyConcurrentLock

RecyclingByteBlockAllocator

public RecyclingByteBlockAllocator(int blockSize,
                                   int maxBufferedBlocks)
Creates a new RecyclingByteBlockAllocator with a DummyConcurrentLock instance.

Parameters:
blockSize - the block size in bytes
maxBufferedBlocks - maximum number of buffered byte block

RecyclingByteBlockAllocator

public RecyclingByteBlockAllocator()
Creates a new RecyclingByteBlockAllocator with a block size of ByteBlockPool.BYTE_BLOCK_SIZE, upper buffered docs limit of DEFAULT_BUFFERED_BLOCKS (64) and a DummyConcurrentLock instance.

Method Detail

getByteBlock

public byte[] getByteBlock()
Overrides:
getByteBlock in class ByteBlockPool.Allocator

recycleByteBlocks

public void recycleByteBlocks(byte[][] blocks,
                              int start,
                              int end)
Specified by:
recycleByteBlocks in class ByteBlockPool.Allocator

numBufferedBlocks

public int numBufferedBlocks()
Returns:
the number of currently buffered blocks

bytesUsed

public long bytesUsed()
Returns:
the number of bytes currently allocated by this ByteBlockPool.Allocator

maxBufferedBlocks

public int maxBufferedBlocks()
Returns:
the maximum number of buffered byte blocks

freeBlocks

public int freeBlocks(int num)
Removes the given number of byte blocks from the buffer if possible.

Parameters:
num - the number of byte blocks to remove
Returns:
the number of actually removed buffers


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.