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

## org.owasp.dependencycheck.concurrency
Class DirectorySpinLock

    java.lang.Object
      org.owasp.dependencycheck.concurrency.DirectorySpinLock

All Implemented Interfaces:
  Closeable

    public class DirectorySpinLock

extends Object
implements Closeable

Implements a spin lock on a given directory. If the lock cannot be obtained, the process will "spin" waiting for an opportunity to obtain the lock requested.

Author:
  Jeremy Long (jeremy.long@owasp.org)

Field Summary
`static String` | `LOCK_NAME` The name of the lock file.
`static int` | `MAX_SPIN` The maximum wait period used when attempting to obtain a lock.

Constructor Summary
`DirectorySpinLock(File directory)` Constructs a new spin lock on the given directory.

Method Summary
`void` | `close()` Releases any locks and closes the underlying channel.
`long` | `getMaxWait()` Get the maximum wait time, in seconds, that the spin lock will wait while trying to obtain a lock.
`void` | `obtainExclusiveLock()` Attempts to obtain an exclusive lock; an exception is thrown if the lock could not be obtained.
`protected void` | `obtainLock(boolean shared)` Attempts to obtain a lock; an exception is thrown if the lock could not be obtained.
`protected void` | `obtainLock(boolean shared, long maxWait)` Attempts to obtain a lock; an exception is thrown if the lock could not be obtained.
`void` | `obtainSharedLock()` Attempts to obtain an exclusive lock; an exception is thrown if the lock could not be obtained.
`void` | `release()` Releases the lock.
`void` | `setMaxWait(long maxWait)` Set the maximum wait time, in seconds, that the spin lock will wait while trying to obtain a lock.

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

Field Detail

### LOCK_NAME

    public static final String LOCK_NAME

  The name of the lock file.

  See Also:
    Constant Field Values

### MAX_SPIN

    public static final int MAX_SPIN

  The maximum wait period used when attempting to obtain a lock.

  See Also:
    Constant Field Values

Constructor Detail

### DirectorySpinLock

    public DirectorySpinLock(File directory)
                      throws InvalidDirectoryException,
                             DirectoryLockException

  Constructs a new spin lock on the given directory.

  Parameters:
    `directory` - the directory to monitor/lock
  Throws:
    `InvalidDirectoryException` - thrown if there is an issue with the directory provided
    `DirectoryLockException` - thrown there is an issue obtaining a handle to the lock file

Method Detail

### getMaxWait

    public long getMaxWait()

  Get the maximum wait time, in seconds, that the spin lock will wait while trying to obtain a lock.

  Returns:
    the number of seconds the spin lock will wait

### setMaxWait

    public void setMaxWait(long maxWait)

  Set the maximum wait time, in seconds, that the spin lock will wait while trying to obtain a lock.

  Parameters:
    `maxWait` - the number of seconds the spin lock will wait

### obtainSharedLock

    public void obtainSharedLock()
                          throws DirectoryLockException

  Attempts to obtain an exclusive lock; an exception is thrown if the lock could not be obtained. This method may block for a few seconds if a lock cannot be obtained.

  Throws:
    `DirectoryLockException` - thrown if there is an exception obtaining the lock

### obtainExclusiveLock

    public void obtainExclusiveLock()
                             throws DirectoryLockException

  Attempts to obtain an exclusive lock; an exception is thrown if the lock could not be obtained. This method may block for a few seconds if a lock cannot be obtained.

  Throws:
    `DirectoryLockException` - thrown if there is an exception obtaining the lock

### obtainLock

    protected void obtainLock(boolean shared,
                              long maxWait)
                       throws DirectoryLockException

  Attempts to obtain a lock; an exception is thrown if the lock could not be obtained. This method may block for a few seconds if a lock cannot be obtained.

  Parameters:
    `shared` - true if the lock is shared, otherwise false
    `maxWait` - the maximum time to wait, in seconds, while trying to obtain the lock
  Throws:
    `DirectoryLockException` - thrown if there is an exception obtaining the lock

### obtainLock

    protected void obtainLock(boolean shared)
                       throws DirectoryLockException

  Attempts to obtain a lock; an exception is thrown if the lock could not be obtained. This method may block for a few seconds if a lock cannot be obtained.

  Parameters:
    `shared` - true if the lock is shared, otherwise false
  Throws:
    `DirectoryLockException` - thrown if there is an exception obtaining the lock

### close

    public void close()
               throws IOException

  Releases any locks and closes the underlying channel.

  Specified by:
    `close` in interface `Closeable`
  Throws:
    `IOException` - if an IO Exception occurs

### release

    public void release()

  Releases the lock. Any exceptions that are thrown by the underlying lock during the release are ignored.

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

Copyright © 2012-2013 OWASP. All Rights Reserved.