Search in sources :

Example 1 with ZKSessionLockFactory

use of org.apache.distributedlog.lock.ZKSessionLockFactory in project bookkeeper by apache.

the class TestBKLogSegmentWriter method createLock.

private ZKDistributedLock createLock(String path, ZooKeeperClient zkClient, boolean acquireLock) throws Exception {
    try {
        Utils.ioResult(Utils.zkAsyncCreateFullPathOptimistic(zkClient, path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
    } catch (ZKException zke) {
    // 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 Utils.ioResult(lock.asyncAcquire());
    } else {
        return lock;
    }
}
Also used : ZKSessionLockFactory(org.apache.distributedlog.lock.ZKSessionLockFactory) ZKException(org.apache.distributedlog.exceptions.ZKException) ZKSessionLockFactory(org.apache.distributedlog.lock.ZKSessionLockFactory) SessionLockFactory(org.apache.distributedlog.lock.SessionLockFactory) ZKDistributedLock(org.apache.distributedlog.lock.ZKDistributedLock)

Aggregations

ZKException (org.apache.distributedlog.exceptions.ZKException)1 SessionLockFactory (org.apache.distributedlog.lock.SessionLockFactory)1 ZKDistributedLock (org.apache.distributedlog.lock.ZKDistributedLock)1 ZKSessionLockFactory (org.apache.distributedlog.lock.ZKSessionLockFactory)1