SMILA 1.0 API documentation

org.eclipse.smila.zookeeper
Class ZkLock

java.lang.Object
  extended by org.eclipse.smila.zookeeper.ZkLock

public class ZkLock
extends java.lang.Object

Zookeeper Lock implementation. Assumes that this is called during a running zookeeper session.

Author:
aweber

Constructor Summary
ZkLock(ZkConnection zk, java.lang.String lockRootNodePath)
           
 
Method Summary
 boolean isLockStillValid()
          Can be called by a client to find out if the acquired lock is still valid.
 boolean tryLock()
          Acquires the lock only if it is free at the time of invocation.
 void unlock()
          Releases the lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZkLock

public ZkLock(ZkConnection zk,
              java.lang.String lockRootNodePath)
Parameters:
zk - zookeeper connection
lockRootNodePath - zookeeper node where to set the lock
Method Detail

tryLock

public boolean tryLock()
Acquires the lock only if it is free at the time of invocation. Assumes that this is called during a running zookeeper session.

Returns:
'true' if the lock could be successfully acquired. If the lock is not available then this method will return immediately with the value 'false'.

unlock

public void unlock()
Releases the lock. Assumes that this is called during a running zookeeper session.


isLockStillValid

public boolean isLockStillValid()
Can be called by a client to find out if the acquired lock is still valid. Could be called at the last possible moment where client could do a rollback of its operations done after acquiring the lock.


SMILA 1.0 API documentation