Esempio n. 1
0
  /**
   * @Description: 初始化
   *
   * @throws IOException
   * @throws InterruptedException
   * @return void
   * @author liaoqiqi
   * @date 2013-6-14
   */
  private void initInternal(String hosts, String defaultPrefixString)
      throws IOException, InterruptedException {

    store = new ResilientActiveKeyValueStore();
    store.connect(hosts);

    LOGGER.info("zoo prefix: " + defaultPrefixString);

    // 新建父目录
    makeDir(defaultPrefixString, ZooUtils.getIp());
  }
Esempio n. 2
0
  /**
   * Zoo的新建目录
   *
   * @param dir
   */
  public void makeDir(String dir, String data) {

    try {

      boolean deafult_path_exist = store.exists(dir);
      if (!deafult_path_exist) {
        LOGGER.info("create: " + dir);
        this.writePersistentUrl(dir, data);
      } else {
      }

    } catch (KeeperException e) {

      LOGGER.error("cannot create path: " + dir, e);

    } catch (Exception e) {

      LOGGER.error("cannot create path: " + dir, e);
    }
  }
Esempio n. 3
0
  /**
   * @Description: 带状态信息的读取数据
   *
   * @param path
   * @param watcher
   * @param stat
   * @return
   * @throws InterruptedException
   * @throws KeeperException
   * @return String
   * @author liaoqiqi
   * @date 2013-6-17
   */
  public String read(String path, Watcher watcher, Stat stat)
      throws InterruptedException, KeeperException {

    return store.read(path, watcher, stat);
  }
Esempio n. 4
0
  /**
   * @Description: 删除结点
   *
   * @param path
   * @return void
   * @author liaoqiqi
   * @date 2013-6-17
   */
  public void deleteNode(String path) {

    store.deleteNode(path);
  }
Esempio n. 5
0
  /*
   * 路径是否存在
   */
  public boolean exists(String path) throws Exception {

    return store.exists(path);
  }
Esempio n. 6
0
  /*
   * 生成一个临时结点
   */
  public String createEphemeralNode(String path, String value, CreateMode createMode)
      throws Exception {

    return store.createEphemeralNode(path, value, createMode);
  }
Esempio n. 7
0
  /*
   * 返回zk
   */
  public ZooKeeper getZk() {

    return store.getZk();
  }
Esempio n. 8
0
  /**
   * @Description: 读结点数据
   *
   * @return
   * @return List<String>
   * @author liaoqiqi
   * @date 2013-6-14
   */
  public String readUrl(String url, Watcher watcher) throws Exception {

    return store.read(url, watcher, null);
  }
Esempio n. 9
0
  /**
   * @Description: 写持久化结点,没有则新建,存在则进行更新
   *
   * @return
   * @return List<String>
   * @author liaoqiqi
   * @date 2013-6-14
   */
  public void writePersistentUrl(String url, String value) throws Exception {

    store.write(url, value);
  }
Esempio n. 10
0
  /**
   * @Description: 获取子孩子 列表
   *
   * @return
   * @return List<String>
   * @author liaoqiqi
   * @date 2013-6-14
   */
  public List<String> getRootChildren() {

    return store.getRootChildren();
  }
Esempio n. 11
0
  /**
   * @Description: 应用程序必须调用它来释放zookeeper资源
   *
   * @return void
   * @author liaoqiqi
   * @date 2013-6-14
   */
  public void release() throws InterruptedException {

    store.close();
  }