public abstract class AbstractBlockBasedDataStore extends AbstractDataStore
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 block
Disk layout of the data store :
blocks (*blockCount blocks of size blockSize)
Computing a block offset from its index :
blockOffset = blockIndex*blockSize
| Modifier and Type | Field and Description |
|---|---|
protected static int |
AB_ALLOCSIZE_OFFSET |
protected static int |
AB_FLAGS_OFFSET |
protected static int |
AB_NEXTBLOCK_OFFSET |
protected static int |
AB_PREVBLOCK_OFFSET |
protected int[] |
allocatedSize |
static String |
ALLOCATION_TABLE_SUFFIX |
protected File |
allocationTableFile |
protected RandomAccessFile |
allocationTableRandomAccessFile |
static int |
AT_BLOCK_SIZE |
static int |
AT_HEADER_BLOCKCOUNT_OFFSET |
protected static int |
AT_HEADER_FIRSTBLOCK_OFFSET |
static int |
AT_HEADER_SIZE |
protected int |
blockCount |
protected int |
blockSize |
static String |
DATA_FILE_SUFFIX |
protected File |
dataFile |
protected RandomAccessFile |
dataRandomAccessFile |
protected AbstractDestinationDescriptor |
descriptor |
protected int |
firstBlock |
protected byte[] |
flags |
protected int[] |
nextBlock |
protected int[] |
previousBlock |
locks, SAFE_MODE| Constructor and Description |
|---|
AbstractBlockBasedDataStore(AbstractDestinationDescriptor descriptor)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkHandle(int handle)
Check handle validity
|
void |
close()
Close the store releasing associated system resources
|
int |
delete(int handle)
Delete data associated to the given handle from the store
|
protected abstract void |
extendStoreFiles(int oldBlockCount,
int newBlockCount)
Extend the store files to newBlockCount
|
int |
first()
Get the first data handle stored
|
protected abstract void |
flush()
Flush internal buffers
|
int |
getAbsoluteStoreUsage()
Get the absolute store usage amount (%)
(Ratio of used space over maximum allocatable space)
|
int |
getBlockSize() |
int |
getStoreUsage()
Get the store usage amount (%)
(Ratio of used space over currently allocated space)
|
void |
init()
Initialize the data store
|
protected void |
initFilesystem() |
protected void |
integrityCheck()
Run an integrity check on the store files and fix them as necessary
|
int |
next(int handle)
Get the next data handle after the given one
|
int |
previous(int handle)
Get the previous data handle after the given one
|
protected abstract void |
readDataBlock(byte[] data,
int offset,
int len,
int blockHandle)
Read a data block to disk
|
int |
replace(int handle,
Object obj)
Replace data in the store at the given position
|
Object |
retrieve(int handle)
Retrieve the data associated to a given handle
|
byte[] |
retrieveHeader(int handle,
int headerSize) |
protected byte[] |
serializeAllocationBlock(int blockIndex)
Serialize allocation block at index blockIndex
|
int |
size()
Get the number of entries in the store
|
int |
store(Object obj,
int previousHandle)
Put some data under in the store after the previous handle data
|
String |
toString() |
protected abstract void |
writeAllocationBlock(int blockIndex)
Write an allocation block to disk
|
protected abstract void |
writeDataBlock(byte[] data,
int offset,
int len,
int blockHandle)
Write a data block to disk
|
protected abstract void |
writeFirstBlock()
Write the first block index to disk
|
isLocked, lock, unlockclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcommitChanges, commitChangespublic static final String DATA_FILE_SUFFIX
public static final String ALLOCATION_TABLE_SUFFIX
public static final int AT_HEADER_SIZE
public static final int AT_BLOCK_SIZE
public static final int AT_HEADER_BLOCKCOUNT_OFFSET
protected static final int AT_HEADER_FIRSTBLOCK_OFFSET
protected static final int AB_FLAGS_OFFSET
protected static final int AB_ALLOCSIZE_OFFSET
protected static final int AB_PREVBLOCK_OFFSET
protected static final int AB_NEXTBLOCK_OFFSET
protected AbstractDestinationDescriptor descriptor
protected int blockSize
protected int blockCount
protected byte[] flags
protected int[] allocatedSize
protected int[] nextBlock
protected int[] previousBlock
protected int firstBlock
protected File allocationTableFile
protected File dataFile
protected RandomAccessFile allocationTableRandomAccessFile
protected RandomAccessFile dataRandomAccessFile
public AbstractBlockBasedDataStore(AbstractDestinationDescriptor descriptor)
public final void init()
throws DataStoreException
LinkedDataStoreDataStoreExceptionprotected void initFilesystem()
throws DataStoreException
DataStoreExceptionprotected void checkHandle(int handle)
throws DataStoreException
AbstractDataStorecheckHandle in class AbstractDataStoreDataStoreExceptionpublic final int first()
throws DataStoreException
LinkedDataStoreDataStoreExceptionpublic final int next(int handle)
throws DataStoreException
LinkedDataStorehandle - block handleDataStoreExceptionpublic final int previous(int handle)
throws DataStoreException
LinkedDataStorehandle - block handleDataStoreExceptionpublic final byte[] retrieveHeader(int handle,
int headerSize)
throws DataStoreException
DataStoreExceptionpublic final Object retrieve(int handle) throws DataStoreException
LinkedDataStoreDataStoreException - on storage error or invalid handlepublic final int size()
DataStorepublic final int delete(int handle)
throws DataStoreException
LinkedDataStoreDataStoreException - on storage error or invalid handlepublic final int replace(int handle,
Object obj)
throws DataStoreException
LinkedDataStorehandle - message handleobj - the message to storeDataStoreExceptionpublic final int store(Object obj, int previousHandle) throws DataStoreException
LinkedDataStorepreviousHandle - previous entry handle, use 0 if the store is emptyDataStoreExceptionpublic void close()
DataStoreprotected void integrityCheck()
throws DataStoreException
DataStoreException - if the files could not be fixedpublic final int getBlockSize()
protected abstract void writeFirstBlock()
throws DataStoreException
DataStoreExceptionprotected abstract void writeAllocationBlock(int blockIndex)
throws DataStoreException
DataStoreExceptionprotected abstract void writeDataBlock(byte[] data,
int offset,
int len,
int blockHandle)
throws DataStoreException
DataStoreExceptionprotected abstract void readDataBlock(byte[] data,
int offset,
int len,
int blockHandle)
throws DataStoreException
DataStoreExceptionprotected abstract void extendStoreFiles(int oldBlockCount,
int newBlockCount)
throws DataStoreException
DataStoreExceptionprotected abstract void flush()
throws DataStoreException
DataStoreExceptionprotected final byte[] serializeAllocationBlock(int blockIndex)
blockIndex - the block indexpublic final int getStoreUsage()
DataStorepublic int getAbsoluteStoreUsage()
DataStoreCopyright © 2019. All rights reserved.