com.h3c.dist.lock

## Interface Lock

-     public interface Lock

  Enables applications to perform specific operations on a lock. For type of locks refer to Lock types `LockType`

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `LockName` | `getName()` Get LockName `LockName` associated with the Lock.
    `LockState` | `getState()` Get current state `LockState` of the Lock.
    `void` | `lock()` Acquire the lock.
    `boolean` | `tryLock()` Acquires the lock only if it is available at the time of invocation.
    `boolean` | `tryLock(long timeOut, TimeUnit unit)` Acquire lock with a timeout.
    `void` | `unlock()` Release the lock which is previously acquired.

- - ### Method Detail

    - #### lock

          void lock()
                    throws InterruptedException,
                           ServiceNotAvailableException,
                           IOException

      Acquire the lock. If lock is readily available, lock is granted otherwise caller is blocked until the lock is available.
      Throws:
        `InterruptedException` - Thread interrupted exception
        `ServiceNotAvailableException` - Lock service is down currently
        `IOException` - IO exception while data serialization

    - #### tryLock

          boolean tryLock(long timeOut,
                        TimeUnit unit)
                          throws InterruptedException,
                                 ServiceNotAvailableException,
                                 IOException

      Acquire lock with a timeout. If lock is readily available, lock is granted otherwise caller is blocked until the lock is available or the timer expires, which ever is earlier.
      Parameters:
        `timeOut` - Timeout value
        `unit` - Timeout unit
      Returns:
        boolean true if lock acquired, false if timeout
      Throws:
        `InterruptedException` - Thread interrupted exception
        `ServiceNotAvailableException` - Lock service down exception
        `IOException` - IO exception while data serialization

    - #### tryLock

          boolean tryLock()
                          throws ServiceNotAvailableException,
                                 InterruptedException,
                                 IOException

      Acquires the lock only if it is available at the time of invocation.
      Returns:
        true if lock acquired, false otherwise
      Throws:
        `ServiceNotAvailableException` - Lock service is down
        `InterruptedException` - Operation interrupted exception
        `IOException` - IO Exception while data serialization

    - #### unlock

          void unlock()
                      throws LockServiceException.LockNotAquiredException,
                             ServiceNotAvailableException,
                             InterruptedException

      Release the lock which is previously acquired. If a lock which is blocked state is released, the previously blocked caller is woken up with lock released exception.
      Throws:
        `LockServiceException.LockNotAquiredException` - Lock is not in aquired state
        `ServiceNotAvailableException` - Lock service is down
        `InterruptedException` - Operation interrupted exception

    - #### getName

          LockName getName()

      Get LockName `LockName` associated with the Lock.
      Returns:
        LockName Lock information object corresponding to the lock.

    - #### getState

          LockState getState()

      Get current state `LockState` of the Lock.
      Returns:
        LockState

Copyright © 2014. All Rights Reserved.