com.thimbleware.jmemcached.storage.bytebuffer
Class ByteBufferBlockStore

java.lang.Object
  extended by com.thimbleware.jmemcached.storage.bytebuffer.ByteBufferBlockStore
Direct Known Subclasses:
MemoryMappedBlockStore

public class ByteBufferBlockStore
extends java.lang.Object

Memory mapped block storage mechanism with a free-list maintained by TreeMap Allows memory for storage to be mapped outside of the VM's main memory, and outside the purvey of the GC. Should offer O(Log(N)) search and free of blocks.


Nested Class Summary
static class ByteBufferBlockStore.BadAllocationException
          Exception thrown on inability to allocate a new block
static class ByteBufferBlockStore.ByteBufferBlockStoreFactory
           
 
Field Summary
protected  org.jboss.netty.buffer.ChannelBuffer storageBuffer
           
 
Constructor Summary
protected ByteBufferBlockStore(int blockSizeBytes)
          Constructor used only be subclasses, allowing them to provide their own buffer.
 
Method Summary
 Region alloc(int desiredSize, org.jboss.netty.buffer.ChannelBuffer data)
          Allocate a region in the block storage
 void clear()
           
 void close()
          Close the store, destroying all data and closing the backing file
 void free(Region region)
           
protected  void freeResources()
           
 org.jboss.netty.buffer.ChannelBuffer get(Region region)
           
 int getBlockSizeBytes()
           
static BlockStoreFactory getFactory()
           
 long getFreeBytes()
           
 long getStoreSizeBytes()
           
protected  void initialize(int storeSizeBytes)
           
static long roundUp(long size, long blockSize)
          Rounds up a requested size to the nearest block width.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

storageBuffer

protected org.jboss.netty.buffer.ChannelBuffer storageBuffer
Constructor Detail

ByteBufferBlockStore

protected ByteBufferBlockStore(int blockSizeBytes)
Constructor used only be subclasses, allowing them to provide their own buffer.

Method Detail

getFactory

public static BlockStoreFactory getFactory()

initialize

protected void initialize(int storeSizeBytes)

roundUp

public static long roundUp(long size,
                           long blockSize)
Rounds up a requested size to the nearest block width.

Parameters:
size - the requested size
blockSize - the block size to use
Returns:
the actual mount to use

close

public void close()
           throws java.io.IOException
Close the store, destroying all data and closing the backing file

Throws:
java.io.IOException - thrown on failure to close file

freeResources

protected void freeResources()
                      throws java.io.IOException
Throws:
java.io.IOException

alloc

public Region alloc(int desiredSize,
                    org.jboss.netty.buffer.ChannelBuffer data)
Allocate a region in the block storage

Parameters:
desiredSize - size (in bytes) desired for the region
data - initial data to place in it
Returns:
the region descriptor

get

public org.jboss.netty.buffer.ChannelBuffer get(Region region)

free

public void free(Region region)

clear

public void clear()

getStoreSizeBytes

public long getStoreSizeBytes()

getBlockSizeBytes

public int getBlockSizeBytes()

getFreeBytes

public long getFreeBytes()


Copyright © 2008-2011 ThimbleWare. All Rights Reserved.