org.apache.jackrabbit.core.data
Class MultiDataStore

java.lang.Object
  extended by org.apache.jackrabbit.core.data.MultiDataStore
All Implemented Interfaces:
DataStore

public class MultiDataStore
extends Object
implements DataStore

A MultiDataStore can handle two independent DataStores.

Attention: You will lost the global single instance mechanism !

It can be used if you have two storage systems. One for fast access and a other one like a archive DataStore on a slower storage system. All Files will be added to the primary DataStore. On read operations first the primary dataStore will be used and if no Record is found the archive DataStore will be used. The GarabageCollector will only remove files from the archive DataStore.

The internal MoveDataTask will be started automatically and could be configured with the following properties.

The Configuration:

 <DataStore class="org.apache.jackrabbit.core.data.MultiDataStore">
     <param name="maxAge" value="60"/>
     <param name="moveDataTaskSleep" value="604800"/>
     <param name="moveDataTaskFirstRunHourOfDay" value="1"/>
     <param name="sleepBetweenRecords" value="100"/>
     <param name="delayedDelete" value="false"/>
     <param name="delayedDeleteSleep" value="86400"/>
     <param name="primary" value="org.apache.jackrabbit.core.data.db.DbDataStore">
        <param .../>
     </param>
     <param name="archive" value="org.apache.jackrabbit.core.data.FileDataStore">
        <param .../>
     </param>
 </DataStore>
 


Nested Class Summary
 class MultiDataStore.DeleteDelayedIdentifiersTask
          Class to clean up the delayed DataRecords from the primary data store.
 class MultiDataStore.MoveDataTask
          Class for maintaining the MultiDataStore.
 
Constructor Summary
MultiDataStore()
           
 
Method Summary
 DataRecord addRecord(InputStream stream)
          Creates a new data record in the primary data store.
 void clearInUse()
          Clear the in-use list.
 void close()
          Close the data store
 int deleteAllOlderThan(long min)
          Delete objects that have a modified date older than the specified date from the archive data store.
 Iterator<DataIdentifier> getAllIdentifiers()
          Get all identifiers from the archive data store.
 long getDelayedDeleteSleep()
           
 int getMaxAge()
           
 int getMinRecordLength()
          Get the minimum size of an object that should be stored in the primary data store.
 int getMoveDataTaskFirstRunHourOfDay()
           
 int getMoveDataTaskSleep()
           
 DataRecord getRecord(DataIdentifier identifier)
          Returns the identified data record from the primary data store.
 DataRecord getRecordFromReference(String reference)
          Returns the record that matches the given binary reference.
 DataRecord getRecordIfStored(DataIdentifier identifier)
          Check if a record for the given identifier exists in the primary data store.
 long getSleepBetweenRecords()
           
 void init(String homeDir)
          Initialized the data store
 boolean isDelayedDelete()
           
 void setArchiveDataStore(DataStore dataStore)
          Setter for the archive dataStore
 void setDelayedDelete(boolean delayedDelete)
           
 void setDelayedDeleteSleep(long delayedDeleteSleep)
           
 void setMaxAge(int maxAge)
           
 void setMoveDataTaskFirstRunHourOfDay(int hourOfDay)
           
 void setMoveDataTaskSleep(int sleep)
           
 void setPrimaryDataStore(DataStore dataStore)
          Setter for the primary dataStore
 void setSleepBetweenRecords(long millis)
           
 void updateModifiedDateOnAccess(long before)
          From now on, update the modified date of an object even when accessing it in the archive data store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiDataStore

public MultiDataStore()
Method Detail

setPrimaryDataStore

public void setPrimaryDataStore(DataStore dataStore)
Setter for the primary dataStore

Parameters:
dataStore -

setArchiveDataStore

public void setArchiveDataStore(DataStore dataStore)
Setter for the archive dataStore

Parameters:
dataStore -

getRecordIfStored

public DataRecord getRecordIfStored(DataIdentifier identifier)
                             throws DataStoreException
Check if a record for the given identifier exists in the primary data store. If not found there it will be returned from the archive data store. If no record exists, this method returns null.

Specified by:
getRecordIfStored in interface DataStore
Parameters:
identifier - data identifier
Returns:
the record if found, and null if not
Throws:
DataStoreException - if the data store could not be accessed

getRecord

public DataRecord getRecord(DataIdentifier identifier)
                     throws DataStoreException
Returns the identified data record from the primary data store. If not found there it will be returned from the archive data store. The given identifier should be the identifier of a previously saved data record. Since records are never removed, there should never be cases where the identified record is not found. Abnormal cases like that are treated as errors and handled by throwing an exception.

Specified by:
getRecord in interface DataStore
Parameters:
identifier - data identifier
Returns:
identified data record
Throws:
DataStoreException - if the data store could not be accessed, or if the given identifier is invalid

addRecord

public DataRecord addRecord(InputStream stream)
                     throws DataStoreException
Creates a new data record in the primary data store. The given binary stream is consumed and a binary record containing the consumed stream is created and returned. If the same stream already exists in another record, then that record is returned instead of creating a new one.

The given stream is consumed and not closed by this method. It is the responsibility of the caller to close the stream. A typical call pattern would be:

     InputStream stream = ...;
     try {
         record = store.addRecord(stream);
     } finally {
         stream.close();
     }
 

Specified by:
addRecord in interface DataStore
Parameters:
stream - binary stream
Returns:
data record that contains the given stream
Throws:
DataStoreException - if the data store could not be accessed

updateModifiedDateOnAccess

public void updateModifiedDateOnAccess(long before)
From now on, update the modified date of an object even when accessing it in the archive data store. Usually, the modified date is only updated when creating a new object, or when a new link is added to an existing object. When this setting is enabled, even getLength() will update the modified date.

Specified by:
updateModifiedDateOnAccess in interface DataStore
Parameters:
before - - update the modified date to the current time if it is older than this value

deleteAllOlderThan

public int deleteAllOlderThan(long min)
                       throws DataStoreException
Delete objects that have a modified date older than the specified date from the archive data store.

Specified by:
deleteAllOlderThan in interface DataStore
Parameters:
min - the minimum time
Returns:
the number of data records deleted
Throws:
DataStoreException

getAllIdentifiers

public Iterator<DataIdentifier> getAllIdentifiers()
                                           throws DataStoreException
Get all identifiers from the archive data store.

Specified by:
getAllIdentifiers in interface DataStore
Returns:
an iterator over all DataIdentifier objects
Throws:
DataStoreException - if the list could not be read

getRecordFromReference

public DataRecord getRecordFromReference(String reference)
                                  throws DataStoreException
Description copied from interface: DataStore
Returns the record that matches the given binary reference. Returns null if the reference is invalid, for example if it points to a record that does not exist.

Specified by:
getRecordFromReference in interface DataStore
Parameters:
reference - binary reference
Returns:
matching record, or null
Throws:
DataStoreException - if the data store could not be accessed

init

public void init(String homeDir)
          throws RepositoryException
Initialized the data store

Specified by:
init in interface DataStore
Parameters:
homeDir - the home directory of the repository
Throws:
RepositoryException

getMinRecordLength

public int getMinRecordLength()
Get the minimum size of an object that should be stored in the primary data store.

Specified by:
getMinRecordLength in interface DataStore
Returns:
the minimum size in bytes

close

public void close()
           throws DataStoreException
Close the data store

Specified by:
close in interface DataStore
Throws:
DataStoreException - if a problem occurred

clearInUse

public void clearInUse()
Clear the in-use list. This is only used for testing to make the the garbage collection think that objects are no longer in use.

Specified by:
clearInUse in interface DataStore

getMaxAge

public int getMaxAge()

setMaxAge

public void setMaxAge(int maxAge)

getMoveDataTaskSleep

public int getMoveDataTaskSleep()

getMoveDataTaskFirstRunHourOfDay

public int getMoveDataTaskFirstRunHourOfDay()

setMoveDataTaskSleep

public void setMoveDataTaskSleep(int sleep)

setMoveDataTaskFirstRunHourOfDay

public void setMoveDataTaskFirstRunHourOfDay(int hourOfDay)

setSleepBetweenRecords

public void setSleepBetweenRecords(long millis)

getSleepBetweenRecords

public long getSleepBetweenRecords()

isDelayedDelete

public boolean isDelayedDelete()

setDelayedDelete

public void setDelayedDelete(boolean delayedDelete)

getDelayedDeleteSleep

public long getDelayedDeleteSleep()

setDelayedDeleteSleep

public void setDelayedDeleteSleep(long delayedDeleteSleep)


Copyright © 2004-2014 The Apache Software Foundation. All Rights Reserved.