Package com.netflix.curator.framework

Examples of com.netflix.curator.framework.CuratorFramework


    builder.connectString(connectionString);
    TimeSpan retryInterval = TimeSpan.FIVE_SECONDS;
    RetryPolicy retryPolicy = new RetryOneTime((int) retryInterval.getTotalMilliseconds());
    builder.retryPolicy(retryPolicy);

    CuratorFramework curatorFramework;
    try {
      curatorFramework = builder.build();
    } catch (IOException e) {
      throw new OpsException("Error building zookeeper connection", e);
    }
View Full Code Here


   * @return
   */
  public CuratorFramework mkClient(Map conf, List<String> servers,
      Object port, String root, final WatcherCallBack watcher) {

    CuratorFramework fk = Utils.newCurator(conf, servers, port, root);

    fk.getCuratorListenable().addListener(new CuratorListener() {
      @Override
      public void eventReceived(CuratorFramework _fk, CuratorEvent e)
          throws Exception {

        if (e.getType().equals(CuratorEventType.WATCHED)) {
          WatchedEvent event = e.getWatchedEvent();

          watcher.execute(event.getState(), event.getType(),
              event.getPath());
        }

      }
    });

    fk.getUnhandledErrorListenable().addListener(
        new UnhandledErrorListener() {
          @Override
          public void unhandledError(String msg, Throwable error) {
            String errmsg = "Unrecoverable Zookeeper error, halting process: "
                + msg;
            LOG.error(errmsg, error);
            StormUtils.halt_process(1,
                "Unrecoverable Zookeeper error");

          }
        });

    fk.start();

    return fk;
  }
View Full Code Here

    for (String zkServer : (List<String>) servers) {
      serverPorts.add(zkServer + ":" + Utils.getInt(port));
    }
    String zkStr = StringUtils.join(serverPorts, ",") + root;
    try {
      CuratorFramework ret = CuratorFrameworkFactory
          .newClient(
              zkStr,
              Utils.getInt(conf
                  .get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT)),
              15000,
View Full Code Here

    return newCurator(conf, servers, port, "");
  }

  public static CuratorFramework newCuratorStarted(Map conf,
      List<String> servers, Object port, String root) {
    CuratorFramework ret = newCurator(conf, servers, port, root);
    ret.start();
    return ret;
  }
View Full Code Here

    return ret;
  }

  public static CuratorFramework newCuratorStarted(Map conf,
      List<String> servers, Object port) {
    CuratorFramework ret = newCurator(conf, servers, port);
    ret.start();
    return ret;
  }
View Full Code Here

  private WatcherCallBack watcher;

  public DistributedClusterState(Map _conf) throws Exception {
    conf = _conf;
    zkobj = new Zookeeper();
    CuratorFramework _zk = mkZk();
    String path = String.valueOf(conf.get(Config.STORM_ZOOKEEPER_ROOT));
    zkobj.mkdirs(_zk, path);
    _zk.close();

    active = new AtomicBoolean(true);

    watcher = new WatcherCallBack() {
      @SuppressWarnings("unchecked")
View Full Code Here

                              .get(Config.TOPOLOGY_KRYO_REGISTER));
            }
            String rootDir = conf.get(Config.TRANSACTIONAL_ZOOKEEPER_ROOT) + "/" + id + "/" + subroot;
            List<String> servers = (List<String>) getWithBackup(conf, Config.TRANSACTIONAL_ZOOKEEPER_SERVERS, Config.STORM_ZOOKEEPER_SERVERS);
            Object port = getWithBackup(conf, Config.TRANSACTIONAL_ZOOKEEPER_PORT, Config.STORM_ZOOKEEPER_PORT);
            CuratorFramework initter = Utils.newCuratorStarted(conf, servers, port);
            try {
                initter.create().creatingParentsIfNeeded().forPath(rootDir);
            } catch(KeeperException.NodeExistsException e)  {
               
            }
           
            initter.close();
                                   
            _curator = Utils.newCuratorStarted(conf, servers, port, rootDir);
            _ser = new KryoValuesSerializer(conf);
            _des = new KryoValuesDeserializer(conf);
        } catch (Exception e) {
View Full Code Here

    }

    @Get("/curator")
    public String testCurator() throws Exception {
        String path = "/test_path";
        CuratorFramework client = CuratorFrameworkFactory.builder().connectString("zookeeper.n.miliao.com:2181").namespace("/test1")
                .retryPolicy(new RetryNTimes(Integer.MAX_VALUE, 1000)).connectionTimeoutMs(5000).build();
        // create a node
        client.create().forPath("/head", new byte[0]);

        // delete a node in background
        client.delete().inBackground().forPath("/head");

        // create a EPHEMERAL_SEQUENTIAL
        client.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath("/head/child", new byte[0]);

        // get the data
        client.getData().watched().inBackground().forPath("/test");

        // check the path exits
        client.checkExists().forPath(path);

        return "@adf";
    }
View Full Code Here

        return "@adf";
    }

    public static void main(String[] args) throws Exception {
        String path = "/test_path";
        CuratorFramework client = CuratorFrameworkFactory.builder().connectString("zookeeper.n.miliao.com:2181").namespace("/brokers").retryPolicy(new RetryNTimes(Integer.MAX_VALUE, 1000)).connectionTimeoutMs(5000).build();
        // 启动 上面的namespace会作为一个最根的节点在使用时自动创建
        client.start();

        // 创建一个节点
        client.create().forPath("/head", new byte[0]);

        // 异步地删除一个节点
        client.delete().inBackground().forPath("/head");

        // 创建一个临时节点
        client.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath("/head/child", new byte[0]);

        // 取数据
        client.getData().watched().inBackground().forPath("/test");

        // 检查路径是否存在
        client.checkExists().forPath(path);

        // 异步删除
        client.delete().inBackground().forPath("/head");

        // 注册观察者,当节点变动时触发
        client.getData().usingWatcher(new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                System.out.println("node is changed");
            }
        }).inBackground().forPath("/test");

        // 结束使用
        client.close();
    }
View Full Code Here

    public static CuratorFramework newCurator(Map conf, List<String> servers, Object port) {
        return newCurator(conf, servers, port, "");
    }

    public static CuratorFramework newCuratorStarted(Map conf, List<String> servers, Object port, String root) {
        CuratorFramework ret = newCurator(conf, servers, port, root);
        ret.start();
        return ret;
    }
View Full Code Here

TOP

Related Classes of com.netflix.curator.framework.CuratorFramework

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.