|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.jackrabbit.oak.spi.blob.AbstractBlobStore
public abstract class AbstractBlobStore
An abstract data store that splits the binaries in relatively small blocks, so that each block fits in memory.
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.
| Nested Class Summary | |
|---|---|
static class |
AbstractBlobStore.BlockId
A block id. |
static class |
AbstractBlobStore.Data
The data for a block. |
| Field Summary | |
|---|---|
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 Summary | |
|---|---|
AbstractBlobStore()
|
|
| Method Summary | |
|---|---|
void |
clearInUse()
Clear all objects marked as "transiently in use". |
String |
getBlobId(String reference)
Returns the blobId that referred by the given binary reference. |
long |
getBlobLength(String blobId)
Get the length of the blob. |
int |
getBlockSize()
|
long |
getBlockSizeMin()
Get the minimum block size (if there is any). |
InputStream |
getInputStream(String blobId)
Returns a new stream for given blobId. |
protected byte[] |
getOrCreateReferenceKey()
Returns the reference key of this blob store. |
String |
getReference(String blobId)
Returns a secure reference to blob referred by blobid, or null if no such
reference is available. |
protected abstract boolean |
isMarkEnabled()
|
AbstractBlobStore.Data |
load(AbstractBlobStore.BlockId id)
|
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. |
Iterator<String> |
resolveChunks(String blobId)
Resolve chunks from the given Id. |
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)
|
void |
setReferenceKey(byte[] referenceKey)
|
void |
setReferenceKeyEncoded(String encodedKey)
Set the referenceKey from Base64 encoded byte array |
void |
setReferenceKeyPlainText(String textKey)
Set the referenceKey from plain text. |
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore |
|---|
clearCache, deleteChunks, getAllChunkIds |
| Field Detail |
|---|
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
| Constructor Detail |
|---|
public AbstractBlobStore()
| Method Detail |
|---|
public void setBlockSizeMin(int x)
public long getBlockSizeMin()
GarbageCollectableBlobStore
getBlockSizeMin in interface GarbageCollectableBlobStorepublic void setBlockSize(int x)
GarbageCollectableBlobStore
setBlockSize in interface GarbageCollectableBlobStorex - the block size in bytes.public int getBlockSize()
public String writeBlob(String tempFilePath)
throws IOException
GarbageCollectableBlobStore
writeBlob in interface GarbageCollectableBlobStoretempFilePath - the temporary file name
IOException
public String writeBlob(InputStream in)
throws IOException
BlobStore
writeBlob in interface BlobStorein - the input stream
IOException
public InputStream getInputStream(String blobId)
throws IOException
BlobStoreread
return the same sequence of bytes as long as neither call throws
an exception.
getInputStream in interface BlobStoreblobId - the blob id
IOExceptionpublic String getReference(String blobId)
BlobStorenull if no such
reference is available.
getReference in interface BlobStoreblobId - blobId referring the blob for which reference is required
nullpublic String getBlobId(String reference)
BlobStorenull if the reference is invalid, for example if it
points to a blob that does not exist.
getBlobId in interface BlobStorereference - binary reference
nullprotected byte[] getOrCreateReferenceKey()
This method is called only once during the lifetime of a data store instance and the return value is cached in memory, so it's no problem if the implementation is slow.
public void setReferenceKey(byte[] referenceKey)
public void setReferenceKeyEncoded(String encodedKey)
encodedKey - base64 encoded keypublic void setReferenceKeyPlainText(String textKey)
This is useful when setting key via generic
bean property manipulation from string properties. User can specify the
key in plain text and that would be passed on this object via
PropertiesUtil.populate(Object, java.util.Map, boolean)
textKey - base64 encoded keyPropertiesUtil.populate(Object, java.util.Map, boolean)protected void usesBlobId(String blobId)
public void clearInUse()
GarbageCollectableBlobStore
clearInUse in interface GarbageCollectableBlobStore
protected 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 stored
IOException
public abstract void startMark()
throws IOException
GarbageCollectableBlobStore
startMark in interface GarbageCollectableBlobStoreIOException
public abstract int sweep()
throws IOException
GarbageCollectableBlobStore
sweep in interface GarbageCollectableBlobStoreIOExceptionprotected abstract boolean isMarkEnabled()
protected abstract void mark(AbstractBlobStore.BlockId id)
throws Exception
Exception
protected void markInUse()
throws IOException
IOException
public int readBlob(String blobId,
long pos,
byte[] buff,
int off,
int length)
throws IOException
BlobStore
readBlob 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 read
IOExceptionpublic AbstractBlobStore.Data load(AbstractBlobStore.BlockId id)
load in interface org.apache.jackrabbit.oak.commons.cache.Cache.Backend<AbstractBlobStore.BlockId,AbstractBlobStore.Data>
protected abstract byte[] readBlockFromBackend(AbstractBlobStore.BlockId id)
throws Exception
id - the block id
Exception
public long getBlobLength(String blobId)
throws IOException
BlobStore
getBlobLength in interface BlobStoreblobId - the blob id
IOException
protected void mark(String blobId)
throws IOException
IOException
public Iterator<String> resolveChunks(String blobId)
throws IOException
GarbageCollectableBlobStore
resolveChunks in interface GarbageCollectableBlobStoreblobId - the blob id
IOException - Signals that an I/O exception has occurred.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||