public abstract class AbstractBlobStore extends Object implements GarbageCollectableBlobStore, org.apache.jackrabbit.oak.commons.cache.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 |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clearCache, deleteChunks, getAllChunkIds
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()
GarbageCollectableBlobStore
getBlockSizeMin
in interface GarbageCollectableBlobStore
public void setBlockSize(int x)
GarbageCollectableBlobStore
setBlockSize
in interface GarbageCollectableBlobStore
x
- the block size in bytes.public int getBlockSize()
public String writeBlob(String tempFilePath) throws IOException
GarbageCollectableBlobStore
writeBlob
in interface GarbageCollectableBlobStore
tempFilePath
- the temporary file nameIOException
public String writeBlob(InputStream in) throws IOException
BlobStore
writeBlob
in interface BlobStore
in
- the input streamIOException
public InputStream getInputStream(String blobId) throws IOException
BlobStore
read
return the same sequence of bytes as long as neither call throws
an exception.getInputStream
in interface BlobStore
blobId
- the blob idIOException
public String getReference(String blobId)
BlobStore
null
if no such
reference is available.getReference
in interface BlobStore
blobId
- blobId referring the blob for which reference is requirednull
public String getBlobId(String reference)
BlobStore
null
if the reference is invalid, for example if it
points to a blob that does not exist.protected 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 storedIOException
public abstract void startMark() throws IOException
GarbageCollectableBlobStore
startMark
in interface GarbageCollectableBlobStore
IOException
public abstract int sweep() throws IOException
GarbageCollectableBlobStore
sweep
in interface GarbageCollectableBlobStore
IOException
protected 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 BlobStore
blobId
- the blob idpos
- the position within the blobbuff
- the target byte arrayoff
- the offset within the target arraylength
- the number of bytes to readIOException
public 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 idException
public long getBlobLength(String blobId) throws IOException
BlobStore
getBlobLength
in interface BlobStore
blobId
- the blob idIOException
protected void mark(String blobId) throws IOException
IOException
public Iterator<String> resolveChunks(String blobId) throws IOException
GarbageCollectableBlobStore
resolveChunks
in interface GarbageCollectableBlobStore
blobId
- the blob idIOException
- Signals that an I/O exception has occurred.Copyright © 2012-2017 The Apache Software Foundation. All Rights Reserved.