org.jgroups.protocols

## Class PEER_LOCK

- java.lang.Object
- - org.jgroups.stack.Protocol
  - - org.jgroups.protocols.Locking
    - - org.jgroups.protocols.PEER_LOCK

    public class PEER_LOCK
    extends Locking

Implementation of a locking protocol which acquires locks by contacting all of the nodes of a cluster. Unless a total order configuration is used (e.g. `SEQUENCER` based), lock requests for the same resource from different senders may be received in different order, so deadlocks can occur. Example:

     - Nodes A and B
     - A and B call lock(X) at the same time
     - A receives L(X,A) followed by L(X,B): locks X(A), queues L(X,B)
     - B receives L(X,B) followed by L(X,A): locks X(B), queues L(X,A)

To acquire a lock, we need lock grants from both A and B, but this will never happen here. To fix this, either add SEQUENCER to the configuration, so that all lock requests are received in the same global order at both A and B, or use `Lock.tryLock(long,java.util.concurrent.TimeUnit)` with retries if a lock cannot be acquired.

An alternative is also the `CENTRAL_LOCK` protocol.

Since:
  2.12
Author:
  Bela Ban
See Also:
  `Locking`, `CENTRAL_LOCK`

### Nested Class Summary

Nested Classes
`protected class` `PEER_LOCK.PeerLock` Lock implementation which grants a lock when all non faulty cluster members OK it.

### Nested classes/interfaces inherited from class org.jgroups.protocols.Locking

`Locking.ClientCondition, Locking.ClientLock, Locking.LockingHeader, Locking.Request, Locking.ServerCondition, Locking.ServerLock, Locking.Type`

### Field Summary

### Fields inherited from class org.jgroups.protocols.Locking

`bypass_bundling, client_locks, local_addr, lock_listeners, server_locks, view`

### Fields inherited from class org.jgroups.stack.Protocol

`down_prot, ergonomics, id, log, name, stack, stats, up_prot`

### Constructor Summary

Constructors
Constructor and Description
`PEER_LOCK()`

### Method Summary

Methods
`protected Locking.ClientLock` `createLock(java.lang.String lock_name)`
`void` `handleView(View view)`
`protected void` `sendAwaitConditionRequest(java.lang.String lock_name, Owner owner)`
`protected void` `sendDeleteAwaitConditionRequest(java.lang.String lock_name, Owner owner)`
`protected void` `sendGrantLockRequest(java.lang.String lock_name, Owner owner, long timeout, boolean is_trylock)`
`protected void` `sendReleaseLockRequest(java.lang.String lock_name, Owner owner)`
`protected void` `sendSignalConditionRequest(java.lang.String lock_name, boolean all)`

### Methods inherited from class org.jgroups.protocols.Locking

`addLockListener, down, getAddress, getBypassBundling, getLock, getLock, getLock, getOwner, getView, handleAwaitRequest, handleCreateAwaitingRequest, handleCreateLockRequest, handleDeleteAwaitingRequest, handleDeleteAwaitRequest, handleDeleteLockRequest, handleLockDeniedResponse, handleLockGrantedResponse, handleLockRequest, handleSignalRequest, handleSignalResponse, notifyAwaited, notifyAwaiting, notifyLockCreated, notifyLockDeleted, notifyLocked, notifyUnlocked, printLocks, removeClientLock, removeLockListener, sendLockResponse, sendRequest, sendSignalResponse, setBypassBundling, unlockAll, up`

### Methods inherited from class org.jgroups.stack.Protocol

`destroy, downThreadEnabled, dumpStats, enableStats, getConfigurableObjects, getDownProtocol, getId, getLevel, getName, getProperties, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getValue, init, isErgonomics, printStats, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStats, setDownProtocol, setErgonomics, setId, setLevel, setProperties, setPropertiesInternal, setProperty, setProtocolStack, setSocketFactory, setUpProtocol, setValue, setValues, start, statsEnabled, stop, upThreadEnabled`

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

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

### Constructor Detail

#### PEER_LOCK

    public PEER_LOCK()

### Method Detail

#### sendGrantLockRequest

    protected void sendGrantLockRequest(java.lang.String lock_name,
                            Owner owner,
                            long timeout,
                            boolean is_trylock)

Specified by:
  `sendGrantLockRequest` in class `Locking`

#### sendReleaseLockRequest

    protected void sendReleaseLockRequest(java.lang.String lock_name,
                              Owner owner)

Specified by:
  `sendReleaseLockRequest` in class `Locking`

#### sendAwaitConditionRequest

    protected void sendAwaitConditionRequest(java.lang.String lock_name,
                                 Owner owner)

Specified by:
  `sendAwaitConditionRequest` in class `Locking`

#### sendSignalConditionRequest

    protected void sendSignalConditionRequest(java.lang.String lock_name,
                                  boolean all)

Specified by:
  `sendSignalConditionRequest` in class `Locking`

#### sendDeleteAwaitConditionRequest

    protected void sendDeleteAwaitConditionRequest(java.lang.String lock_name,
                                       Owner owner)

Specified by:
  `sendDeleteAwaitConditionRequest` in class `Locking`

#### handleView

    public void handleView(View view)

Overrides:
  `handleView` in class `Locking`

#### createLock

    protected Locking.ClientLock createLock(java.lang.String lock_name)

Overrides:
  `createLock` in class `Locking`