public abstract class CachingBinaryManager extends AbstractBinaryManager
BinaryManager
that uses a cache for its files because fetching them is expensive.
Initialization of the BinaryManager
must call initializeCache(java.io.File, long, org.nuxeo.ecm.core.blob.binary.FileStorage)
from the initialize(java.lang.String, java.util.Map<java.lang.String, java.lang.String>)
method.
Modifier and Type | Field and Description |
---|---|
protected File |
cachedir |
FileCache |
fileCache |
protected FileStorage |
fileStorage |
protected static String |
LEN_DIGEST_SUFFIX |
blobProviderId, DEFAULT_DEPTH, DEFAULT_DIGEST, descriptor, DIGESTS_BY_LENGTH, garbageCollector, MAX_BUF_SIZE, MD5_DIGEST, MD5_DIGEST_LENGTH, MIN_BUF_SIZE, SHA1_DIGEST, SHA1_DIGEST_LENGTH, SHA256_DIGEST, SHA256_DIGEST_LENGTH
PROP_KEY, PROP_PATH
Constructor and Description |
---|
CachingBinaryManager() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the binary manager and releases all resources and temporary objects held by it.
|
protected Binary |
getBinary(InputStream in)
Creates a binary value from the given input stream.
|
Binary |
getBinary(String digest)
Returns a
Binary corresponding to the given digest. |
File |
getFile(String digest)
Gets a file from cache or storage.
|
Long |
getLength(String digest)
Gets a file length from cache or storage.
|
protected Long |
getLengthFromCache(String digest) |
void |
initialize(String blobProviderId,
Map<String,String> properties)
Initializes the binary manager.
|
void |
initializeCache(File dir,
long maxSize,
FileStorage fileStorage)
Initialize the cache.
|
void |
initializeCache(String cacheSizeStr,
FileStorage fileStorage)
Initialize the cache.
|
protected void |
putLengthInCache(String digest,
Long len) |
getBinary, getDefaultDigestAlgorithm, getDescriptor, getDigestAlgorithm, getGarbageCollector, removeBinaries, storeAndDigest, toHexString
protected static final String LEN_DIGEST_SUFFIX
protected FileStorage fileStorage
public CachingBinaryManager()
public void initialize(String blobProviderId, Map<String,String> properties) throws IOException
BinaryManager
initialize
in interface BinaryManager
initialize
in class AbstractBinaryManager
blobProviderId
- the blob provider id for this binary managerproperties
- initialization propertiesIOException
public void initializeCache(File dir, long maxSize, FileStorage fileStorage)
dir
- the directory to use to store cached filesmaxSize
- the maximum size of the cache (in bytes)fileStorage
- the file storage mechanism to use to store and fetch filespublic void initializeCache(String cacheSizeStr, FileStorage fileStorage) throws IOException
cacheSizeStr
- the maximum size of the cache (as a String)fileStorage
- the file storage mechanism to use to store and fetch filesIOException
initializeCache(File, long, FileStorage)
,
SizeUtils.parseSizeInBytes(String)
public void close()
BinaryManager
protected Binary getBinary(InputStream in) throws IOException
AbstractBinaryManager
getBinary
in class AbstractBinaryManager
IOException
public Binary getBinary(String digest)
BinaryManager
Binary
corresponding to the given digest.
A null
is returned if the digest could not be found.
getBinary
in interface BinaryManager
getBinary
in class AbstractBinaryManager
digest
- the digest, or null
public File getFile(String digest) throws IOException
Used by LazyBinary
.
IOException
public Long getLength(String digest) throws IOException
Use by LazyBinary
.
IOException
protected Long getLengthFromCache(String digest) throws IOException
IOException
protected void putLengthInCache(String digest, Long len) throws IOException
IOException
Copyright © 2015 Nuxeo SA. All rights reserved.