org.apache.ignite.internal.processors.cache

## Class GridCacheExplicitLockSpan<K>

- java.lang.Object
- - java.util.concurrent.locks.ReentrantLock
  - - org.apache.ignite.internal.processors.cache.GridCacheExplicitLockSpan<K>

All Implemented Interfaces:
  Serializable, Lock

    public class GridCacheExplicitLockSpan<K>
    extends ReentrantLock

Collection of near local locks acquired by a thread on one topology version.

See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`GridCacheExplicitLockSpan(GridDiscoveryTopologySnapshot topSnapshot, GridCacheMvccCandidate<K> cand)`

### Method Summary

Methods
`boolean` `addCandidate(GridDiscoveryTopologySnapshot topSnapshot, GridCacheMvccCandidate<K> cand)` Adds candidate to a lock span.
`GridCacheMvccCandidate<K>` `candidate(K key, GridCacheVersion ver)` Gets explicit lock candidate for given key.
`boolean` `isEmpty()`
`void` `markOwned(K key)` Marks all candidates added for given key as owned.
`IgniteInternalFuture<Object>` `releaseFuture()` Gets span release future.
`boolean` `removeCandidate(GridCacheMvccCandidate<K> cand)` Removes candidate from this lock span.
`GridCacheMvccCandidate<K>` `removeCandidate(K key, GridCacheVersion ver)` Removes lock by key and optional version.
`GridDiscoveryTopologySnapshot` `topologySnapshot()` Gets actual topology snapshot for thread lock span.
`String` `toString()`

### Methods inherited from class java.util.concurrent.locks.ReentrantLock

`getHoldCount, getOwner, getQueuedThreads, getQueueLength, getWaitingThreads, getWaitQueueLength, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isHeldByCurrentThread, isLocked, lock, lockInterruptibly, newCondition, tryLock, tryLock, unlock`

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

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

### Constructor Detail

#### GridCacheExplicitLockSpan

    public GridCacheExplicitLockSpan(GridDiscoveryTopologySnapshot topSnapshot,
                             GridCacheMvccCandidate<K> cand)

Parameters:
  `topSnapshot` - Topology snapshot.
  `cand` - Candidate.

### Method Detail

#### addCandidate

    public boolean addCandidate(GridDiscoveryTopologySnapshot topSnapshot,
                       GridCacheMvccCandidate<K> cand)

Adds candidate to a lock span.

Parameters:
  `topSnapshot` - Topology snapshot for which candidate is added.
  `cand` - Candidate to add.
Returns:
  `True` if candidate was added, `false` if this span is empty and new span should be created.

#### removeCandidate

    public boolean removeCandidate(GridCacheMvccCandidate<K> cand)

Removes candidate from this lock span.

Parameters:
  `cand` - Candidate to remove.
Returns:
  `True` if span is empty and should be removed, `false` otherwise.

#### removeCandidate

    public GridCacheMvccCandidate<K> removeCandidate(K key,
                                            @Nullable
                                            GridCacheVersion ver)

Removes lock by key and optional version.

Parameters:
  `key` - Key.
  `ver` - Version (or `null` if any candidate should be removed.)
Returns:
  Removed candidate if matches given parameters.

#### isEmpty

    public boolean isEmpty()

Returns:
  `True` if span is empty and candidates cannot be added anymore.

#### markOwned

    public void markOwned(K key)

Marks all candidates added for given key as owned.

Parameters:
  `key` - Key.

#### candidate

    @Nullable
    public GridCacheMvccCandidate<K> candidate(K key,
                                               @Nullable
                                               GridCacheVersion ver)

Gets explicit lock candidate for given key.

Parameters:
  `key` - Key to lookup.
  `ver` - Version to lookup (if `null` - return any).
Returns:
  Last added explicit lock candidate, if any, or `null`.

#### topologySnapshot

    @Nullable
    public GridDiscoveryTopologySnapshot topologySnapshot()

Gets actual topology snapshot for thread lock span.

Returns:
  Topology snapshot or `null` if candidate list is empty.

#### releaseFuture

    public IgniteInternalFuture<Object> releaseFuture()

Gets span release future. Future is completed when last lock is released.

Returns:
  Release future.

#### toString

    public String toString()

Overrides:
  `toString` in class `ReentrantLock`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015