Class VFSBackend

  • All Implemented Interfaces:
    Backend

    public class VFSBackend
    extends AbstractBackend
    A data store backend that stores data on VFS file system.
    • Constructor Detail

      • VFSBackend

        public VFSBackend​(org.apache.commons.vfs2.FileObject baseFolder)
    • Method Detail

      • getLength

        public long getLength​(DataIdentifier identifier)
                       throws DataStoreException
        Return length of record identified by identifier.
        Parameters:
        identifier - identifier of record.
        Returns:
        length of the record.
        Throws:
        DataStoreException - if record not found or any error.
      • getLastModified

        public long getLastModified​(DataIdentifier identifier)
                             throws DataStoreException
        Return lastModified of record identified by identifier.
        Parameters:
        identifier - identifier of record.
        Returns:
        lastModified of the record.
        Throws:
        DataStoreException - if record not found or any error.
      • write

        public void write​(DataIdentifier identifier,
                          File file)
                   throws DataStoreException
        Stores file to backend with identifier used as key. If key pre-exists, it updates the timestamp of the key.
        Parameters:
        identifier - key of the file
        file - file that would be stored in backend.
        Throws:
        DataStoreException - for any error.
      • exists

        public boolean exists​(DataIdentifier identifier,
                              boolean touch)
                       throws DataStoreException
        This method check the existence of record in backend. Return true if records exists else false. This method also touch record identified by identifier if touch is true.
        Throws:
        DataStoreException
      • exists

        public boolean exists​(DataIdentifier identifier)
                       throws DataStoreException
        This method check the existence of record in backend.
        Parameters:
        identifier - identifier to be checked.
        Returns:
        true if records exists else false.
        Throws:
        DataStoreException
      • isTouchFilePreferred

        public boolean isTouchFilePreferred()
        Returns true if a touch file should be used to save/get the last modified time for a file object. True by default unless the getBaseFolderObject() is representing a local file system folder (e.g, file://...).

        When returns true, this backend creates a separate file named by the original file base name followed by this touch file name suffix. So, this backend can set the last modified time on the separate touch file instead of trying to do it on the original entry file. For example, WebDAV file system doesn't allow to modify the last modified time on a file.

        Returns:
        true if a touch file should be used to save/get the last modified time for a file object
      • setTouchFilePreferred

        public void setTouchFilePreferred​(boolean touchFilePreferred)
        Sets whether or not a touch file should be used to save/get the last modified timestamp for a file object.
        Parameters:
        touchFilePreferred - whether or not a touch file should be used to save/get the last modified timestamp for a file object
      • getBaseFolderObject

        protected org.apache.commons.vfs2.FileObject getBaseFolderObject()
        Returns the VFS base folder object.
        Returns:
        the VFS base folder object
      • resolveFileObject

        protected org.apache.commons.vfs2.FileObject resolveFileObject​(DataIdentifier identifier)
                                                                throws DataStoreException
        Returns a resolved identified file object. This method implements the pattern used to avoid problems with too many files in a single folder.
        Parameters:
        identifier - data identifier
        Returns:
        identified file object
        Throws:
        DataStoreException - if any file system exception occurs
      • resolveFileObjectRelPath

        protected String resolveFileObjectRelPath​(DataIdentifier identifier)
        Returns a resolved relative file object path by the given entry identifier.
        Parameters:
        identifier - entry identifier
        Returns:
        a resolved relative file object path by the given entry identifier
      • getExistingFileObject

        protected org.apache.commons.vfs2.FileObject getExistingFileObject​(DataIdentifier identifier)
                                                                    throws DataStoreException
        Returns the identified file object. If not existing, returns null.
        Parameters:
        identifier - data identifier
        Returns:
        identified file object
        Throws:
        DataStoreException - if any file system exception occurs
      • isTouchFileObject

        protected boolean isTouchFileObject​(org.apache.commons.vfs2.FileObject fileObject)
        Returns true if the fileObject is used for touching purpose.
        Parameters:
        fileObject - file object
        Returns:
        true if the fileObject is used for touching purpose
      • getTouchFileObject

        protected org.apache.commons.vfs2.FileObject getTouchFileObject​(org.apache.commons.vfs2.FileObject fileObject,
                                                                        boolean create)
                                                                 throws DataStoreException
        Returns the touch file for the fileObject. If there's no corresponding touch file existing, then returns null when create is false. When create is true, it creates a new touch file if no corresponding touch file exists.
        Parameters:
        fileObject - file object
        create - create a touch file if not existing
        Returns:
        touch file object
        Throws:
        DataStoreException - if any file system exception occurs
      • getAsyncWriteExecutorActiveCount

        protected int getAsyncWriteExecutorActiveCount()
        Returns the approximate number of threads that are actively executing asynchronous writing tasks.
        Returns:
        the approximate number of threads that are actively executing asynchronous writing tasks