|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tranche.commons.Debuggable
org.tranche.flatfile.DataBlock
public class DataBlock
Represents a block of data. Might have more than one file in it.
Note that the following critical activities are synchronized on the DataBlock object:
| Field Summary | |
|---|---|
static BigHash |
HASH_LENGTH_ZERO
|
static int |
HEADERS_PER_FILE
The amount of headers per file. |
static int |
MAX_BLOCK_SIZE
The maximum DataBlock size, in bytes. |
| Constructor Summary | |
|---|---|
DataBlock(java.lang.String filename,
DataDirectoryConfiguration ddc,
DataBlockUtil dbu)
|
|
| Method Summary | |
|---|---|
void |
addBytes(BigHash hash,
boolean isMetaData,
byte[] bytes)
Add a chunk to this DataBlock. |
void |
addBytes(BigHash hash,
boolean isMetaData,
byte[] bytes,
int recursionCount)
Add a chunk to this DataBlock. |
int |
compareTo(java.lang.Object o)
Compare underlying files for DataBlock instances. |
void |
deleteBytes(BigHash hash,
boolean isMetaData)
Delete the bytes (chunk) from this DataBlock based on hash. |
java.lang.String |
getAbsolutePath()
Get absolute path to underlying file for DataBlock. |
byte[] |
getBytes(BigHash hash,
boolean isMetaData)
Returns the bytes (chunk) representing by the hash, or throws a FileNotFoundException if not found. |
byte[] |
getBytes(int o,
int s)
Uses cached information to get chunk. |
java.util.List<BigHash> |
getHashes(boolean isMetaData)
Returns the list of either data or meta-data hashes stored in this block. |
protected DataBlock[] |
getSubBlocks()
Return the subblocks for this DataBlock. |
boolean |
hasBytes(BigHash hash,
boolean isMetaData)
Check whether the bytes (chunk) represented by the hash exist in this DataBlock instance. |
boolean |
isDirectory()
Returns true if this DataBlock is a directory. |
boolean |
isMerging()
Returns true if this file is half-way through a merge. |
long |
length()
Return the size in bytes of the underlying file for the DataBlock instance. |
protected boolean |
moveToDataDirectoryConfiguration(DataDirectoryConfiguration newDDC)
The data block moves itself. |
| Methods inherited from class org.tranche.commons.Debuggable |
|---|
debugErr, debugErr, debugOut, isDebug, setDebug |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static BigHash HASH_LENGTH_ZERO
public static final int MAX_BLOCK_SIZE
The maximum DataBlock size, in bytes.
public static final int HEADERS_PER_FILE
The amount of headers per file.
Each header's size in bytes is equal to BigHash.HASH_LENGTH + 1 + 1 + 4 + 4. Every new block will start with this many headers. To get the blocks size, you must also include all the data in the block.
| Constructor Detail |
|---|
public DataBlock(java.lang.String filename,
DataDirectoryConfiguration ddc,
DataBlockUtil dbu)
filename - ddc - dbu - | Method Detail |
|---|
public final boolean isDirectory()
Returns true if this DataBlock is a directory. (I.e., it has children DataBlock instances.)
public final java.lang.String getAbsolutePath()
Get absolute path to underlying file for DataBlock. No guarentee if regular file or directory.
public final boolean isMerging()
Returns true if this file is half-way through a merge.
public final long length()
Return the size in bytes of the underlying file for the DataBlock instance.
public final java.util.List<BigHash> getHashes(boolean isMetaData)
throws java.lang.Exception
Returns the list of either data or meta-data hashes stored in this block. If true is passed as a parameter, only meta-data is returned. Otherwise only data hashes are returned.
isMetaData -
java.lang.Exception
public final byte[] getBytes(int o,
int s)
throws java.lang.Exception
Uses cached information to get chunk.
o - Offset of chunks - Size of chunk
java.lang.Exception
public final byte[] getBytes(BigHash hash,
boolean isMetaData)
throws java.lang.Exception
Returns the bytes (chunk) representing by the hash, or throws a FileNotFoundException if not found.
hash - isMetaData -
java.lang.Exception
public final boolean hasBytes(BigHash hash,
boolean isMetaData)
throws java.lang.Exception
Check whether the bytes (chunk) represented by the hash exist in this DataBlock instance.
hash - isMetaData -
java.lang.Exception
public final void addBytes(BigHash hash,
boolean isMetaData,
byte[] bytes)
throws java.lang.Exception
Add a chunk to this DataBlock.
hash - isMetaData - bytes -
java.lang.Exception
public final void addBytes(BigHash hash,
boolean isMetaData,
byte[] bytes,
int recursionCount)
throws java.lang.Exception
Add a chunk to this DataBlock.
hash - isMetaData - bytes - recursionCount - The number of times this has been recursively called while waiting for DataBlock to merge. (After a certain number of times, this will fail and throw an exception.)
java.lang.Exception
public final void deleteBytes(BigHash hash,
boolean isMetaData)
throws java.lang.Exception
Delete the bytes (chunk) from this DataBlock based on hash.
hash - isMetaData -
java.lang.Exceptionpublic final int compareTo(java.lang.Object o)
Compare underlying files for DataBlock instances.
compareTo in interface java.lang.Comparableo -
protected final DataBlock[] getSubBlocks()
Return the subblocks for this DataBlock.
protected final boolean moveToDataDirectoryConfiguration(DataDirectoryConfiguration newDDC)
throws java.lang.Exception
The data block moves itself. This synchronized method places the data block in a new DataDirectoryConfiguration.
The intended use for this method is to balance a server's data across data directories.
newDDC -
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||