Class 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>
     
    • maxAge: defines how many days the content will reside in the primary data store. DataRecords that have been added before this time span will be moved to the archive data store. (default = 60)
    • moveDataTaskSleep: specifies the sleep time of the moveDataTaskThread in seconds. (default = 60 * 60 * 24 * 7, which equals 7 days)
    • moveDataTaskNextRunHourOfDay: specifies the hour at which the moveDataTaskThread initiates its first run (default = 1 which means 01:00 at night)
    • sleepBetweenRecords: specifies the delay in milliseconds between scanning data records (default = 100)
    • delayedDelete: its possible to delay the delete operation on the primary data store. The DataIdentifiers will be written to a temporary file. The file will be processed after a defined sleep (see delayedDeleteSleep) It's useful if you like to create a snapshot of the primary data store backend in the meantime before the data will be deleted. (default = false)
    • delayedDeleteSleep: specifies the sleep time of the delayedDeleteTaskThread in seconds. (default = 60 * 60 * 24, which equals 1 day). This means the delayed delete from the primary data store will be processed after one day.
    • 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
      • 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
      • 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
      • 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)