Class AbstractBlobStore
- java.lang.Object
 - 
- org.apache.jackrabbit.oak.spi.blob.AbstractBlobStore
 
 
- 
- All Implemented Interfaces:
 java.lang.AutoCloseable,Cache.Backend<AbstractBlobStore.BlockId,AbstractBlobStore.Data>,BlobStore,GarbageCollectableBlobStore
- Direct Known Subclasses:
 CachingBlobStore,FileBlobStore,MemoryBlobStore
public abstract class AbstractBlobStore extends java.lang.Object implements GarbageCollectableBlobStore, Cache.Backend<AbstractBlobStore.BlockId,AbstractBlobStore.Data>
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
- data (a number of bytes), or
 - the hash code of the content of a number of bytes, or
 - the hash code of the content of a data store id (indirect hash)
 
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
Nested Classes Modifier and Type Class Description static classAbstractBlobStore.BlockIdA block id.static classAbstractBlobStore.DataThe data for a block. 
- 
Constructor Summary
Constructors Constructor Description AbstractBlobStore() 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclearInUse()Clear all objects marked as "transiently in use".voidclose()booleandeleteChunks(java.util.List<java.lang.String> chunkIds, long maxLastModifiedTime)Deletes the blobs with the given ids.java.lang.StringgetBlobId(@NotNull java.lang.String reference)Returns the blobId that referred by the given binary reference.longgetBlobLength(java.lang.String blobId)Get the length of the blob.intgetBlockSize()longgetBlockSizeMin()Get the minimum block size (if there is any).java.io.InputStreamgetInputStream(java.lang.String blobId)Returns a new stream for given blobId.java.lang.StringgetReference(@NotNull java.lang.String blobId)Returns a secure reference to blob referred by blobid, ornullif no such reference is available.AbstractBlobStore.Dataload(AbstractBlobStore.BlockId id)Load the object.intreadBlob(java.lang.String blobId, long pos, byte[] buff, int off, int length)Read a number of bytes from a blob.java.util.Iterator<java.lang.String>resolveChunks(java.lang.String blobId)Resolve chunks stored in the blob store from the given Id.voidsetBlockSize(int x)Set the block size used by this blob store, if the blob store splits binaries into blocks.voidsetBlockSizeMin(int x)voidsetReferenceKey(byte[] referenceKey)voidsetReferenceKeyEncoded(java.lang.String encodedKey)Set the referenceKey from Base64 encoded byte arrayvoidsetReferenceKeyPlainText(java.lang.String textKey)Set the referenceKey from plain text.voidsetStatsCollector(BlobStatsCollector stats)abstract voidstartMark()Start the mark phase.abstract intsweep()Remove all unused blocks.java.lang.StringwriteBlob(java.io.InputStream in)Write a blob from an input stream.java.lang.StringwriteBlob(java.io.InputStream in, BlobOptions options)Default implementation ignores options and delegates to thewriteBlob(InputStream)method.java.lang.StringwriteBlob(java.lang.String tempFilePath)Write a blob from a temporary file.- 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
- 
Methods inherited from interface org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
clearCache, countDeleteChunks, getAllChunkIds 
 - 
 
 - 
 
- 
- 
Method Detail
- 
setBlockSizeMin
public void setBlockSizeMin(int x)
 
- 
getBlockSizeMin
public long getBlockSizeMin()
Description copied from interface:GarbageCollectableBlobStoreGet the minimum block size (if there is any).- Specified by:
 getBlockSizeMinin interfaceGarbageCollectableBlobStore- Returns:
 - the block size
 
 
- 
setBlockSize
public void setBlockSize(int x)
Description copied from interface:GarbageCollectableBlobStoreSet the block size used by this blob store, if the blob store splits binaries into blocks. If not, this setting is ignored.- Specified by:
 setBlockSizein interfaceGarbageCollectableBlobStore- Parameters:
 x- the block size in bytes.
 
- 
setStatsCollector
public void setStatsCollector(BlobStatsCollector stats)
 
- 
getBlockSize
public int getBlockSize()
 
- 
writeBlob
public java.lang.String writeBlob(java.lang.String tempFilePath) throws java.io.IOExceptionDescription copied from interface:GarbageCollectableBlobStoreWrite a blob from a temporary file. The temporary file is removed afterwards. A file based blob stores might simply rename the file, so that no additional writes are necessary.- Specified by:
 writeBlobin interfaceGarbageCollectableBlobStore- Parameters:
 tempFilePath- the temporary file name- Returns:
 - the blob id
 - Throws:
 java.io.IOException
 
- 
writeBlob
public java.lang.String writeBlob(java.io.InputStream in) throws java.io.IOExceptionDescription copied from interface:BlobStoreWrite a blob from an input stream. This method closes the input stream. 
- 
writeBlob
public java.lang.String writeBlob(java.io.InputStream in, BlobOptions options) throws java.io.IOExceptionDefault implementation ignores options and delegates to thewriteBlob(InputStream)method. 
- 
getInputStream
public java.io.InputStream getInputStream(java.lang.String blobId) throws java.io.IOExceptionDescription copied from interface:BlobStoreReturns a new stream for given blobId. The streams returned from multiple calls to this method are byte wise equals. That is, subsequent calls toreadreturn the same sequence of bytes as long as neither call throws an exception.- Specified by:
 getInputStreamin interfaceBlobStore- Parameters:
 blobId- the blob id- Returns:
 - a new stream for given blobId
 - Throws:
 java.io.IOException
 
- 
getReference
public java.lang.String getReference(@NotNull @NotNull java.lang.String blobId)Description copied from interface:BlobStoreReturns a secure reference to blob referred by blobid, ornullif no such reference is available.- Specified by:
 getReferencein interfaceBlobStore- Parameters:
 blobId- blobId referring the blob for which reference is required- Returns:
 - binary reference, or 
null 
 
- 
getBlobId
public java.lang.String getBlobId(@NotNull @NotNull java.lang.String reference)Description copied from interface:BlobStoreReturns the blobId that referred by the given binary reference. Returnsnullif the reference is invalid, for example if it points to a blob that does not exist. 
- 
setReferenceKey
public void setReferenceKey(byte[] referenceKey)
 
- 
setReferenceKeyEncoded
public void setReferenceKeyEncoded(java.lang.String encodedKey)
Set the referenceKey from Base64 encoded byte array- Parameters:
 encodedKey- base64 encoded key
 
- 
setReferenceKeyPlainText
public void setReferenceKeyPlainText(java.lang.String textKey)
Set the referenceKey from plain text. Key content would be UTF-8 encoding of the string.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)- Parameters:
 textKey- base64 encoded key- See Also:
 PropertiesUtil.populate(Object, java.util.Map, boolean)
 
- 
clearInUse
public void clearInUse()
Description copied from interface:GarbageCollectableBlobStoreClear all objects marked as "transiently in use".- Specified by:
 clearInUsein interfaceGarbageCollectableBlobStore
 
- 
startMark
public abstract void startMark() throws java.io.IOExceptionDescription copied from interface:GarbageCollectableBlobStoreStart the mark phase.- Specified by:
 startMarkin interfaceGarbageCollectableBlobStore- Throws:
 java.io.IOException
 
- 
sweep
public abstract int sweep() throws java.io.IOExceptionDescription copied from interface:GarbageCollectableBlobStoreRemove all unused blocks.- Specified by:
 sweepin interfaceGarbageCollectableBlobStore- Returns:
 - the number of removed blocks
 - Throws:
 java.io.IOException
 
- 
readBlob
public int readBlob(java.lang.String blobId, long pos, byte[] buff, int off, int length) throws java.io.IOExceptionDescription copied from interface:BlobStoreRead a number of bytes from a blob. 
- 
load
public AbstractBlobStore.Data load(AbstractBlobStore.BlockId id)
Description copied from interface:Cache.BackendLoad the object. The method does not need to be synchronized (it is synchronized in the cache)- Specified by:
 loadin interfaceCache.Backend<AbstractBlobStore.BlockId,AbstractBlobStore.Data>- Parameters:
 id- the key- Returns:
 - the value
 
 
- 
getBlobLength
public long getBlobLength(java.lang.String blobId) throws java.io.IOExceptionDescription copied from interface:BlobStoreGet the length of the blob.- Specified by:
 getBlobLengthin interfaceBlobStore- Parameters:
 blobId- the blob id- Returns:
 - the length
 - Throws:
 java.io.IOException
 
- 
resolveChunks
public java.util.Iterator<java.lang.String> resolveChunks(java.lang.String blobId) throws java.io.IOExceptionDescription copied from interface:GarbageCollectableBlobStoreResolve chunks stored in the blob store from the given Id. This will not return any chunks stored in-line in the id.- Specified by:
 resolveChunksin interfaceGarbageCollectableBlobStore- Parameters:
 blobId- the blob id- Returns:
 - the iterator
 - Throws:
 java.io.IOException- Signals that an I/O exception has occurred.
 
- 
deleteChunks
public boolean deleteChunks(java.util.List<java.lang.String> chunkIds, long maxLastModifiedTime) throws java.lang.ExceptionDescription copied from interface:GarbageCollectableBlobStoreDeletes the blobs with the given ids.- Specified by:
 deleteChunksin interfaceGarbageCollectableBlobStore- Parameters:
 chunkIds- the chunk idsmaxLastModifiedTime- the max last modified time to consider for retrieval, with the special value '0' meaning no filtering by time- Returns:
 - true, if successful
 - Throws:
 java.lang.Exception- the exception
 
- 
close
public void close() throws java.lang.Exception- Specified by:
 closein interfacejava.lang.AutoCloseable- Throws:
 java.lang.Exception
 
 - 
 
 -