Package org.ametys.runtime.data
Class AmetysHomeLock
- java.lang.Object
-
- org.ametys.runtime.data.AmetysHomeLock
-
public class AmetysHomeLock extends Object
Exclusive lock on the Ametys Home directory. Based on the Jackrabbit repository lock.
-
-
Field Summary
Fields Modifier and Type Field Description private static String
__LOCK_FILE
Name of the lock file within a directory.private File
_directory
The ametys home directoryprivate File
_file
The lock file within the directoryprivate String
_identifier
Unique identifier (canonical path name) of the locked directory.private FileLock
_lock
The file lock.private RandomAccessFile
_randomAccessFile
The random access file.
-
Constructor Summary
Constructors Constructor Description AmetysHomeLock(File ametysHome)
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
_closeRandomAccessFile()
Close the random access file if it is open, and set it to null.private void
_tryLock()
Try to lock the random access file.void
acquire()
Lock the Ametys home directoryvoid
release()
Releases repository lock.
-
-
-
Field Detail
-
__LOCK_FILE
private static final String __LOCK_FILE
Name of the lock file within a directory.- See Also:
- Constant Field Values
-
_directory
private File _directory
The ametys home directory
-
_randomAccessFile
private RandomAccessFile _randomAccessFile
The random access file.
-
_identifier
private String _identifier
Unique identifier (canonical path name) of the locked directory. Used to ensure exclusive locking within a single JVM.
-
-
Constructor Detail
-
AmetysHomeLock
public AmetysHomeLock(File ametysHome) throws AmetysHomeLockException
Default constructor. Initialize the instance. The lock still needs to be explicitly acquired using theacquire()
method.- Parameters:
ametysHome
- The ametys home directory- Throws:
AmetysHomeLockException
- if the canonical path of the directory can not be determined
-
-
Method Detail
-
acquire
public void acquire() throws AmetysHomeLockException
Lock the Ametys home directory- Throws:
AmetysHomeLockException
- if the repository lock can not be acquired
-
_tryLock
private void _tryLock() throws AmetysHomeLockException
Try to lock the random access file.- Throws:
AmetysHomeLockException
- If an error occurs during the lock attempt.
-
_closeRandomAccessFile
private void _closeRandomAccessFile()
Close the random access file if it is open, and set it to null.
-
release
public void release()
Releases repository lock.
-
-