Package org.eclipse.rdf4j.sail.helpers
Class DirectoryLockManager
- java.lang.Object
-
- org.eclipse.rdf4j.sail.helpers.DirectoryLockManager
-
- All Implemented Interfaces:
LockManager
public class DirectoryLockManager extends java.lang.Object implements LockManager
Used to create a lock in a directory.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.File
dir
private static java.lang.String
INFO_FILE_NAME
private static java.lang.String
LOCK_DIR_NAME
private static java.lang.String
LOCK_FILE_NAME
private org.slf4j.Logger
logger
-
Constructor Summary
Constructors Constructor Description DirectoryLockManager(java.io.File dir)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Lock
createLock(java.io.RandomAccessFile raf, java.nio.channels.FileLock fileLock)
java.lang.String
getLocation()
Technical description of where the lock is located, such as a URL.private java.io.File
getLockDir()
private java.lang.String
getLockedBy()
private java.lang.String
getProcessName()
boolean
isLocked()
Determines if the directory is locked.Lock
lockOrFail()
Creates a lock in a directory if it does not yet exist.private void
removeInvalidLock(java.io.File lockDir)
boolean
revokeLock()
Revokes a lock owned by another process.private void
sign(java.io.File infoFile)
Lock
tryLock()
Creates a lock in a directory if it does not yet exist.
-
-
-
Field Detail
-
LOCK_DIR_NAME
private static final java.lang.String LOCK_DIR_NAME
- See Also:
- Constant Field Values
-
LOCK_FILE_NAME
private static final java.lang.String LOCK_FILE_NAME
- See Also:
- Constant Field Values
-
INFO_FILE_NAME
private static final java.lang.String INFO_FILE_NAME
- See Also:
- Constant Field Values
-
logger
private final org.slf4j.Logger logger
-
dir
private final java.io.File dir
-
-
Method Detail
-
getLocation
public java.lang.String getLocation()
Description copied from interface:LockManager
Technical description of where the lock is located, such as a URL.- Specified by:
getLocation
in interfaceLockManager
-
getLockDir
private java.io.File getLockDir()
-
isLocked
public boolean isLocked()
Determines if the directory is locked.- Specified by:
isLocked
in interfaceLockManager
- Returns:
true
if the directory is already locked.
-
tryLock
public Lock tryLock()
Creates a lock in a directory if it does not yet exist.- Specified by:
tryLock
in interfaceLockManager
- Returns:
- a newly acquired lock or null if the directory is already locked.
-
lockOrFail
public Lock lockOrFail() throws SailLockedException
Creates a lock in a directory if it does not yet exist.- Specified by:
lockOrFail
in interfaceLockManager
- Returns:
- a newly acquired lock.
- Throws:
SailLockedException
- if the directory is already locked.
-
revokeLock
public boolean revokeLock()
Revokes a lock owned by another process.- Specified by:
revokeLock
in interfaceLockManager
- Returns:
true
if a lock was successfully revoked.
-
removeInvalidLock
private void removeInvalidLock(java.io.File lockDir)
-
getLockedBy
private java.lang.String getLockedBy()
-
createLock
private Lock createLock(java.io.RandomAccessFile raf, java.nio.channels.FileLock fileLock)
-
sign
private void sign(java.io.File infoFile) throws java.io.IOException
- Throws:
java.io.IOException
-
getProcessName
private java.lang.String getProcessName()
-
-