Package org.apache.jackrabbit.vfs.ext.ds
Class VFSBackend
- java.lang.Object
-
- org.apache.jackrabbit.core.data.AbstractBackend
-
- org.apache.jackrabbit.vfs.ext.ds.VFSBackend
-
- All Implemented Interfaces:
Backend
public class VFSBackend extends AbstractBackend
A data store backend that stores data on VFS file system.
-
-
Constructor Summary
Constructors Constructor Description VFSBackend(org.apache.commons.vfs2.FileObject baseFolder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<DataIdentifier>
deleteAllOlderThan(long timestamp)
Delete all records which are older than timestamp.void
deleteRecord(DataIdentifier identifier)
Delete record identified by identifier.boolean
exists(DataIdentifier identifier)
This method check the existence of record in backend.boolean
exists(DataIdentifier identifier, boolean touch)
This method check the existence of record in backend.Iterator<DataIdentifier>
getAllIdentifiers()
Returns identifiers of all records that exists in backend.protected int
getAsyncWriteExecutorActiveCount()
Returns the approximate number of threads that are actively executing asynchronous writing tasks.protected org.apache.commons.vfs2.FileObject
getBaseFolderObject()
Returns the VFS base folder object.protected org.apache.commons.vfs2.FileObject
getExistingFileObject(DataIdentifier identifier)
Returns the identified file object.long
getLastModified(DataIdentifier identifier)
Return lastModified of record identified by identifier.long
getLength(DataIdentifier identifier)
Return length of record identified by identifier.protected org.apache.commons.vfs2.FileObject
getTouchFileObject(org.apache.commons.vfs2.FileObject fileObject, boolean create)
Returns the touch file for the fileObject.void
init(CachingDataStore store, String homeDir, String config)
This method initialize backend with the configuration.protected boolean
isTouchFileObject(org.apache.commons.vfs2.FileObject fileObject)
Returns true if the fileObject is used for touching purpose.boolean
isTouchFilePreferred()
Returns true if a touch file should be used to save/get the last modified time for a file object.InputStream
read(DataIdentifier identifier)
Return inputstream of record identified by identifier.protected org.apache.commons.vfs2.FileObject
resolveFileObject(DataIdentifier identifier)
Returns a resolved identified file object.protected String
resolveFileObjectRelPath(DataIdentifier identifier)
Returns a resolved relative file object path by the given entry identifier.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.void
touch(DataIdentifier identifier, long minModifiedDate)
Update the lastModified of record if it's lastModified < minModifiedDate.void
touchAsync(DataIdentifier identifier, long minModifiedDate, AsyncTouchCallback callback)
Update the lastModified of record if it's lastModified < minModifiedDate asynchronously.void
write(DataIdentifier identifier, File file)
Stores file to backend with identifier used as key.void
writeAsync(DataIdentifier identifier, File file, AsyncUploadCallback callback)
Write file to backend in asynchronous mode.-
Methods inherited from class org.apache.jackrabbit.core.data.AbstractBackend
close, createAsyncWriteExecutor, getAsyncWriteExecutor, getAsyncWritePoolSize, getConfig, getDataStore, getHomeDir, setAsyncWritePoolSize, setConfig, setDataStore, setHomeDir
-
-
-
-
Method Detail
-
init
public void init(CachingDataStore store, String homeDir, String config) throws DataStoreException
This method initialize backend with the configuration.- Specified by:
init
in interfaceBackend
- Overrides:
init
in classAbstractBackend
- Parameters:
store
-CachingDataStore
homeDir
- path of repository home dir.config
- path of config property file.- Throws:
DataStoreException
-
read
public InputStream read(DataIdentifier identifier) throws DataStoreException
Return inputstream of record identified by identifier.- Parameters:
identifier
- identifier of record.- Returns:
- inputstream of the record.
- Throws:
DataStoreException
- if record not found or any error.
-
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 filefile
- file that would be stored in backend.- Throws:
DataStoreException
- for any error.
-
writeAsync
public void writeAsync(DataIdentifier identifier, File file, AsyncUploadCallback callback) throws DataStoreException
Write file to backend in asynchronous mode.callback
- Callback interface to called after upload succeed or failed.- Throws:
DataStoreException
-
getAllIdentifiers
public Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException
Returns identifiers of all records that exists in backend.- Returns:
- iterator consisting of all identifiers
- Throws:
DataStoreException
-
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
-
touch
public void touch(DataIdentifier identifier, long minModifiedDate) throws DataStoreException
Update the lastModified of record if it's lastModified < minModifiedDate.- Throws:
DataStoreException
-
touchAsync
public void touchAsync(DataIdentifier identifier, long minModifiedDate, AsyncTouchCallback callback) throws DataStoreException
Update the lastModified of record if it's lastModified < minModifiedDate asynchronously. Result of update is passed using appropriateAsyncTouchCallback
methods. If identifier's lastModified > minModifiedAsyncTouchCallback.onAbort(AsyncTouchResult)
is called. Any exception is communicated throughAsyncTouchCallback.onFailure(AsyncTouchResult)
. On successful update of lastModified,AsyncTouchCallback.onSuccess(AsyncTouchResult)
is invoked.- Throws:
DataStoreException
-
deleteAllOlderThan
public Set<DataIdentifier> deleteAllOlderThan(long timestamp) throws DataStoreException
Delete all records which are older than timestamp.- Returns:
Set
of identifiers which are deleted.- Throws:
DataStoreException
-
deleteRecord
public void deleteRecord(DataIdentifier identifier) throws DataStoreException
Delete record identified by identifier. No-op if identifier not found.- 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 thegetBaseFolderObject()
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 whencreate
is false. Whencreate
is true, it creates a new touch file if no corresponding touch file exists.- Parameters:
fileObject
- file objectcreate
- 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
-
-