Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ModeShape Distribution 3.0.0.Beta3
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.modeshape.jcr.value.binary
Class FileLocks

    java.lang.Object
      org.modeshape.jcr.value.binary.FileLocks

    public final class FileLocks

extends Object

A utility class that represents read and write lock for files, which internally uses `FileLock` to coordinate file locks with other processes. This class maintains a single file lock per file, since multiple concurrent `FileLock`s on the same file are not allowed by the JVM. It also uses reference counts to remove locks only when a named lock is no longer being used.

Nested Class Summary
`protected class` | `FileLocks.LockHolder`
`protected static class` | `FileLocks.WrappedLock`

Method Summary
`static FileLocks` | `get()` Obtain the singleton instance for this virtual machine.
`protected FileLocks.WrappedLock` | `lock(File file, boolean writeLock, boolean block)`
`FileLocks.WrappedLock` | `readLock(File file)` Obtain a read lock for the supplied file.
`int` | `size()` Get the number of named locks.
`FileLocks.WrappedLock` | `tryReadLock(File file)` Try to obtain a read lock for the supplied file.
`FileLocks.WrappedLock` | `tryWriteLock(File file)` Try to obtain a write lock for the supplied file.
`protected void` | `unlock(FileLocks.LockHolder holder, Lock rawLock)`
`FileLocks.WrappedLock` | `writeLock(File file)` Obtain a write lock for the supplied file.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### get

    public static FileLocks get()

  Obtain the singleton instance for this virtual machine.

  Returns:
    the file lock manager; never null

### writeLock

    public FileLocks.WrappedLock writeLock(File file)
                                    throws IOException

  Obtain a write lock for the supplied file. When this method returns, the current thread will have obtained the lock. Therefore, there is no need to call any of the lock methods (e.g., `FileLocks.WrappedLock.lock()`, `FileLocks.WrappedLock.lockInterruptibly()`, `FileLocks.WrappedLock.tryLock()` or `FileLocks.WrappedLock.tryLock(long, TimeUnit)`), as those methods will immediately return.

  Parameters:
    `file` - the file to be locked; may not be null
  Returns:
    the lock held by the current thread; never null
  Throws:
    `IOException` - if there is a problem obtaining the file lock

### readLock

    public FileLocks.WrappedLock readLock(File file)
                                   throws IOException

  Obtain a read lock for the supplied file. When this method returns, the current thread will have obtained the lock. Therefore, there is no need to call any of the lock methods (e.g., `FileLocks.WrappedLock.lock()`, `FileLocks.WrappedLock.lockInterruptibly()`, `FileLocks.WrappedLock.tryLock()` or `FileLocks.WrappedLock.tryLock(long, TimeUnit)`), as those methods will immediately return.

  Parameters:
    `file` - the file to be locked; may not be null
  Returns:
    the lock held by the current thread; never null
  Throws:
    `IOException` - if there is a problem obtaining the file lock

### tryWriteLock

    public FileLocks.WrappedLock tryWriteLock(File file)
                                       throws IOException

  Try to obtain a write lock for the supplied file. When this method returns a non-null lock, the current thread will have obtained the lock. Therefore, there is no need to call any of the lock methods (e.g., `FileLocks.WrappedLock.lock()`, `FileLocks.WrappedLock.lockInterruptibly()`, `FileLocks.WrappedLock.tryLock()` or `FileLocks.WrappedLock.tryLock(long, TimeUnit)`), as those methods will immediately return.

  However, if this method returns `null`, this method could not obtain the lock.

  Parameters:
    `file` - the file to be locked; may not be null
  Returns:
    the lock held by the current thread; null if the lock could not be obtained
  Throws:
    `IOException` - if there is a problem obtaining the file lock

### tryReadLock

    public FileLocks.WrappedLock tryReadLock(File file)
                                      throws IOException

  Try to obtain a read lock for the supplied file. When this method returns a non-null lock, the current thread will have obtained the lock. Therefore, there is no need to call any of the lock methods (e.g., `FileLocks.WrappedLock.lock()`, `FileLocks.WrappedLock.lockInterruptibly()`, `FileLocks.WrappedLock.tryLock()` or `FileLocks.WrappedLock.tryLock(long, TimeUnit)`), as those methods will immediately return.

  However, if this method returns `null`, this method could not obtain the lock.

  Parameters:
    `file` - the file to be locked; may not be null
  Returns:
    the lock held by the current thread; null if the lock could not be obtained
  Throws:
    `IOException` - if there is a problem obtaining the file lock

### lock

    protected final FileLocks.WrappedLock lock(File file,
                                               boolean writeLock,
                                               boolean block)
                                        throws IOException

  Throws:
    `IOException`

### unlock

    protected void unlock(FileLocks.LockHolder holder,
                          Lock rawLock)

### size

    public int size()

  Get the number of named locks.

  Returns:
    the number of named locks; never negative

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ModeShape Distribution 3.0.0.Beta3
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.