Tabnine Logo
ZkConnection
Code IndexAdd Tabnine to your IDE (free)

How to use
ZkConnection
in
info.xiancloud.zookeeper

Best Java code snippets using info.xiancloud.zookeeper.ZkConnection (Showing top 8 results out of 315)

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);
  }
}
info.xiancloud.zookeeperZkConnection

Javadoc

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

Most used methods

  • close
  • start
  • getZkConnStr
  • isConnected

Popular in Java

  • Making http post requests using okhttp
  • getResourceAsStream (ClassLoader)
  • setContentView (Activity)
  • getApplicationContext (Context)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • BoxLayout (javax.swing)
  • Table (org.hibernate.mapping)
    A relational table
  • PhpStorm for WordPress
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now