com.thinkaurelius.titan.diskstorage.locking

## Class LocalLockMediator<T>

- java.lang.Object
- - com.thinkaurelius.titan.diskstorage.locking.LocalLockMediator<T>

-     public class LocalLockMediator<T>
      extends Object

  This class resolves lock contention between two transactions on the same JVM.

  This is not just an optimization to reduce network traffic. Locks written by Titan to a distributed key-value store contain an identifier, the "Rid", which is unique only to the process level. The Rid can't tell which transaction in a process holds any given lock. This class prevents two transactions in a single process from concurrently writing the same lock to a distributed key-value store.
  Author:
    Dan LaRocque

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `LocalLockMediator(String name, TimestampProvider times)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `lock(KeyColumn kc, T requestor, Timepoint expires)` Acquire the lock specified by `kc`.
    `String` | `toString()`
    `boolean` | `unlock(KeyColumn kc, T requestor)` Release the lock specified by `kc` and which was previously locked by `requestor`, if it is possible to release it.

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

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

- - ### Constructor Detail

    - #### LocalLockMediator

          public LocalLockMediator(String name,
                           TimestampProvider times)

  - ### Method Detail

    - #### lock

          public boolean lock(KeyColumn kc,
                     T requestor,
                     Timepoint expires)

      Acquire the lock specified by `kc`.

      For any particular key-column, whatever value of `requestor` is passed to this method must also be passed to the associated later call to `#unlock(KeyColumn, ExpectedValueCheckingTransaction)`.

      If some requestor `r` calls this method on a KeyColumn `k` and this method returns true, then subsequent calls to this method by `r` on `l` merely attempt to update the `expiresAt` timestamp. This differs from typical lock reentrance: multiple successful calls to this method do not require an equal number of calls to `#unlock()`. One `#unlock()` call is enough, no matter how many times a `requestor` called `lock` beforehand. Note that updating the timestamp may fail, in which case the lock is considered to have expired and the calling context should assume it no longer holds the lock specified by `kc`.

      The number of nanoseconds elapsed since the UNIX Epoch is not readily available within the JVM. When reckoning expiration times, this method uses the approximation implemented by `com.thinkaurelius.titan.diskstorage.util.NanoTime#getApproxNSSinceEpoch(false)`.

      The current implementation of this method returns true when given an `expiresAt` argument in the past. Future implementations may return false instead.
      Parameters:
        `kc` - lock identifier
        `requestor` - the object locking `kc`
        `expires` - instant at which this lock will automatically expire
      Returns:
        true if the lock is acquired, false if it was not acquired

    - #### unlock

          public boolean unlock(KeyColumn kc,
                       T requestor)

      Release the lock specified by `kc` and which was previously locked by `requestor`, if it is possible to release it.
      Parameters:
        `kc` - lock identifier
        `requestor` - the object which previously locked `kc`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2012–2014. All rights reserved.