Class AbstractBlockBasedDataStore
- java.lang.Object
-
- net.timewalker.ffmq4.storage.data.impl.AbstractDataStore
-
- net.timewalker.ffmq4.storage.data.impl.AbstractBlockBasedDataStore
-
- All Implemented Interfaces:
DataStore,LinkedDataStore
- Direct Known Subclasses:
BlockBasedDataStore,JournalingBlockBasedDataStore
public abstract class AbstractBlockBasedDataStore extends AbstractDataStore
Block-based data store with journal support
Implements a mix between a block-based file system structure and a doubly-linked list.
Disk layout of the allocation table :
blockCount | 4 bytes (int) | Number of blocks in store blockSize | 4 bytes (int) | Size of a storage block firstClusterIndex | 4 bytes (int) | Index of the first block allocationTable (*blockCount allocation entries) flags | 1 byte | Flags indicating the block usage allocatedSize | 4 bytes (int) | Size of the actual data stored in this block previousClusterIndex | 4 bytes (int) | Index of the previous block nextClusterIndex | 4 bytes (int) | Index of the next blockDisk layout of the data store :
blocks (*blockCount blocks of size blockSize)
Computing a block offset from its index :
blockOffset = blockIndex*blockSize
-
-
Field Summary
Fields Modifier and Type Field Description protected static intAB_ALLOCSIZE_OFFSETprotected static intAB_FLAGS_OFFSETprotected static intAB_NEXTBLOCK_OFFSETprotected static intAB_PREVBLOCK_OFFSETprotected int[]allocatedSizestatic StringALLOCATION_TABLE_SUFFIXprotected FileallocationTableFileprotected RandomAccessFileallocationTableRandomAccessFilestatic intAT_BLOCK_SIZEstatic intAT_HEADER_BLOCKCOUNT_OFFSETprotected static intAT_HEADER_FIRSTBLOCK_OFFSETstatic intAT_HEADER_SIZEprotected intblockCountprotected intblockSizestatic StringDATA_FILE_SUFFIXprotected FiledataFileprotected RandomAccessFiledataRandomAccessFileprotected AbstractDestinationDescriptordescriptorprotected intfirstBlockprotected byte[]flagsprotected int[]nextBlockprotected int[]previousBlock-
Fields inherited from class net.timewalker.ffmq4.storage.data.impl.AbstractDataStore
locks, SAFE_MODE
-
-
Constructor Summary
Constructors Constructor Description AbstractBlockBasedDataStore(AbstractDestinationDescriptor descriptor)Constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcheckHandle(int handle)Check handle validityvoidclose()Close the store releasing associated system resourcesintdelete(int handle)Delete data associated to the given handle from the storeprotected abstract voidextendStoreFiles(int oldBlockCount, int newBlockCount)Extend the store files to newBlockCountintfirst()Get the first data handle storedprotected abstract voidflush()Flush internal buffersintgetAbsoluteStoreUsage()Get the absolute store usage amount (%) (Ratio of used space over maximum allocatable space)intgetBlockSize()intgetStoreUsage()Get the store usage amount (%) (Ratio of used space over currently allocated space)voidinit()Initialize the data storeprotected voidinitFilesystem()protected voidintegrityCheck()Run an integrity check on the store files and fix them as necessaryintnext(int handle)Get the next data handle after the given oneintprevious(int handle)Get the previous data handle after the given oneprotected abstract voidreadDataBlock(byte[] data, int offset, int len, int blockHandle)Read a data block to diskintreplace(int handle, Object obj)Replace data in the store at the given positionObjectretrieve(int handle)Retrieve the data associated to a given handlebyte[]retrieveHeader(int handle, int headerSize)protected byte[]serializeAllocationBlock(int blockIndex)Serialize allocation block at index blockIndexintsize()Get the number of entries in the storeintstore(Object obj, int previousHandle)Put some data under in the store after the previous handle dataStringtoString()protected abstract voidwriteAllocationBlock(int blockIndex)Write an allocation block to diskprotected abstract voidwriteDataBlock(byte[] data, int offset, int len, int blockHandle)Write a data block to diskprotected abstract voidwriteFirstBlock()Write the first block index to disk-
Methods inherited from class net.timewalker.ffmq4.storage.data.impl.AbstractDataStore
isLocked, lock, unlock
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.timewalker.ffmq4.storage.data.DataStore
commitChanges, commitChanges
-
-
-
-
Field Detail
-
DATA_FILE_SUFFIX
public static final String DATA_FILE_SUFFIX
- See Also:
- Constant Field Values
-
ALLOCATION_TABLE_SUFFIX
public static final String ALLOCATION_TABLE_SUFFIX
- See Also:
- Constant Field Values
-
AT_HEADER_SIZE
public static final int AT_HEADER_SIZE
- See Also:
- Constant Field Values
-
AT_BLOCK_SIZE
public static final int AT_BLOCK_SIZE
- See Also:
- Constant Field Values
-
AT_HEADER_BLOCKCOUNT_OFFSET
public static final int AT_HEADER_BLOCKCOUNT_OFFSET
- See Also:
- Constant Field Values
-
AT_HEADER_FIRSTBLOCK_OFFSET
protected static final int AT_HEADER_FIRSTBLOCK_OFFSET
- See Also:
- Constant Field Values
-
AB_FLAGS_OFFSET
protected static final int AB_FLAGS_OFFSET
- See Also:
- Constant Field Values
-
AB_ALLOCSIZE_OFFSET
protected static final int AB_ALLOCSIZE_OFFSET
- See Also:
- Constant Field Values
-
AB_PREVBLOCK_OFFSET
protected static final int AB_PREVBLOCK_OFFSET
- See Also:
- Constant Field Values
-
AB_NEXTBLOCK_OFFSET
protected static final int AB_NEXTBLOCK_OFFSET
- See Also:
- Constant Field Values
-
descriptor
protected AbstractDestinationDescriptor descriptor
-
blockSize
protected int blockSize
-
blockCount
protected int blockCount
-
flags
protected byte[] flags
-
allocatedSize
protected int[] allocatedSize
-
nextBlock
protected int[] nextBlock
-
previousBlock
protected int[] previousBlock
-
firstBlock
protected int firstBlock
-
allocationTableFile
protected File allocationTableFile
-
dataFile
protected File dataFile
-
allocationTableRandomAccessFile
protected RandomAccessFile allocationTableRandomAccessFile
-
dataRandomAccessFile
protected RandomAccessFile dataRandomAccessFile
-
-
Constructor Detail
-
AbstractBlockBasedDataStore
public AbstractBlockBasedDataStore(AbstractDestinationDescriptor descriptor)
Constructor
-
-
Method Detail
-
init
public final void init() throws DataStoreExceptionDescription copied from interface:LinkedDataStoreInitialize the data store- Throws:
DataStoreException
-
initFilesystem
protected void initFilesystem() throws DataStoreException- Throws:
DataStoreException
-
checkHandle
protected void checkHandle(int handle) throws DataStoreExceptionDescription copied from class:AbstractDataStoreCheck handle validity- Specified by:
checkHandlein classAbstractDataStore- Throws:
DataStoreException
-
first
public final int first() throws DataStoreExceptionDescription copied from interface:LinkedDataStoreGet the first data handle stored- Returns:
- the first entry handle or -1 if the store is empty
- Throws:
DataStoreException
-
next
public final int next(int handle) throws DataStoreExceptionDescription copied from interface:LinkedDataStoreGet the next data handle after the given one- Parameters:
handle- block handle- Returns:
- the next entry handle or -1 if their is no successor
- Throws:
DataStoreException
-
previous
public final int previous(int handle) throws DataStoreExceptionDescription copied from interface:LinkedDataStoreGet the previous data handle after the given one- Parameters:
handle- block handle- Returns:
- the previous entry handle or -1 if their is no predecessor
- Throws:
DataStoreException
-
retrieveHeader
public final byte[] retrieveHeader(int handle, int headerSize) throws DataStoreException- Throws:
DataStoreException
-
retrieve
public final Object retrieve(int handle) throws DataStoreException
Description copied from interface:LinkedDataStoreRetrieve the data associated to a given handle- Throws:
DataStoreException- on storage error or invalid handle
-
size
public final int size()
Description copied from interface:DataStoreGet the number of entries in the store
-
delete
public final int delete(int handle) throws DataStoreExceptionDescription copied from interface:LinkedDataStoreDelete data associated to the given handle from the store- Returns:
- the previous handle or -1
- Throws:
DataStoreException- on storage error or invalid handle
-
replace
public final int replace(int handle, Object obj) throws DataStoreExceptionDescription copied from interface:LinkedDataStoreReplace data in the store at the given position- Parameters:
handle- message handleobj- the message to store- Throws:
DataStoreException
-
store
public final int store(Object obj, int previousHandle) throws DataStoreException
Description copied from interface:LinkedDataStorePut some data under in the store after the previous handle datapreviousHandle- previous entry handle, use 0 if the store is empty- Throws:
DataStoreException
-
close
public void close()
Description copied from interface:DataStoreClose the store releasing associated system resources
-
integrityCheck
protected void integrityCheck() throws DataStoreExceptionRun an integrity check on the store files and fix them as necessary- Throws:
DataStoreException- if the files could not be fixed
-
getBlockSize
public final int getBlockSize()
-
writeFirstBlock
protected abstract void writeFirstBlock() throws DataStoreExceptionWrite the first block index to disk- Throws:
DataStoreException
-
writeAllocationBlock
protected abstract void writeAllocationBlock(int blockIndex) throws DataStoreExceptionWrite an allocation block to disk- Throws:
DataStoreException
-
writeDataBlock
protected abstract void writeDataBlock(byte[] data, int offset, int len, int blockHandle) throws DataStoreExceptionWrite a data block to disk- Throws:
DataStoreException
-
readDataBlock
protected abstract void readDataBlock(byte[] data, int offset, int len, int blockHandle) throws DataStoreExceptionRead a data block to disk- Throws:
DataStoreException
-
extendStoreFiles
protected abstract void extendStoreFiles(int oldBlockCount, int newBlockCount) throws DataStoreExceptionExtend the store files to newBlockCount- Throws:
DataStoreException
-
flush
protected abstract void flush() throws DataStoreExceptionFlush internal buffers- Throws:
DataStoreException
-
serializeAllocationBlock
protected final byte[] serializeAllocationBlock(int blockIndex)
Serialize allocation block at index blockIndex- Parameters:
blockIndex- the block index- Returns:
- the serialized allocation block
-
getStoreUsage
public final int getStoreUsage()
Description copied from interface:DataStoreGet the store usage amount (%) (Ratio of used space over currently allocated space)
-
getAbsoluteStoreUsage
public int getAbsoluteStoreUsage()
Description copied from interface:DataStoreGet the absolute store usage amount (%) (Ratio of used space over maximum allocatable space)
-
-