com.twitter.distributedlog.lock.ZKSessionLock.unlock()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中com.twitter.distributedlog.lock.ZKSessionLock.unlock()方法的一些代码示例,展示了ZKSessionLock.unlock()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKSessionLock.unlock()方法的具体详情如下:
包路径:com.twitter.distributedlog.lock.ZKSessionLock
类名称:ZKSessionLock
方法名:unlock

ZKSessionLock.unlock介绍

[英]NOTE: unlockInternal should only after try lock.
[中]注意:只有在尝试锁定后才能解锁Internal。

代码示例

代码示例来源:origin: twitter/distributedlog

unlock();

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testLockWhenPreviousLockZnodeStillExists() throws Exception {
  String lockPath = "/test-lock-when-previous-lock-znode-still-exists-" +
      System.currentTimeMillis();
  String clientId = "client-id";
  ZooKeeper zk = zkc.get();
  createLockPath(zk, lockPath);
  final ZKSessionLock lock0 = new ZKSessionLock(zkc0, lockPath, clientId, lockStateExecutor);
  // lock0 lock
  lock0.tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
  // simulate lock0 expires but znode still exists
  final DistributedLockContext context1 = new DistributedLockContext();
  context1.addLockId(lock0.getLockId());
  final ZKSessionLock lock1 = new ZKSessionLock(zkc, lockPath, clientId, lockStateExecutor,
      60000, NullStatsLogger.INSTANCE, context1);
  lock1.tryLock(0L, TimeUnit.MILLISECONDS);
  assertEquals(State.CLAIMED, lock1.getLockState());
  lock1.unlock();
  final DistributedLockContext context2 = new DistributedLockContext();
  context2.addLockId(lock0.getLockId());
  final ZKSessionLock lock2 = new ZKSessionLock(zkc, lockPath, clientId, lockStateExecutor,
      60000, NullStatsLogger.INSTANCE, context2);
  lock2.tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
  assertEquals(State.CLAIMED, lock2.getLockState());
  lock2.unlock();
  lock0.unlock();
}

代码示例来源:origin: twitter/distributedlog

lock0.unlock();
} else {
  ZooKeeperClientUtils.expireSession(zkc0, zkServers, sessionTimeoutMs);
assertEquals(lock1.getLockId(), Await.result(asyncParseClientID(zkc.get(), lockPath, children.get(0))));
lock1.unlock();

代码示例来源:origin: twitter/distributedlog

lock.unlock();

代码示例来源:origin: twitter/distributedlog

lock0.unlock();
} else {
  ZooKeeperClientUtils.expireSession(zkc0, zkServers, sessionTimeoutMs);
assertEquals(lock1_1.getLockId(), Await.result(asyncParseClientID(zkc.get(), lockPath, children.get(0))));
lock1_1.unlock();

代码示例来源:origin: twitter/distributedlog

assertEquals(lock0.getLockId(), Await.result(asyncParseClientID(zkc0.get(), lockPath, children.get(0))));
lock0.unlock();
assertEquals(lock2.getLockId(), Await.result(asyncParseClientID(zkc.get(), lockPath, children.get(0))));
lock2.unlock();

代码示例来源:origin: twitter/distributedlog

lock0.unlock();
  assertEquals(State.CLOSED, lock0.getLockState());
  children = getLockWaiters(zkc0, lockPath);
  assertEquals(State.CLAIMED, lock1.getLockState());
  assertEquals(lock1.getLockId(), Await.result(asyncParseClientID(zkc0.get(), lockPath, children.get(0))));
  lock1.unlock();
} else {
  ZooKeeperClientUtils.expireSession(zkc0, zkServers, sessionTimeoutMs);

代码示例来源:origin: twitter/distributedlog

lock.unlock();

代码示例来源:origin: twitter/distributedlog

lock0_0.unlock();
} else {
  ZooKeeperClientUtils.expireSession(zkc0, zkServers, sessionTimeoutMs);
lock1.unlock();

代码示例来源:origin: twitter/distributedlog

/**
 * Test lock after unlock is called.
 *
 * @throws Exception
 */
@Test(timeout = 60000)
public void testLockAfterUnlock() throws Exception {
  String lockPath = "/test-lock-after-unlock";
  String clientId = "test-lock-after-unlock";
  ZKSessionLock lock = new ZKSessionLock(zkc, lockPath, clientId, lockStateExecutor);
  lock.unlock();
  assertEquals(State.CLOSED, lock.getLockState());
  try {
    lock.tryLock(0, TimeUnit.MILLISECONDS);
    fail("Should fail on tryLock since lock state has changed.");
  } catch (LockStateChangedException lsce) {
    // expected
  }
  assertEquals(State.CLOSED, lock.getLockState());
  try {
    lock.tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
    fail("Should fail on tryLock immediately if lock state has changed.");
  } catch (LockStateChangedException lsce) {
    // expected
  }
  assertEquals(State.CLOSED, lock.getLockState());
}

代码示例来源:origin: twitter/distributedlog

/**
 * Test unlock timeout.
 *
 * @throws Exception
 */
@Test(timeout = 60000)
public void testUnlockTimeout() throws Exception {
  String name = testNames.getMethodName();
  String lockPath = "/" + name;
  String clientId = name;
  createLockPath(zkc.get(), lockPath);
  ZKSessionLock lock = new ZKSessionLock(
      zkc, lockPath, clientId, lockStateExecutor,
      1*1000 /* op timeout */, NullStatsLogger.INSTANCE,
      new DistributedLockContext());
  lock.tryLock(0, TimeUnit.MILLISECONDS);
  assertEquals(State.CLAIMED, lock.getLockState());
  try {
    FailpointUtils.setFailpoint(FailpointUtils.FailPointName.FP_LockUnlockCleanup,
                  new DelayFailpointAction(60*60*1000));
    lock.unlock();
    assertEquals(State.CLOSING, lock.getLockState());
  } finally {
    FailpointUtils.removeFailpoint(FailpointUtils.FailPointName.FP_LockUnlockCleanup);
  }
}

相关文章