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

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

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

ZkUtil.createPath介绍

[英]Creates a persistent path on zookeeper if it does not exist yet, including any parents. Keeps retrying in case of connection loss.

The supplied data is used for the last node in the path. If the path already exists, the data is updated if necessary.
[中]在zookeeper上创建一个持久路径(如果它还不存在),包括任何父级。在连接丢失的情况下不断重试。
提供的数据用于路径中的最后一个节点。如果路径已经存在,则在必要时更新数据。

代码示例

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

public static void createPath(final ZooKeeperItf zk, final String path)
    throws InterruptedException, KeeperException {
  createPath(zk, path, null);
}

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

@PostConstruct
public void init() throws KeeperException, InterruptedException {
  ZkUtil.createPath(zk, "/lily/repositoryNodes");
  refresh();
}

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

@Override
  public Void call() throws InterruptedException, KeeperException, RepositoryException {
    for (int j = 0; j < 16; j++) {
      String bucket = "" + DIGITS_LOWER[index] + DIGITS_LOWER[j];
      ZkUtil.createPath(zooKeeper, bucketPath(bucket));
      cacheWatchers.add(new CacheWatcher(bucket));
    }
    return null;
  }
}));

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

@PostConstruct
  public void start() throws IOException, InterruptedException, KeeperException {
    // Publish our address
    ZkUtil.createPath(zk, nodesPath);
    final String repoAddressAndPort = hostAddress + ":" + port;
    zk.retryOperation(new ZooKeeperOperation<Object>() {
      @Override
      public Object execute() throws KeeperException, InterruptedException {
        zk.create(nodesPath + "/" + repoAddressAndPort, null, ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.EPHEMERAL);
        return null;
      }
    });

    // Publish HBase configuration for LilyClient use
    // Translate HBase conf into json
    ObjectNode propertiesNode = JsonNodeFactory.instance.objectNode();
    for (Map.Entry<String, String> propertyEntry : hbaseConf) {
      if (!propertyEntry.getKey().equals(HConstants.HBASE_CLIENT_INSTANCE_ID)) {
        propertiesNode.put(propertyEntry.getKey(), propertyEntry.getValue());
      }
    }
    // TODO we could compare with current state and log a warn if its different
    ZkUtil.createPath(zk, hbaseConfPath, JsonFormat.serializeAsBytes(propertiesNode));
  }
}

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

public void start() throws InterruptedException, KeeperException, RepositoryException {
  cacheRefresher.start();
  ZkUtil.createPath(zooKeeper, CACHE_INVALIDATION_PATH);
  final ExecutorService threadPool = Executors.newFixedThreadPool(50);
  final List<Future> futures = new ArrayList<Future>();
  ZkUtil.createPath(zooKeeper, CACHE_REFRESHENABLED_PATH);
  connectionWatcher = new ConnectionWatcher();
  zooKeeper.addDefaultWatcher(connectionWatcher);

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

private void proposeAsLeader() throws LeaderElectionSetupException, InterruptedException, KeeperException {
  ZkUtil.createPath(zk, electionPath);
  try {
    // In case of connection loss, a node might have been created for us (we do not know it). Therefore,
    // retrying upon connection loss is important, so that we can continue with watching the leaders.
    // Later on, we do not look at the name of the node we created here, but at the owner.
    zk.retryOperation(new ZooKeeperOperation<String>() {
      @Override
      public String execute() throws KeeperException, InterruptedException {
        return zk.create(electionPath + "/n_", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
      }
    });
  } catch (KeeperException e) {
    throw new LeaderElectionSetupException("Error creating leader election zookeeper node below " +
        electionPath, e);
  }
  watchLeaders();
}

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

public void init() throws KeeperException, InterruptedException {
  ZkUtil.createPath(zk, REPOSITORY_COLLECTION_PATH);
  assureDefaultRepositoryExists();
  zkWatcher = new RepositoryZkWatcher();
  zk.addDefaultWatcher(zkWatcher);
  refresh();
}

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

private Server createServer() throws Exception {
  if (this.useSolrCloud) {
    // create path on zookeeper for solr cloud
    ZooKeeperItf zk = ZkUtil.connect("localhost:2181", 10000);
    ZkUtil.createPath(zk, "/solr");
    zk.close();
  }
  Server server = new Server(solrPort);
  WebAppContext ctx = new WebAppContext(solrWarPath, "/solr");
  // The reason to change the classloading behavior was primarily so that the logging libraries would
  // be inherited, and hence that Solr would use the same logging system & conf.
  ctx.setParentLoaderPriority(true);
  server.addHandler(ctx);
  return server;
}

相关文章

微信公众号

最新文章

更多