gpt4 book ai didi

com.ngdata.sep.util.zookeeper.ZooKeeperItf类的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 17:13:31 25 4
gpt4 key购买 nike

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

ZooKeeperItf介绍

[英]An interface for ZooKeeper.
[中]ZooKeeper的界面。

代码示例

代码示例来源:origin: NGDATA/hbase-indexer

@Override
  public Object execute() throws KeeperException, InterruptedException {
    byte[] data = zk.getData(indexerPath, false, null);
    String trashPath = indexerTrashPath + "/" + indexerName;
    // An indexer with the same name might have existed before and hence already exist
    // in the indexer trash, handle this by appending a sequence number until a unique
    // name is found.
    String baseTrashpath = trashPath;
    int count = 0;
    while (zk.exists(trashPath, false) != null) {
      count++;
      trashPath = baseTrashpath + "." + count;
    }
    zk.create(trashPath, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    return null;
  }
});

代码示例来源:origin: NGDATA/hbase-indexer

try {
  if (zk.exists(indexerLockPath, false) != null) {
    List<String> children = Collections.emptyList();
    try {
      children = zk.getChildren(indexerLockPath, false);
    } catch (KeeperException.NoNodeException e) {
        zk.delete(indexerLockPath + "/" + child, -1);
      } catch (KeeperException.NoNodeException e) {
      zk.delete(indexerLockPath, -1);
    } catch (KeeperException.NoNodeException e) {
  zk.delete(indexerPath, -1);

代码示例来源:origin: NGDATA/hbase-indexer

/**
 * Updates data on a zookeeper node.
 * 
 * <p>
 * The supplied data is used for the last node in the path. The path must
 * already exist. It is not checked if the data is changed or not. This will
 * cause the version of the node to be increased.
 * <p>
 * This operation is retried until it succeeds.
 */
public static void update(final ZooKeeperItf zk, final String path, final byte[] data, final int version)
    throws InterruptedException, KeeperException {
  zk.retryOperation(new ZooKeeperOperation<Boolean>() {
    @Override
    public Boolean execute() throws KeeperException, InterruptedException {
      zk.setData(path, data, version);
      return null;
    }
  });
}

代码示例来源:origin: NGDATA/hbase-indexer

@Override
  public Boolean execute() throws KeeperException, InterruptedException {
    byte[] currentData = zk.getData(path, false, new Stat());
    if (!Arrays.equals(currentData, data)) {
      zk.setData(path, data, -1);
    }
    return null;
  }
});

代码示例来源:origin: NGDATA/hbase-indexer

@Override
  public Boolean execute() throws KeeperException, InterruptedException {
    if (zk.exists(subPath.toString(), false) == null) {
      try {
        zk.create(subPath.toString(), newData, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        return true;
      } catch (KeeperException.NodeExistsException e) {
        return false;
      }
    }
    return false;
  }
});

代码示例来源:origin: com.ngdata/hbase-sep-tools

if (zk.exists(regionServerPath, false) == null) {
  return new ReplicationStatus(statusByPeerAndServer);
List<String> regionServers = zk.getChildren(regionServerPath, false);
    peers = zk.getChildren(peersPath, false);
  } catch (KeeperException.NoNodeException e) {
      logs.addAll(zk.getChildren(hlogsPath, false));
    } catch (KeeperException.NoNodeException e) {
        byte[] data = zk.getData(hlogsPath + "/" + log, false, stat);

代码示例来源:origin: NGDATA/hbase-indexer

@Override
  public Stat execute() throws KeeperException, InterruptedException {
    return zk.exists(childPath, false);
  }
});

代码示例来源:origin: NGDATA/hbase-indexer

List<String> children = zk.getChildren(electionPath, watcher);
Stat stat = zk.exists(electionPath + "/" + leader, false);
if (stat.getEphemeralOwner() == zk.getSessionId() && !elected) {
  elected = true;
  log.info("Elected as leader for the position of " + position);

代码示例来源:origin: com.ngdata/hbase-sep-impl-common

@Override
  public Boolean execute() throws KeeperException, InterruptedException {
    Stat stat = zk.exists(path, false);
    if (stat != null) {
      try {
        zk.delete(path, stat.getVersion());
      } catch (KeeperException.NoNodeException nne) {
        // This is ok, the node is already gone
      }
      // We don't catch BadVersion or NotEmpty as these are probably signs that there is something
      // unexpected going on with the node that is to be deleted
    }
    return true;
  }
});

代码示例来源:origin: NGDATA/hbase-indexer

@Override
  public String execute() throws KeeperException, InterruptedException {
    return zk.create(electionPath + "/n_", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
  }
});

代码示例来源:origin: NGDATA/hbase-indexer

@Override
    public List<IndexerProcess> execute() throws KeeperException, InterruptedException {
      List<IndexerProcess> indexerProcesses = Lists.newArrayList();
      for (String childNode : zk.getChildren(zkBaseNode, false)) {
        List<String> nodeNameParts = Lists.newArrayList(Splitter.on(',').split(childNode));
        if (indexerName.equals(nodeNameParts.get(0))) {
          byte[] errorBytes = zk.getData(zkBaseNode + "/" + childNode, false, null);
          IndexerProcess indexerProcess = new IndexerProcess(indexerName,
              nodeNameParts.get(1),
              errorBytes == null  || errorBytes.length == 0? null : Bytes.toString(errorBytes));
          indexerProcesses.add(indexerProcess);
        }
      }
      return indexerProcesses;
      
    }});
} catch (Exception e) {

代码示例来源:origin: NGDATA/hbase-indexer

private IndexerDefinition loadIndexer(String indexerName, boolean forCache)
    throws InterruptedException, KeeperException, IndexerNotFoundException {
  final String childPath = indexerCollectionPath + "/" + indexerName;
  final Stat stat = new Stat();
  byte[] data;
  try {
    if (forCache) {
      // do not retry, install watcher
      data = zk.getData(childPath, watcher, stat);
    } else {
      // do retry, do not install watcher
      data = zk.retryOperation(new ZooKeeperOperation<byte[]>() {
        @Override
        public byte[] execute() throws KeeperException, InterruptedException {
          return zk.getData(childPath, false, stat);
        }
      });
    }
  } catch (KeeperException.NoNodeException e) {
    throw new IndexerNotFoundException(indexerName);
  }
  IndexerDefinitionBuilder builder = IndexerDefinitionJsonSerDeser.INSTANCE.fromJsonBytes(data);
  builder.name(indexerName);
  builder.occVersion(stat.getVersion());
  return builder.build();
}

代码示例来源:origin: NGDATA/hbase-indexer

/**
 * 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/hbase-indexer

@Override
  public Object execute() throws KeeperException, InterruptedException {
    try {
      zk.delete(childPath, -1);
    } catch (KeeperException.NoNodeException e) {
      // ignore
    }
    return null;
  }
});

代码示例来源:origin: com.ngdata/hbase-indexer-common

@Override
  public List<String> execute() throws KeeperException, InterruptedException {
    return zk.getChildren(lockPath, null);
  }
}));

代码示例来源:origin: NGDATA/hbase-indexer

@Override
  public byte[] execute() throws KeeperException, InterruptedException {
    return zk.getData(childPath, false, stat);
  }
});

代码示例来源:origin: NGDATA/hbase-indexer

@Override
  public Boolean execute() throws KeeperException, InterruptedException {
    zk.setData(path, data, version);
    return null;
  }
});

代码示例来源:origin: NGDATA/hbase-indexer

@PreDestroy
public void stop() throws InterruptedException {
  stopped = true;
  zk.removeDefaultWatcher(connectStateWatcher);
  indexerCacheRefresher.shutdown();
}

代码示例来源:origin: NGDATA/hbase-indexer

/**
 *
 * @param position a name for what position this leader election is about, used in informational messages.
 * @param electionPath path under which the ephemeral leader election nodes should be created. The path
 *                     will be created if it does not exist. The path should not end on a slash.
 */
public LeaderElection(ZooKeeperItf zk, String position, String electionPath, LeaderElectionCallback callback)
    throws LeaderElectionSetupException, InterruptedException, KeeperException {
  this.zk = zk;
  this.position = position;
  this.electionPath = electionPath;
  this.callback = callback;
  proposeAsLeader();
  zk.addDefaultWatcher(connectStateWatcher);
  leaderProvisioner.start();
}

代码示例来源:origin: NGDATA/hbase-indexer

@Override
  public Stat execute() throws KeeperException, InterruptedException {
    return zk.exists(lockPath, null);
  }
});

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