当前位置: 首页>>代码示例>>Java>>正文


Java PersistentNode.waitForInitialCreate方法代码示例

本文整理汇总了Java中org.apache.curator.framework.recipes.nodes.PersistentNode.waitForInitialCreate方法的典型用法代码示例。如果您正苦于以下问题:Java PersistentNode.waitForInitialCreate方法的具体用法?Java PersistentNode.waitForInitialCreate怎么用?Java PersistentNode.waitForInitialCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.curator.framework.recipes.nodes.PersistentNode的用法示例。


在下文中一共展示了PersistentNode.waitForInitialCreate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registry

import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入方法依赖的package包/类
@Override
public void registry(RegistryConfig registryConfig) {
    registryConfig.setRegistry(registry);
    try {
        String nodeName = registryConfig.getServerInfo().toString();
        Map<String, PersistentNode> appKeyServers = nodeNames.computeIfAbsent(registryConfig.getAppKey(), (key) -> new ConcurrentHashMap<>());
        if (appKeyServers.get(nodeName) != null) {
            log.error("server registry exists: " + nodeName);
            throw new TRpcRegistryException("server registry exists for key:" + nodeName);
        }
        String nodeValue = registryConfig.toJsonString();
        PersistentNode node = new PersistentNode(client, CreateMode.EPHEMERAL, true, ZkConstant.SERVICES_DIR + registryConfig.getAppKey() + "/" + nodeName, nodeValue.getBytes());
        node.start();
        node.waitForInitialCreate(3, TimeUnit.SECONDS);
        appKeyServers.put(nodeName, node);
        String actualPath = node.getActualPath();
        log.info("registry to zookeeper, node: " + actualPath + " value: " + nodeValue);
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            log.error("registry error", e);
        }
    }
}
 
开发者ID:sofn,项目名称:trpc,代码行数:26,代码来源:ZkRegistry.java

示例2: advertise

import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入方法依赖的package包/类
void advertise(
    Closer closer,
    InetSocketAddress endpoint,
    Map<String, InetSocketAddress> additionalEndpoints)
    throws AdvertiseException, InterruptedException {

  byte[] nodeData = serializeAdvertisement(endpoint, additionalEndpoints);
  PersistentNode persistentNode =
      new PersistentNode(
          client,
          CreateMode.EPHEMERAL_SEQUENTIAL,

          // TODO(John Sirois): Enable GUID protection once clients are updated to support
          // its effects on group member node naming.  We get nodes like:
          //   4f5f98c4-8e71-41e3-8c8d-1c9a1f5f5df9-member_000000001
          // Clients expect member_ is the prefix and are not prepared for the GUID.
          false /* GUID protection */,

          ZKPaths.makePath(groupPath, memberToken),
          nodeData);
  persistentNode.start();
  closer.register(persistentNode);

  // NB: This blocks on initial server set node population to emulate legacy
  // SingletonService.LeaderControl.advertise (Group.join) behavior. Asynchronous
  // population is an option though, we simply need to remove this wait.
  if (!persistentNode.waitForInitialCreate(Long.MAX_VALUE, TimeUnit.DAYS)) {
    throw new AdvertiseException("Timed out waiting for leader advertisement.");
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:31,代码来源:CuratorSingletonService.java

示例3: doStart

import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入方法依赖的package包/类
protected void doStart() throws Exception {

        int i = startingId;

        while (this.id == -1) {

            String lockPath = ZKPaths.makePath(locksBasePath, String.valueOf(i));
            String memberPath = ZKPaths.makePath(membersBasePath, String.valueOf(i));

            log.trace("Acquiring mutex for member {} via lock path {}", i, lockPath);

            InterProcessMutex mutex = new InterProcessMutex(this.client, lockPath);
            mutex.acquire();

            log.debug("Acquired mutex for member {} via lock path {}", i, lockPath);

            try {

                Stat stat = client.checkExists().creatingParentContainersIfNeeded().forPath(memberPath);

                if (stat == null) {

                    log.debug("Claiming container id {} via member path {}", i, memberPath);

                    try {
                        //no peer has this node yet, grab it:
                        pen = new PersistentNode(client, CreateMode.EPHEMERAL, false, memberPath, payload);
                        pen.start();
                        pen.waitForInitialCreate(30000, TimeUnit.SECONDS);
                        this.id = i;
                        log.info("Claimed container id {} via member path {}", i, memberPath);
                        return;
                    } catch (InterruptedException e) {
                        CloseableUtils.closeQuietly(pen);
                        ThreadUtils.checkInterrupted(e);
                        Throwables.propagate(e);
                    }
                }

            } finally {
                mutex.release();
                log.debug("Released mutex for member {} via lock path {}", i, lockPath);
            }

            i++;
        }
    }
 
开发者ID:stormpath,项目名称:samza-spring-boot-starter,代码行数:48,代码来源:SequentialGroupMember.java


注:本文中的org.apache.curator.framework.recipes.nodes.PersistentNode.waitForInitialCreate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。