Search in sources :

Example 1 with ZKSessionLockFactory

use of com.twitter.distributedlog.lock.ZKSessionLockFactory in project distributedlog by twitter.

the class TestBKLogSegmentWriter method createLock.

private ZKDistributedLock createLock(String path, ZooKeeperClient zkClient, boolean acquireLock) throws Exception {
    try {
        Await.result(Utils.zkAsyncCreateFullPathOptimistic(zkClient, path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
    } catch (KeeperException.NodeExistsException nee) {
    // node already exists
    }
    SessionLockFactory lockFactory = new ZKSessionLockFactory(zkClient, "test-lock", lockStateExecutor, 0, Long.MAX_VALUE, conf.getZKSessionTimeoutMilliseconds(), NullStatsLogger.INSTANCE);
    ZKDistributedLock lock = new ZKDistributedLock(lockStateExecutor, lockFactory, path, Long.MAX_VALUE, NullStatsLogger.INSTANCE);
    if (acquireLock) {
        return FutureUtils.result(lock.asyncAcquire());
    } else {
        return lock;
    }
}
Also used : ZKSessionLockFactory(com.twitter.distributedlog.lock.ZKSessionLockFactory) SessionLockFactory(com.twitter.distributedlog.lock.SessionLockFactory) ZKSessionLockFactory(com.twitter.distributedlog.lock.ZKSessionLockFactory) KeeperException(org.apache.zookeeper.KeeperException) ZKDistributedLock(com.twitter.distributedlog.lock.ZKDistributedLock)

Aggregations

SessionLockFactory (com.twitter.distributedlog.lock.SessionLockFactory)1 ZKDistributedLock (com.twitter.distributedlog.lock.ZKDistributedLock)1 ZKSessionLockFactory (com.twitter.distributedlog.lock.ZKSessionLockFactory)1 KeeperException (org.apache.zookeeper.KeeperException)1