public abstract class AbstractBlobStore extends java.lang.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
The minimum block size.
|
protected static java.lang.String |
HASH_ALGORITHM |
protected java.util.Map<java.lang.String,java.lang.ref.WeakReference<java.lang.String>> |
inUse
The blob ids that are still floating around in memory.
|
protected static int |
TYPE_DATA |
protected static int |
TYPE_HASH |
| Constructor and Description |
|---|
AbstractBlobStore() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearInUse()
Clear all objects marked as "transiently in use".
|
void |
close() |
boolean |
deleteChunks(java.util.List<java.lang.String> chunkIds,
long maxLastModifiedTime)
Deletes the blobs with the given ids.
|
java.lang.String |
getBlobId(@NotNull java.lang.String reference)
Returns the blobId that referred by the given binary reference.
|
long |
getBlobLength(java.lang.String blobId)
Get the length of the blob.
|
int |
getBlockSize() |
long |
getBlockSizeMin()
Get the minimum block size (if there is any).
|
java.io.InputStream |
getInputStream(java.lang.String blobId)
Returns a new stream for given blobId.
|
protected byte[] |
getOrCreateReferenceKey()
Returns the reference key of this blob store.
|
java.lang.String |
getReference(@NotNull java.lang.String blobId)
Returns a secure reference to blob referred by blobid, or
null if no such
reference is available. |
protected BlobStatsCollector |
getStatsCollector() |
protected abstract boolean |
isMarkEnabled() |
AbstractBlobStore.Data |
load(AbstractBlobStore.BlockId id) |
protected abstract void |
mark(AbstractBlobStore.BlockId id) |
protected void |
mark(java.lang.String blobId) |
protected void |
markInUse() |
int |
readBlob(java.lang.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.
|
java.util.Iterator<java.lang.String> |
resolveChunks(java.lang.String blobId)
Resolve chunks stored in the blob store 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(java.lang.String encodedKey)
Set the referenceKey from Base64 encoded byte array
|
void |
setReferenceKeyPlainText(java.lang.String textKey)
Set the referenceKey from plain text.
|
void |
setStatsCollector(BlobStatsCollector stats) |
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(java.lang.String blobId) |
java.lang.String |
writeBlob(java.io.InputStream in)
Write a blob from an input stream.
|
java.lang.String |
writeBlob(java.io.InputStream in,
BlobOptions options)
Default implementation ignores options and delegates to the
writeBlob(InputStream)
method. |
java.lang.String |
writeBlob(java.lang.String tempFilePath)
Write a blob from a temporary file.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclearCache, countDeleteChunks, getAllChunkIdsprotected static final java.lang.String HASH_ALGORITHM
protected static final int TYPE_DATA
protected static final int TYPE_HASH
protected static final int BLOCK_SIZE_LIMIT
protected java.util.Map<java.lang.String,java.lang.ref.WeakReference<java.lang.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 void setStatsCollector(BlobStatsCollector stats)
protected BlobStatsCollector getStatsCollector()
public int getBlockSize()
public java.lang.String writeBlob(java.lang.String tempFilePath)
throws java.io.IOException
GarbageCollectableBlobStorewriteBlob in interface GarbageCollectableBlobStoretempFilePath - the temporary file namejava.io.IOExceptionpublic java.lang.String writeBlob(java.io.InputStream in)
throws java.io.IOException
BlobStorepublic java.lang.String writeBlob(java.io.InputStream in,
BlobOptions options)
throws java.io.IOException
writeBlob(InputStream)
method.public java.io.InputStream getInputStream(java.lang.String blobId)
throws java.io.IOException
BlobStoreread
return the same sequence of bytes as long as neither call throws
an exception.getInputStream in interface BlobStoreblobId - the blob idjava.io.IOExceptionpublic java.lang.String getReference(@NotNull
@NotNull java.lang.String blobId)
BlobStorenull if no such
reference is available.getReference in interface BlobStoreblobId - blobId referring the blob for which reference is requirednullpublic java.lang.String getBlobId(@NotNull
@NotNull java.lang.String reference)
BlobStorenull 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(java.lang.String encodedKey)
encodedKey - base64 encoded keypublic void setReferenceKeyPlainText(java.lang.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(java.lang.String blobId)
public void clearInUse()
GarbageCollectableBlobStoreclearInUse in interface GarbageCollectableBlobStoreprotected abstract void storeBlock(byte[] digest,
int level,
byte[] data)
throws java.io.IOException
digest - the content hash (32 bytes)level - 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 (the number of bytes is at most the block size)java.io.IOExceptionpublic abstract void startMark()
throws java.io.IOException
GarbageCollectableBlobStorestartMark in interface GarbageCollectableBlobStorejava.io.IOExceptionpublic abstract int sweep()
throws java.io.IOException
GarbageCollectableBlobStoresweep in interface GarbageCollectableBlobStorejava.io.IOExceptionprotected abstract boolean isMarkEnabled()
protected abstract void mark(AbstractBlobStore.BlockId id) throws java.lang.Exception
java.lang.Exceptionprotected void markInUse()
throws java.io.IOException
java.io.IOExceptionpublic int readBlob(java.lang.String blobId,
long pos,
byte[] buff,
int off,
int length)
throws java.io.IOException
BlobStorepublic 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 java.lang.Exception
id - the block idjava.lang.Exceptionpublic long getBlobLength(java.lang.String blobId)
throws java.io.IOException
BlobStoregetBlobLength in interface BlobStoreblobId - the blob idjava.io.IOExceptionprotected void mark(java.lang.String blobId)
throws java.io.IOException
java.io.IOExceptionpublic java.util.Iterator<java.lang.String> resolveChunks(java.lang.String blobId)
throws java.io.IOException
GarbageCollectableBlobStoreresolveChunks in interface GarbageCollectableBlobStoreblobId - the blob idjava.io.IOException - Signals that an I/O exception has occurred.public boolean deleteChunks(java.util.List<java.lang.String> chunkIds,
long maxLastModifiedTime)
throws java.lang.Exception
GarbageCollectableBlobStoredeleteChunks in interface GarbageCollectableBlobStorechunkIds - the chunk idsmaxLastModifiedTime - the max last modified time to consider for retrieval,
with the special value '0' meaning no filtering by timejava.lang.Exception - the exceptionpublic void close()
throws java.lang.Exception
close in interface java.lang.AutoCloseablejava.lang.ExceptionCopyright © 2012–2022 The Apache Software Foundation. All rights reserved.