org.glassfish.common.util.admin
Class ManagedFile

java.lang.Object
  extended by 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
static interface ManagedFile.ManagedLock
           
 
Constructor Summary
ManagedFile(File file, int timeOut, int maxHoldingTime)
          Creates a new managed file.
 
Method Summary
 ManagedFile.ManagedLock accessRead()
          Blocks for timeOut milliseconds for the read access to the managed file.
 ManagedFile.ManagedLock accessWrite()
          Blocks for timeOut milliseconds for the write access to the managed file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ManagedFile

public ManagedFile(File file,
                   int timeOut,
                   int maxHoldingTime)
            throws IOException
Creates a new managed file.

Parameters:
file - the file to manage
timeOut - the max time in milliseconds to wait for a read or write lock
maxHoldingTime - 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 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.