|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.jackrabbit.core.data.AbstractDataStore
org.apache.jackrabbit.core.data.CachingDataStore
public abstract class CachingDataStore
A caching data store that consists of LocalCache and Backend.
Backend is single source of truth. All methods first try to fetch
information from LocalCache. If record is not available in
LocalCache, then it is fetched from Backend and saved to
LocalCache for further access. This class is designed to work without
LocalCache and then all information is fetched from Backend.
To disable LocalCache set setCacheSize(long) to 0. *
Configuration:
<DataStore class="org.apache.jackrabbit.aws.ext.ds.CachingDataStore">
<param name="path" value="/data/datastore"/>
<param name="config" value="${rep.home}/backend.properties"/>
<param name="cacheSize" value="68719476736"/>
<param name="secret" value="123456"/>
<param name="setCachePurgeTrigFactor(double)" value="0.95d"/>
<param name="cacheSize" value="0.85d"/>
<param name="minRecordLength" value="1024"/>
<param name="continueOnAsyncUploadFailure" value="false"/>
<param name="concurrentUploadsThreads" value="10"/>
<param name="asyncUploadLimit" value="100"/>
<param name="uploadRetries" value="3"/>
</DataStore>
| Field Summary | |
|---|---|
protected Backend |
backend
|
protected Map<DataIdentifier,WeakReference<DataIdentifier>> |
inUse
All data identifiers that are currently in use are in this set until they are garbage collected. |
protected Map<DataIdentifier,Integer> |
uploadRetryMap
In memory map to hold failed asynchronous upload DataIdentifier
and its retry count. |
| Constructor Summary | |
|---|---|
CachingDataStore()
|
|
| Method Summary | |
|---|---|
DataRecord |
addRecord(InputStream input)
Creates a new data record in Backend. |
void |
clearInUse()
Clear the in-use list. |
void |
close()
Close the data store |
protected abstract Backend |
createBackend()
|
int |
deleteAllOlderThan(long min)
Delete objects that have a modified date older than the specified date. |
void |
deleteRecord(DataIdentifier identifier)
This method deletes record from Backend and then from
LocalCache |
Iterator<DataIdentifier> |
getAllIdentifiers()
Retrieves all identifiers from Backend. |
int |
getAsyncUploadLimit()
|
Backend |
getBackend()
|
double |
getCachePurgeResizeFactor()
|
double |
getCachePurgeTrigFactor()
|
long |
getCacheSize()
|
int |
getConcurrentUploadsThreads()
|
String |
getConfig()
Return path of configuration properties. |
long |
getLastModified(DataIdentifier identifier)
Return lastModified of record from Backend assuming
Backend as a single source of truth. |
long |
getLength(DataIdentifier identifier)
Return the length of record from LocalCache if available,
otherwise retrieve it from Backend. |
protected abstract String |
getMarkerFile()
|
int |
getMinRecordLength()
Return mininum object length. |
protected byte[] |
getOrCreateReferenceKey()
Returns the reference key of this data store. |
String |
getPath()
|
Set<String> |
getPendingUploads()
|
DataRecord |
getRecord(DataIdentifier identifier)
Returns the identified data record. |
DataRecord |
getRecordIfStored(DataIdentifier identifier)
Get a data record for the given identifier or null it data record doesn't exist in Backend |
int |
getUploadRetries()
|
void |
init(String homeDir)
Initialized the data store. |
boolean |
isContinueOnAsyncUploadFailure()
|
boolean |
isInUse(DataIdentifier identifier)
|
void |
onAbort(AsyncUploadResult result)
Callback method for aborted asynchronous upload. |
void |
onFailure(AsyncUploadResult result)
Callback method for failed asynchronous upload. |
void |
onSuccess(AsyncUploadResult result)
Callback method for successful asynchronous upload. |
void |
setAsyncUploadLimit(int asyncUploadLimit)
|
void |
setCachePurgeResizeFactor(double cachePurgeResizeFactor)
Set purge resize factor of LocalCache. |
void |
setCachePurgeTrigFactor(double cachePurgeTrigFactor)
Set purge trigger factor of LocalCache. |
void |
setCacheSize(long cacheSize)
Set size of LocalCache. |
void |
setConcurrentUploadsThreads(int concurrentUploadsThreads)
|
void |
setConfig(String config)
Set the configuration properties path. |
void |
setContinueOnAsyncUploadFailure(boolean continueOnAsyncUploadFailure)
|
void |
setMinRecordLength(int minRecordLength)
Set the minimum object length. |
void |
setPath(String path)
Set path of LocalCache. |
void |
setSecret(String secret)
Setter for configuration based secret |
void |
setUploadRetries(int uploadRetries)
|
void |
updateModifiedDateOnAccess(long before)
From now on, update the modified date of an object even when accessing it. |
| Methods inherited from class org.apache.jackrabbit.core.data.AbstractDataStore |
|---|
encodeHexString, getRecordFromReference, getReferenceFromIdentifier |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Map<DataIdentifier,WeakReference<DataIdentifier>> inUse
protected final Map<DataIdentifier,Integer> uploadRetryMap
DataIdentifier
and its retry count. Once if all retries are exhausted or file is
successfully uploaded, then corresponding entry is flushed from the map.
As all failed uploads are synchronously uploaded at startup, this map
is not required to be persisted.
protected Backend backend
| Constructor Detail |
|---|
public CachingDataStore()
| Method Detail |
|---|
protected abstract Backend createBackend()
protected abstract String getMarkerFile()
public void init(String homeDir)
throws RepositoryException
init in interface DataStorehomeDir - the home directory of the repository
RepositoryException
public DataRecord addRecord(InputStream input)
throws DataStoreException
Backend. The stream is first
consumed and the contents are saved in a temporary file and the SHA-1
message digest of the stream is calculated. If a record with the same
SHA-1 digest (and length) is found then it is returned. Otherwise new
record is created in Backend and the temporary file is moved in
place to LocalCache.
addRecord in interface DataStoreinput - binary stream
CachingDataRecord
DataStoreException - if the record could not be created.
public DataRecord getRecord(DataIdentifier identifier)
throws DataStoreException
DataStore
getRecord in interface DataStoregetRecord in class AbstractDataStoreidentifier - data identifier
DataStoreException - if the data store could not be accessed,
or if the given identifier is invalid
public DataRecord getRecordIfStored(DataIdentifier identifier)
throws DataStoreException
Backend
getRecordIfStored in interface DataStoreidentifier - identifier of record.
CachingDataRecord or null.
DataStoreException - if the data store could not be accessedpublic void updateModifiedDateOnAccess(long before)
DataStore
updateModifiedDateOnAccess in interface DataStorebefore - - update the modified date to the current time if it is older than this value
public Iterator<DataIdentifier> getAllIdentifiers()
throws DataStoreException
Backend.
getAllIdentifiers in interface DataStoreDataStoreException - if the list could not be read
public void deleteRecord(DataIdentifier identifier)
throws DataStoreException
Backend and then from
LocalCache
deleteRecord in interface MultiDataStoreAwareidentifier - data identifier
DataStoreException - if the data store could not be accessed, or if the given
identifier is invalid
public int deleteAllOlderThan(long min)
throws DataStoreException
DataStore
deleteAllOlderThan in interface DataStoremin - the minimum time
DataStoreException
public long getLastModified(DataIdentifier identifier)
throws DataStoreException
Backend assuming
Backend as a single source of truth.
DataStoreException
public long getLength(DataIdentifier identifier)
throws DataStoreException
LocalCache if available,
otherwise retrieve it from Backend.
DataStoreException
protected byte[] getOrCreateReferenceKey()
throws DataStoreException
AbstractDataStoreThis 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.
getOrCreateReferenceKey in class AbstractDataStoreDataStoreException - if the key is not availablepublic Set<String> getPendingUploads()
public void onSuccess(AsyncUploadResult result)
AsyncUploadCallback
onSuccess in interface AsyncUploadCallbackpublic void onFailure(AsyncUploadResult result)
AsyncUploadCallback
onFailure in interface AsyncUploadCallbackpublic void onAbort(AsyncUploadResult result)
AsyncUploadCallback
onAbort in interface AsyncUploadCallbackpublic void clearInUse()
DataStore
clearInUse in interface DataStorepublic boolean isInUse(DataIdentifier identifier)
public void close()
throws DataStoreException
DataStore
close in interface DataStoreDataStoreException - if a problem occurredpublic void setSecret(String secret)
secret - the secret used to sign reference binariespublic void setMinRecordLength(int minRecordLength)
minRecordLength - the lengthpublic int getMinRecordLength()
getMinRecordLength in interface DataStorepublic String getConfig()
public void setConfig(String config)
config - path of configuration properties.public long getCacheSize()
LocalCache.public void setCacheSize(long cacheSize)
LocalCache.
cacheSize - size of LocalCache.public String getPath()
LocalCache.public void setPath(String path)
LocalCache.
path - of LocalCache.public double getCachePurgeTrigFactor()
LocalCache.public void setCachePurgeTrigFactor(double cachePurgeTrigFactor)
LocalCache.
cachePurgeTrigFactor - purge trigger factor.public double getCachePurgeResizeFactor()
LocalCache.public void setCachePurgeResizeFactor(double cachePurgeResizeFactor)
LocalCache.
cachePurgeResizeFactor - purge resize factor.public int getConcurrentUploadsThreads()
public void setConcurrentUploadsThreads(int concurrentUploadsThreads)
public int getAsyncUploadLimit()
public void setAsyncUploadLimit(int asyncUploadLimit)
public boolean isContinueOnAsyncUploadFailure()
public void setContinueOnAsyncUploadFailure(boolean continueOnAsyncUploadFailure)
public int getUploadRetries()
public void setUploadRetries(int uploadRetries)
public Backend getBackend()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||