|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.processmining.framework.log.rfb.io.BlockDataStorage
public class BlockDataStorage
This class implements a storage container providing dynamically sized blocks of bytes. Initially, each block data storage contains one single block, which extends on the whole backing operating system file. With the allocation of further blocks, the current blocks are partitioned symmetrically, in a recursive manner. This means, on each partitioning level, each currently contained block is cut in half, yielding a new block each, extending over the prior block's second half. In this way, each partitioning doubles the number of blocks in the block data storage while cutting each block's size in half. We assume that files are allocated or written consecutively, i.e. one after another. If we further assume that files are written in large numbers of the same size of file, this block data storage scales perfectly, adjusting its partitioning dynamically to the size of required byte chunks. The block data storage can be tuned in its behavior with two parameters. One of it being the size of the block data storage, i.e. the number of bytes which is provided in a whole. The other parameter is the partitioning limit. If this limit, as a percentage of each block's inhibited space from the space it can maximally hold, is increased for at least one block in the storage, the storage can no longer be partitioned. This concept is geared towards the idea of a virtual file system, where file metaphors represent abstract sequential byte storages, which can extend over multiple storage blocks as provided by this class.
Field Summary | |
---|---|
protected java.util.ArrayList<StorageBlock> |
blocks
List of the currently provided storage blocks within this storage. |
protected int |
blockSize
Current size of blocks provided by this storage |
protected java.nio.MappedByteBuffer |
buffer
This buffer will hold the memory-mapped backing file |
protected java.io.File |
file
The operating system level file backing the storage |
protected java.util.ArrayList<StorageBlock> |
freeBlocks
List or provided storage blocks in this storage, which can still be allocated, i.e. |
protected int |
partitionLevel
The partition level in which this storage currently is in. |
protected double |
partitionThreshold
If at least one block in the provided set exceeds a usage percentage given in this threshold, no further partitioning must occur. |
protected int |
pointer
Current offset in the storage file, from which will be read or written the next time |
protected int |
size
Size of the storage file, in bytes. |
Constructor Summary | |
---|---|
BlockDataStorage(java.io.File aFile,
int fileSize)
Create a new block data storage, based on the given file with the given size. |
Method Summary | |
---|---|
StorageBlock |
allocateBlock()
Allocate a new block of bytes from this block data storage. |
void |
close()
|
boolean |
defragment()
Attempts to defragment the block data storage, i.e. |
void |
freeBlock(int index)
This method registers the given indexed block as free with the storage. |
int |
getBlockOffset(int blockIndex)
Returns the offset in bytes of the indexed block, measured from the beginning of the block-partitioned file. |
int |
getBlockSize()
Returns the current block size of the partitioned file. |
java.io.File |
getFile()
Returns the file which is backing this block data storage. |
BlockDataStorageInfo |
getInfo()
Returns information about the current usage of this block data storage's blocks |
int |
length()
|
protected boolean |
partition()
This method performs a partitioning of the current set of blocks. |
protected static int |
powerOfTwoFloor(int n)
Returns the largest integer that is a power of two and smaller than the given integer parameter, i.e. |
boolean |
readBoolean(int blockNumber,
int offset)
|
byte |
readByte(int blockNumber,
int offset)
|
char |
readChar(int blockNumber,
int offset)
|
double |
readDouble(int blockNumber,
int offset)
|
float |
readFloat(int blockNumber,
int offset)
|
void |
readFully(int blockNumber,
int offset,
byte[] b)
|
void |
readFully(int blockNumber,
int offset,
byte[] b,
int off,
int len)
|
int |
readInt(int blockNumber,
int offset)
|
long |
readLong(int blockNumber,
int offset)
|
short |
readShort(int blockNumber,
int offset)
|
int |
readUnsignedByte(int blockNumber,
int offset)
|
int |
readUnsignedShort(int blockNumber,
int offset)
|
protected int |
translateOffsetChecking(int blockIndex,
int blockOffset,
int bytes)
Internal method to translate block-private file pointer addresses, given as block index and block-private offset, into global, file-wide offsets. |
void |
write(int blockNumber,
int offset,
byte[] b)
|
void |
write(int blockNumber,
int offset,
byte[] b,
int off,
int len)
|
void |
write(int blockNumber,
int offset,
int b)
|
void |
writeBoolean(int blockNumber,
int offset,
boolean v)
|
void |
writeByte(int blockNumber,
int offset,
int v)
|
void |
writeBytes(int blockNumber,
int offset,
java.lang.String s)
|
void |
writeChar(int blockNumber,
int offset,
int v)
|
void |
writeChars(int blockNumber,
int offset,
java.lang.String s)
|
void |
writeDouble(int blockNumber,
int offset,
double v)
|
void |
writeFloat(int blockNumber,
int offset,
float v)
|
void |
writeInt(int blockNumber,
int offset,
int v)
|
void |
writeLong(int blockNumber,
int offset,
long v)
|
void |
writeShort(int blockNumber,
int offset,
int v)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.io.File file
protected java.nio.MappedByteBuffer buffer
protected int size
protected int pointer
protected int blockSize
protected int partitionLevel
protected double partitionThreshold
protected java.util.ArrayList<StorageBlock> blocks
protected java.util.ArrayList<StorageBlock> freeBlocks
Constructor Detail |
---|
public BlockDataStorage(java.io.File aFile, int fileSize) throws java.io.IOException
aFile
- File which is to back this block storage.fileSize
- Size of the block data storage in bytes.
java.io.IOException
Method Detail |
---|
protected static int powerOfTwoFloor(int n)
n
-
public StorageBlock allocateBlock()
null
.
public void freeBlock(int index)
index
- Index of the block to be freed from allocation.public java.io.File getFile()
protected boolean partition()
false
is returned.
If partitioning is successful, true
is returned, implying
adjustment of all prior contained blocks and creation of all respective
new blocks.
public boolean defragment()
public int getBlockOffset(int blockIndex)
blockIndex
- Index of the block, whose offset is requested.
protected int translateOffsetChecking(int blockIndex, int blockOffset, int bytes) throws java.io.IOException
blockIndex
- Index of the requesting block.blockOffset
- Offset within the requesting block.bytes
- Number of bytes to be read or written from the requested offset.
java.io.IOException
public int getBlockSize()
public BlockDataStorageInfo getInfo()
public void close() throws java.io.IOException
java.io.IOException
public int length() throws java.io.IOException
java.io.IOException
public void write(int blockNumber, int offset, int b) throws java.io.IOException
java.io.IOException
public void write(int blockNumber, int offset, byte[] b) throws java.io.IOException
java.io.IOException
public void write(int blockNumber, int offset, byte[] b, int off, int len) throws java.io.IOException
java.io.IOException
public void writeBoolean(int blockNumber, int offset, boolean v) throws java.io.IOException
java.io.IOException
public void writeByte(int blockNumber, int offset, int v) throws java.io.IOException
java.io.IOException
public void writeBytes(int blockNumber, int offset, java.lang.String s) throws java.io.IOException
java.io.IOException
public void writeChar(int blockNumber, int offset, int v) throws java.io.IOException
java.io.IOException
public void writeChars(int blockNumber, int offset, java.lang.String s) throws java.io.IOException
java.io.IOException
public void writeDouble(int blockNumber, int offset, double v) throws java.io.IOException
java.io.IOException
public void writeFloat(int blockNumber, int offset, float v) throws java.io.IOException
java.io.IOException
public void writeInt(int blockNumber, int offset, int v) throws java.io.IOException
java.io.IOException
public void writeLong(int blockNumber, int offset, long v) throws java.io.IOException
java.io.IOException
public void writeShort(int blockNumber, int offset, int v) throws java.io.IOException
java.io.IOException
public boolean readBoolean(int blockNumber, int offset) throws java.io.IOException
java.io.IOException
public byte readByte(int blockNumber, int offset) throws java.io.IOException
java.io.IOException
public char readChar(int blockNumber, int offset) throws java.io.IOException
java.io.IOException
public double readDouble(int blockNumber, int offset) throws java.io.IOException
java.io.IOException
public float readFloat(int blockNumber, int offset) throws java.io.IOException
java.io.IOException
public void readFully(int blockNumber, int offset, byte[] b) throws java.io.IOException
java.io.IOException
public void readFully(int blockNumber, int offset, byte[] b, int off, int len) throws java.io.IOException
java.io.IOException
public int readInt(int blockNumber, int offset) throws java.io.IOException
java.io.IOException
public long readLong(int blockNumber, int offset) throws java.io.IOException
java.io.IOException
public short readShort(int blockNumber, int offset) throws java.io.IOException
java.io.IOException
public int readUnsignedByte(int blockNumber, int offset) throws java.io.IOException
java.io.IOException
public int readUnsignedShort(int blockNumber, int offset) throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |