org.glassfish.common.util.admin
Class ManagedFile
java.lang.Object
org.glassfish.common.util.admin.ManagedFile
public class ManagedFile
- extends Object
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
|
Constructor Summary |
ManagedFile(File file,
int timeOut,
int maxHoldingTime)
Creates a new managed file. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ManagedFile
public ManagedFile(File file,
int timeOut,
int maxHoldingTime)
throws IOException
- 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
accessWrite
public ManagedFile.ManagedLock accessWrite()
throws IOException,
TimeoutException
- Blocks for
timeOut milliseconds for the write access
to the managed file.
- Returns:
- the lock instance on the locked file.
- Throws:
IOException - if the file cannot be locked
TimeoutException - if the lock cannot be obtained before the timeOut
expiration.
accessRead
public ManagedFile.ManagedLock accessRead()
throws IOException,
TimeoutException
- Blocks for
timeOut milliseconds for the read access
to the managed file.
- Returns:
- the lock instance on the locked file.
- Throws:
IOException - if the file cannot be locked
TimeoutException - if the lock cannot be obtained before the timeOut
expiration.
Copyright © 2012 GlassFish Community. All Rights Reserved.