Package org.apache.storm.hdfs.spout

# Class DirLock

java.lang.Object
org.apache.storm.hdfs.spout.DirLock

public class DirLock extends Object
Facility to synchronize access to HDFS directory. The lock itself is represented as a file in the same directory. Relies on atomic file creation.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `DIR_LOCK_FILE`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `org.apache.hadoop.fs.Path`
  `getLockFile()`
  `void`
  `release()`
  Release lock on dir by deleting the lock file.
  `static DirLock`
  `takeOwnershipIfStale(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dirToLock, int lockTimeoutSec)`
  if the lock on the directory is stale, take ownership.
  `static DirLock`
  `tryLock(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir)`
  Get a lock on file if not already locked.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### DIR_LOCK_FILE

    public static final String DIR_LOCK_FILE
    See Also:
      - Constant Field Values

- ## Method Details

  - ### tryLock

    public static DirLock tryLock(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir) throws IOException
    Get a lock on file if not already locked.
    Parameters:
      `dir` - the dir on which to get a lock
    Returns:
      The lock object if it the lock was acquired. Returns null if the dir is already locked.
    Throws:
      `IOException` - if there were errors

  - ### takeOwnershipIfStale

    public static DirLock takeOwnershipIfStale(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dirToLock, int lockTimeoutSec)
    if the lock on the directory is stale, take ownership.

  - ### release

    public void release() throws IOException
    Release lock on dir by deleting the lock file.
    Throws:
      `IOException`

  - ### getLockFile

    public org.apache.hadoop.fs.Path getLockFile()