org.apache.jackrabbit.mk.blobs
Class AbstractBlobStore

java.lang.Object
  extended by org.apache.jackrabbit.mk.blobs.AbstractBlobStore
All Implemented Interfaces:
Closeable, BlobStore, Cache.Backend<AbstractBlobStore.BlockId,AbstractBlobStore.Data>
Direct Known Subclasses:
DbBlobStore, FileBlobStore, MemoryBlobStore, MongoBlobStore

public abstract class AbstractBlobStore
extends Object
implements Closeable, BlobStore, 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

Thanks to the indirection, blocks can be kept relatively small, so that caching is simpler, and so that the storage backend doesn't need to support arbitrary size blobs (some storage backends buffer blobs in memory) and fast seeks (some storage backends re-read the whole blob when seeking).

The 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 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
 String addBlob(String tempFilePath)
          Write a blob from a temporary file.
 void clearCache()
           
 void clearInUse()
           
 void close()
           
 long getBlobLength(String blobId)
           
 int getBlockSize()
           
 long getBlockSizeMin()
           
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)
           
protected abstract  byte[] readBlockFromBackend(AbstractBlobStore.BlockId id)
           
 void setBlockSize(int x)
           
 void setBlockSizeMin(int x)
           
abstract  void startMark()
           
protected abstract  void storeBlock(byte[] digest, int level, byte[] data)
           
abstract  int sweep()
           
protected  void usesBlobId(String blobId)
           
 String writeBlob(InputStream in)
          Write a blob from an input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HASH_ALGORITHM

protected static final String HASH_ALGORITHM
See Also:
Constant Field Values

TYPE_DATA

protected static final int TYPE_DATA
See Also:
Constant Field Values

TYPE_HASH

protected static final int TYPE_HASH
See Also:
Constant Field Values

TYPE_HASH_COMPRESSED

protected static final int TYPE_HASH_COMPRESSED
See Also:
Constant Field Values

inUse

protected Map<String,WeakReference<String>> inUse
Constructor Detail

AbstractBlobStore

public AbstractBlobStore()
Method Detail

setBlockSizeMin

public void setBlockSizeMin(int x)

getBlockSizeMin

public long getBlockSizeMin()

setBlockSize

public void setBlockSize(int x)

getBlockSize

public int getBlockSize()

addBlob

public String addBlob(String tempFilePath)
Description copied from interface: BlobStore
Write 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:
addBlob in interface BlobStore
Parameters:
tempFilePath - the temporary file
Returns:
the blob id

writeBlob

public String writeBlob(InputStream in)
Description copied from interface: BlobStore
Write a blob from an input stream. This method closes the input stream.

Specified by:
writeBlob in interface BlobStore
Parameters:
in - the input stream
Returns:
the blob id

usesBlobId

protected void usesBlobId(String blobId)

clearInUse

public void clearInUse()

clearCache

public void clearCache()

storeBlock

protected abstract void storeBlock(byte[] digest,
                                   int level,
                                   byte[] data)
                            throws Exception
Throws:
Exception

startMark

public abstract void startMark()
                        throws Exception
Throws:
Exception

sweep

public abstract int sweep()
                   throws Exception
Throws:
Exception

isMarkEnabled

protected abstract boolean isMarkEnabled()

mark

protected abstract void mark(AbstractBlobStore.BlockId id)
                      throws Exception
Throws:
Exception

markInUse

protected void markInUse()
                  throws Exception
Throws:
Exception

readBlob

public int readBlob(String blobId,
                    long pos,
                    byte[] buff,
                    int off,
                    int length)
Specified by:
readBlob in interface BlobStore

load

public AbstractBlobStore.Data load(AbstractBlobStore.BlockId id)
Description copied from interface: Cache.Backend
Load the object. The method does not need to be synchronized (it is synchronized in the cache)

Specified by:
load in interface Cache.Backend<AbstractBlobStore.BlockId,AbstractBlobStore.Data>
Parameters:
id - the key
Returns:
the value

readBlockFromBackend

protected abstract byte[] readBlockFromBackend(AbstractBlobStore.BlockId id)
                                        throws Exception
Throws:
Exception

getBlobLength

public long getBlobLength(String blobId)
Specified by:
getBlobLength in interface BlobStore

mark

protected void mark(String blobId)
             throws IOException
Throws:
IOException

close

public void close()
Specified by:
close in interface Closeable
Specified by:
close in interface BlobStore


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.