public abstract class AbstractBlobStore extends Object implements GarbageCollectableBlobStore, Cache.Backend<AbstractBlobStore.BlockId,AbstractBlobStore.Data>
Each data store id is a list of zero or more entries. Each entry is either
The format of a 'data' entry is: type (one byte; 0 for data), length (variable size int), data (bytes).
The format of a 'hash of content' entry is: type (one byte; 1 for hash), level (variable size int, 0 meaning not nested), size (variable size long), hash code length (variable size int), hash code.
The format of a 'hash of data store id' entry is: type (one byte; 1 for hash), level (variable size int, nesting level), total size (variable size long), size of data store id (variable size long), hash code length (variable size int), hash code.
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractBlobStore.BlockId
A block id.
|
static class |
AbstractBlobStore.Data
The data for a block.
|
| Modifier and Type | Field and Description |
|---|---|
protected static int |
BLOCK_SIZE_LIMIT |
protected static String |
HASH_ALGORITHM |
protected Map<String,WeakReference<String>> |
inUse |
protected static int |
TYPE_DATA |
protected static int |
TYPE_HASH |
protected static int |
TYPE_HASH_COMPRESSED |
| Constructor and Description |
|---|
AbstractBlobStore() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearCache()
Clear the cache.
|
void |
clearInUse()
Clear all objects marked as "transiently in use".
|
long |
getBlobLength(String blobId)
Get the length of the blob.
|
int |
getBlockSize() |
long |
getBlockSizeMin()
Get the minimum block size (if there is any).
|
protected abstract boolean |
isMarkEnabled() |
AbstractBlobStore.Data |
load(AbstractBlobStore.BlockId id)
Load the object.
|
protected abstract void |
mark(AbstractBlobStore.BlockId id) |
protected void |
mark(String blobId) |
protected void |
markInUse() |
int |
readBlob(String blobId,
long pos,
byte[] buff,
int off,
int length)
Read a number of bytes from a blob.
|
protected abstract byte[] |
readBlockFromBackend(AbstractBlobStore.BlockId id)
Load the block from the storage backend.
|
void |
setBlockSize(int x)
Set the block size used by this blob store, if the blob store splits
binaries into blocks.
|
void |
setBlockSizeMin(int x) |
abstract void |
startMark()
Start the mark phase.
|
protected abstract void |
storeBlock(byte[] digest,
int level,
byte[] data)
Store a block of data.
|
abstract int |
sweep()
Remove all unused blocks.
|
protected void |
usesBlobId(String blobId) |
String |
writeBlob(InputStream in)
Write a blob from an input stream.
|
String |
writeBlob(String tempFilePath)
Write a blob from a temporary file.
|
protected static final String HASH_ALGORITHM
protected static final int TYPE_DATA
protected static final int TYPE_HASH
protected static final int TYPE_HASH_COMPRESSED
protected static final int BLOCK_SIZE_LIMIT
protected Map<String,WeakReference<String>> inUse
public void setBlockSizeMin(int x)
public long getBlockSizeMin()
GarbageCollectableBlobStoregetBlockSizeMin in interface GarbageCollectableBlobStorepublic void setBlockSize(int x)
GarbageCollectableBlobStoresetBlockSize in interface GarbageCollectableBlobStorex - the block size in bytes.public int getBlockSize()
public String writeBlob(String tempFilePath) throws IOException
GarbageCollectableBlobStorewriteBlob in interface GarbageCollectableBlobStoreIOExceptionpublic String writeBlob(InputStream in) throws IOException
BlobStorewriteBlob in interface BlobStorein - the input streamIOExceptionprotected void usesBlobId(String blobId)
public void clearInUse()
GarbageCollectableBlobStoreclearInUse in interface GarbageCollectableBlobStorepublic void clearCache()
GarbageCollectableBlobStoreclearCache in interface GarbageCollectableBlobStoreprotected abstract void storeBlock(byte[] digest,
int level,
byte[] data)
throws IOException
digest - the content hashlevel - the indirection level (0 is for user data, 1 is a list of
digests that point to user data, 2 is a list of digests that
point to digests, and so on). This parameter is for
informational use only, and it is not required to store it
unless that's easy to achievedata - the data to be storedIOExceptionpublic abstract void startMark()
throws IOException
GarbageCollectableBlobStorestartMark in interface GarbageCollectableBlobStoreIOExceptionpublic abstract int sweep()
throws IOException
GarbageCollectableBlobStoresweep in interface GarbageCollectableBlobStoreIOExceptionprotected abstract boolean isMarkEnabled()
protected abstract void mark(AbstractBlobStore.BlockId id) throws Exception
Exceptionprotected void markInUse()
throws IOException
IOExceptionpublic int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws IOException
BlobStorereadBlob in interface BlobStoreblobId - the blob idpos - the position within the blobbuff - the target byte arrayoff - the offset within the target arraylength - the number of bytes to readIOExceptionpublic AbstractBlobStore.Data load(AbstractBlobStore.BlockId id)
Cache.Backendload in interface Cache.Backend<AbstractBlobStore.BlockId,AbstractBlobStore.Data>id - the keyprotected abstract byte[] readBlockFromBackend(AbstractBlobStore.BlockId id) throws Exception
id - the block idExceptionpublic long getBlobLength(String blobId) throws IOException
BlobStoregetBlobLength in interface BlobStoreblobId - the blob idIOExceptionprotected void mark(String blobId) throws IOException
IOExceptionCopyright © 2012-2014 The Apache Software Foundation. All Rights Reserved.