public class

ZKHelixLock

extends Object
implements HelixLock
java.lang.Object
   ↳ org.apache.helix.lock.zk.ZKHelixLock

Class Overview

Locking scheme for Helix that uses the ZooKeeper exclusive lock implementation Please use the following lock order convention: Cluster, Participant, Resource, Partition WARNING: this is not a reentrant lock

Summary

Public Constructors
ZKHelixLock(ClusterId clusterId, Scope<?> scope, ZkClient zkClient)
Initialize for a cluster and scope
Public Methods
boolean isBlocked()
Check if this object is blocked waiting on the lock
synchronized boolean lock()
Try to synchronously lock the scope
synchronized boolean unlock()
Unlock the scope
Protected Methods
void setBlocked(boolean isBlocked)
Set if this the lock method is currently blocked
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.helix.lock.HelixLock

Public Constructors

public ZKHelixLock (ClusterId clusterId, Scope<?> scope, ZkClient zkClient)

Initialize for a cluster and scope

Parameters
clusterId the cluster under which the lock will live
scope the scope to lock
zkClient an active ZK client

Public Methods

public boolean isBlocked ()

Check if this object is blocked waiting on the lock

Returns
  • true if blocked, false otherwise

public synchronized boolean lock ()

Try to synchronously lock the scope

Returns
  • true if the lock succeeded, false if it failed, as is the case if the connection to ZK is lost

public synchronized boolean unlock ()

Unlock the scope

Returns
  • true if unlock executed, false otherwise

Protected Methods

protected void setBlocked (boolean isBlocked)

Set if this the lock method is currently blocked

Parameters
isBlocked true if blocked, false otherwise