Package org.glassfish.common.util.admin
Class ManagedFile
java.lang.Object
org.glassfish.common.util.admin.ManagedFile
Defines the notion of a managed file with a classic Read-Write locking policy.
A managed file can be locked for multiple concurrent reads or a single write.
A simple example could follow this :
ManagedFile managedFile = new ManagedFile(new File(...), 1000, -1);
Lock writeLock;
try {
writeLock = managedFile.writeAccess();
// write or delete the file
} finally {
writeLock.unlock();
}
- Author:
- Jerome Dochez
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionManagedFile(File file, int timeOut, int maxHoldingTime) Creates a new managed file. -
Method Summary
Modifier and TypeMethodDescriptionBlocks fortimeOutmilliseconds for the read access to the managed file.Blocks fortimeOutmilliseconds for the write access to the managed file.
-
Constructor Details
-
ManagedFile
Creates a new managed file.- Parameters:
file- the file to managetimeOut- the max time in milliseconds to wait for a read or write lockmaxHoldingTime- the max time in milliseconds to hold the read or write lock- Throws:
IOException- when the file cannot be locked
-
-
Method Details
-
accessWrite
Blocks fortimeOutmilliseconds for the write access to the managed file.- Returns:
- the lock instance on the locked file.
- Throws:
IOException- if the file cannot be lockedTimeoutException- if the lock cannot be obtained before the timeOut expiration.
-
accessRead
Blocks fortimeOutmilliseconds for the read access to the managed file.- Returns:
- the lock instance on the locked file.
- Throws:
IOException- if the file cannot be lockedTimeoutException- if the lock cannot be obtained before the timeOut expiration.
-