org.apache.lucene.store.bytebuffer
Class CachingByteBufferAllocator

java.lang.Object
  extended by org.apache.lucene.store.bytebuffer.PlainByteBufferAllocator
      extended by org.apache.lucene.store.bytebuffer.CachingByteBufferAllocator
All Implemented Interfaces:
ByteBufferAllocator

public class CachingByteBufferAllocator
extends PlainByteBufferAllocator

The caching byte buffer allocator allows to define a global size for both the small and large buffers allocated. Those will be reused when possible.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.lucene.store.bytebuffer.ByteBufferAllocator
ByteBufferAllocator.Cleaner, ByteBufferAllocator.Type
 
Field Summary
 
Fields inherited from class org.apache.lucene.store.bytebuffer.PlainByteBufferAllocator
direct, largeBufferSizeInBytes, smallBufferSizeInBytes
 
Constructor Summary
CachingByteBufferAllocator(boolean direct, int smallBufferSizeInBytes, int largeBufferSizeInBytes, int smallCacheSizeInBytes, int largeCacheSizeInBytes)
           
 
Method Summary
 java.nio.ByteBuffer allocate(ByteBufferAllocator.Type type)
          Allocate a byte buffer for the specific type.
 void close()
          Close the allocator, releasing any cached buffers for example.
 void release(java.nio.ByteBuffer buffer)
          Release the buffer.
 
Methods inherited from class org.apache.lucene.store.bytebuffer.PlainByteBufferAllocator
sizeInBytes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingByteBufferAllocator

public CachingByteBufferAllocator(boolean direct,
                                  int smallBufferSizeInBytes,
                                  int largeBufferSizeInBytes,
                                  int smallCacheSizeInBytes,
                                  int largeCacheSizeInBytes)
Parameters:
direct - If set to true, will allocate direct buffers (off heap).
smallBufferSizeInBytes - The size (in bytes) of the small buffer allocation.
largeBufferSizeInBytes - The size (in bytes) of the large buffer allocation.
smallCacheSizeInBytes - The size of the small cache buffer in bytes.
largeCacheSizeInBytes - The size of the large cache buffer in bytes.
Method Detail

allocate

public java.nio.ByteBuffer allocate(ByteBufferAllocator.Type type)
                             throws java.io.IOException
Description copied from interface: ByteBufferAllocator
Allocate a byte buffer for the specific type.

Specified by:
allocate in interface ByteBufferAllocator
Overrides:
allocate in class PlainByteBufferAllocator
Throws:
java.io.IOException

release

public void release(java.nio.ByteBuffer buffer)
Description copied from interface: ByteBufferAllocator
Release the buffer.

Specified by:
release in interface ByteBufferAllocator
Overrides:
release in class PlainByteBufferAllocator

close

public void close()
Description copied from interface: ByteBufferAllocator
Close the allocator, releasing any cached buffers for example.

Specified by:
close in interface ByteBufferAllocator
Overrides:
close in class PlainByteBufferAllocator