• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PersistentNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



PersistentNode类属于org.apache.curator.framework.recipes.nodes包,在下文中一共展示了PersistentNode类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: modify

import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入依赖的package包/类
@Override
public void modify(RegistryConfig registryConfig) {
    registryConfig.setRegistry(registry);
    try {
        String nodeName = registryConfig.getServerInfo().toString();
        Map<String, PersistentNode> appKeyServers = nodeNames.computeIfAbsent(registryConfig.getAppKey(), (key) -> new ConcurrentHashMap<>());
        PersistentNode node = appKeyServers.get(nodeName);
        if (node == null) {
            log.warn("server registry not exists " + nodeName + " try to registry");
            registry(registryConfig);
            return;
        }
        String nodeValue = registryConfig.toJsonString();
        node.setData(nodeValue.getBytes());
        String actualPath = node.getActualPath();
        log.info("zookeeper modify, node: " + actualPath + " value: " + nodeValue);
    } catch (Exception e) {
        log.error("modify error", e);
    }
}
 
开发者ID:sofn,项目名称:trpc,代码行数:21,代码来源:ZkRegistry.java


示例3: unRegistry

import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入依赖的package包/类
@Override
public boolean unRegistry(String appKey, ThriftServerInfo serverInfo) {
    try {
        Map<String, PersistentNode> appKeyServers = nodeNames.computeIfAbsent(appKey, (key) -> new ConcurrentHashMap<>());
        PersistentNode node = appKeyServers.get(serverInfo.toString());
        if (node != null) {
            log.info("unRegistry " + serverInfo + " actualPath: " + node.getActualPath());
            node.close();
            appKeyServers.remove(serverInfo.toString());
            return true;
        } else {
            log.warn("unRegistry " + serverInfo + " node not found");
        }
    } catch (Exception e) {
        log.error("unRegistry error, serverInfo: " + serverInfo, e);
    }
    return false;
}
 
开发者ID:sofn,项目名称:trpc,代码行数:19,代码来源:ZkRegistry.java


示例4: 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


示例5: registerHost

import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入依赖的package包/类
/**
 * Register Host to cluster.
 *
 * @param host Host to be part of cluster.
 */
@Override
@Synchronized
public void registerHost(Host host) {
    Preconditions.checkNotNull(host, "host");
    Exceptions.checkArgument(!entryMap.containsKey(host), "host", "host is already registered to cluster.");

    String hostPath = ZKPaths.makePath(getPathPrefix(), host.toString());
    PersistentNode node = new PersistentNode(client, CreateMode.EPHEMERAL, false, hostPath,
            SerializationUtils.serialize(host));

    node.start(); //start creation of ephemeral node in background.
    entryMap.put(host, node);
}
 
开发者ID:pravega,项目名称:pravega,代码行数:19,代码来源:ClusterZKImpl.java


示例6: deregisterHost

import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入依赖的package包/类
/**
 * Remove Host from cluster.
 *
 * @param host Host to be removed from cluster.
 */
@Override
@Synchronized
public void deregisterHost(Host host) {
    Preconditions.checkNotNull(host, "host");
    PersistentNode node = entryMap.get(host);
    Preconditions.checkNotNull(node, "Host is not present in cluster.");
    entryMap.remove(host);
    close(node);
}
 
开发者ID:pravega,项目名称:pravega,代码行数:15,代码来源:ClusterZKImpl.java


示例7: doStart

import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
	
	CuratorFramework client = zkClient.get();
	
	if(client.checkExists().forPath(serverPath) != null){ 
		
		byte []data = client.getData().forPath(serverPath);
		throw new IllegalStateException("server already exist:" + new String(data));
	}

	persistentNode = new PersistentNode(zkClient.get(), CreateMode.EPHEMERAL, false, serverPath, Codec.DEFAULT.encodeAsBytes(getClusterInfo()));
	persistentNode.start();
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:15,代码来源:DefaultCurrentClusterServer.java


示例8: 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


示例9: testNode

import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入依赖的package包/类
@Test
public void testNode() throws IOException{
	
	String path = "/" + getTestName();
	PersistentNode persistentNode = new PersistentNode(client, CreateMode.EPHEMERAL, false, path, "123456".getBytes());
	persistentNode.start();
	
	waitForAnyKeyToExit();
	
	persistentNode.close();
	
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:13,代码来源:PersistentNodeTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TokenHandler类代码示例发布时间:2022-05-22
下一篇:
Java Address类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap