Package 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ManagedFile.ManagedLock
-
Constructor Summary
Constructors Constructor Description ManagedFile(File file, int timeOut, int maxHoldingTime)
Creates a new managed file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ManagedFile.ManagedLock
accessRead()
Blocks fortimeOut
milliseconds for the read access to the managed file.ManagedFile.ManagedLock
accessWrite()
Blocks fortimeOut
milliseconds for the write access to the managed file.
-
-
-
Constructor Detail
-
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
-
-
Method Detail
-
accessWrite
public ManagedFile.ManagedLock accessWrite() throws IOException, TimeoutException
Blocks fortimeOut
milliseconds 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
public ManagedFile.ManagedLock accessRead() throws IOException, TimeoutException
Blocks fortimeOut
milliseconds 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.
-
-