gpt4 book ai didi

info.xiancloud.zookeeper.ZkConnection类的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 08:11:31 27 4
gpt4 key购买 nike

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

ZkConnection介绍

[英]单例; 将启动项设置为xian-core内的标准化抽象类,然后由zk插件实现该抽象类;不仅可以解决顺序问题,而且可以解决zk的侵入性
[中]单例; 将启动项设置为西安核心内的标准化抽象类,然后由zk插件实现该抽象类;不仅可以解决顺序问题,而且可以解决zk的侵入性

代码示例

代码示例来源:origin: xiancloud/xian

@Override
  public void destroy() {
    close();
  }
}

代码示例来源:origin: xiancloud/xian

public static void start() {
  start(getZkConnStr());
}

代码示例来源:origin: xiancloud/xian

@Test
  public void setDataWithVersionTest() throws Exception {
    ZkConnection.start();
    try {
      /*ZkConnection.client.create().creatingParentsIfNeeded().forPath("/YY/11");*/
      ZkConnection.client.setData().withVersion(-1).forPath("/YY/11", "ss".getBytes());
    } finally {
      ZkConnection.close();
    }
  }
}

代码示例来源:origin: xiancloud/xian

@Override
public void init() {
  start();
}

代码示例来源:origin: xiancloud/xian

@Override
public Properties getAll(String pluginName) {
  Properties properties = new Properties();
  if (!ZkConnection.isConnected()) {
    return properties;
  }
  for (ChildData childData : resCaches.getUnchecked(pluginName).getCurrentData()) {
    properties.put(childData.getPath().substring(childData.getPath().lastIndexOf("/") + 1), new String(childData.getData()));
  }
  return properties;
}

代码示例来源:origin: xiancloud/xian

@Override
public void execute(UnitRequest msg, Handler<UnitResponse> handler) throws Exception {
  /**
   * 请设置此变量来删除指定路径下的脏节点
   */
  final String PATH = msg.get("basePath", "/xian_runtime_dev/unit");
  try {
    ZkConnection.start();
    for (String s : ZkConnection.client.getChildren().forPath(PATH)) {
      String fullPath = PATH.concat("/").concat(s);
      String data = new String(ZkConnection.client.getData().forPath(fullPath));
      System.out.println(data);
      if (StringUtil.isEmpty(data)) {
        LOG.debug("实现原理是xian服务注册会在unit和group节点data上写入其定义数据,如果没有定义数据的,那么一定是脏节点");
        ZkConnection.client.delete().forPath(fullPath);
      }
    }
  } finally {
    ZkConnection.close();
  }
  handler.handle(UnitResponse.createSuccess());
}

代码示例来源:origin: xiancloud/xian

@Override
public String get(String pluginName, String key) {
  if (!ZkConnection.isConnected()) {
    return null;
  }
  ChildData childData = resCaches.getUnchecked(pluginName).getCurrentData(fullPath(pluginName + "/" + key));
  if (childData == null) return null;
  return new String(childData.getData());
}

代码示例来源:origin: xiancloud/xian

@Override
public String getVersion(String pluginName) {
  if (!ZkConnection.isConnected()) {
    return null;
  }
  LOG.debug("注意:查询版本号操作是实时查询zk,没有做缓存,不允许高频操作:" + pluginName);
  try {
    byte[] versionData = ZkConnection.client.getData().forPath(fullPath(pluginName));
    LOG.debug("if path exits but no data found, then empty byte array is returned. Thus here we need a empty array checking.");
    ResPluginDataBean resPluginDataBean = Reflection.toType(new String(versionData), ResPluginDataBean.class);
    if (resPluginDataBean != null)
      return resPluginDataBean.getVersion();
    return null;
  } catch (KeeperException.NoNodeException notExists) {
    return null;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

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