gpt4 book ai didi

org.lilyproject.util.zookeeper.ZooKeeperItf.isCurrentThreadEventThread()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 19:58:49 26 4
gpt4 key购买 nike

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

ZooKeeperItf.isCurrentThreadEventThread介绍

[英]Returns true if we know for sure the current thread is the ZooKeeper event thread.

This is a Lily-specific method.
[中]如果确定当前线程是ZooKeeper事件线程,则返回true。
这是一种百合特有的方法。

代码示例

代码示例来源:origin: NGDATA/lilyproject

@Override
public boolean isCurrentThreadEventThread() {
  return wrapped.isCurrentThreadEventThread();
}

代码示例来源:origin: NGDATA/lilyproject

/**
 * Verifies that the specified lockId is the owner of the lock.
 */
public static boolean ownsLock(final ZooKeeperItf zk, final String lockId) throws ZkLockException {
  if (zk.isCurrentThreadEventThread()) {
    throw new RuntimeException("ZkLock should not be used from within the ZooKeeper event thread.");
  }
  try {
    int lastSlashPos = lockId.lastIndexOf('/');
    final String lockPath = lockId.substring(0, lastSlashPos);
    String lockName = lockId.substring(lastSlashPos + 1);
    List<String> children = zk.retryOperation(new ZooKeeperOperation<List<String>>() {
      @Override
      public List<String> execute() throws KeeperException, InterruptedException {
        return zk.getChildren(lockPath, null);
      }
    });
    if (children.isEmpty()) {
      return false;
    }
    SortedSet<String> sortedChildren = new TreeSet<String>(children);
    return sortedChildren.first().equals(lockName);
  } catch (Throwable t) {
    throw new ZkLockException("Error checking lock, path: " + lockId, t);
  }
}

代码示例来源:origin: NGDATA/lilyproject

/**
 * Releases a lock.
 *
 * @param lockId the string returned by {@link ZkLock#lock}.
 * @param ignoreMissing if true, do not throw an exception if the lock does not exist
 */
public static void unlock(final ZooKeeperItf zk, final String lockId, boolean ignoreMissing) throws ZkLockException {
  if (zk.isCurrentThreadEventThread()) {
    throw new RuntimeException("ZkLock should not be used from within the ZooKeeper event thread.");
  }
  try {
    zk.retryOperation(new ZooKeeperOperation<Object>() {
      @Override
      public Object execute() throws KeeperException, InterruptedException {
        zk.delete(lockId, -1);
        return null;
      }
    });
  } catch (KeeperException.NoNodeException e) {
    if (!ignoreMissing) {
      throw new ZkLockException("Error releasing lock: the lock does not exist. Path: " + lockId, e);
    }
  } catch (Throwable t) {
    throw new ZkLockException("Error releasing lock, path: " + lockId, t);
  }
}

代码示例来源:origin: NGDATA/lilyproject

if (zk.isCurrentThreadEventThread()) {
  throw new RuntimeException("ZkLock should not be used from within the ZooKeeper event thread.");

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com