Class LockableFile
java.lang.Object
net.adoptopenjdk.icedteaweb.lockingfile.LockableFile
Process invalid input: '&' thread lockable access to a file. Creates file if it does not already exist.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interfaceInterface for abstracting away the details of how a file is locked system wide.private classThis is an alternative approach to locking a file system-wide.private classThis is the recommended way to lock a file system wide (across multiple processes). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Fileprivate static final Map<File, LockableFile> private static final Loggerprivate final LockableFile.InterProcessLockprivate final booleanprivate final ReentrantLock -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleancanWriteFile(File file) private booleancanWriteParent(File file) private voidprivate voidprivate voidgetFile()Get the file being locked.static LockableFilegetInstance(File file) Get a LockableFile for a given File.booleanbooleanprivate booleanisReadOnly(File file) voidlock()Lock access to the file.Lock is reentrant.booleantryLock()voidunlock()Unlock access to the file.Lock is reentrant.
-
Field Details
-
logger
-
instanceCache
-
file
-
readOnly
private final boolean readOnly -
threadLock
-
processLock
-
-
Constructor Details
-
LockableFile
-
-
Method Details
-
getInstance
Get a LockableFile for a given File. Ensures that we share the same instance for all threads.- Parameters:
file- the file to lock- Returns:
- a LockableFile instance
-
isReadOnly
-
canWriteFile
-
canWriteParent
-
createParentDirIfMissing
-
createLockableFile
private void createLockableFile() -
getFile
-
isReadOnly
public boolean isReadOnly()- Returns:
- if the file is read only.
-
lock
Lock access to the file.Lock is reentrant.- Throws:
IOException- if an I/O error occurs.
-
tryLock
public boolean tryLock() -
createFileIfMissing
- Throws:
IOException
-
unlock
Unlock access to the file.Lock is reentrant. Does not do anything if not holding the lock.- Throws:
IOException- if an I/O error occurs.
-
isHeldByCurrentThread
public boolean isHeldByCurrentThread()
-