这是ZooKeeper客户端库的主要类。使用一个ZooKeeper服务,应用程序必须首先实例化ZooKeeper类的对象。所有的迭代都将通过调用ZooKeeper类的方法来完成。除非另有说明,该类的方法是线程安全的。

构造函数:

    public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher)
throws IOException
{
this(connectString, sessionTimeout, watcher, false);
}

  

    public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher,
boolean canBeReadOnly)
throws IOException{
LOG.info("Initiating client connection, connectString=" + connectString
+ " sessionTimeout=" + sessionTimeout + " watcher=" + watcher); watchManager.defaultWatcher = watcher; ConnectStringParser connectStringParser = new ConnectStringParser(
connectString);
HostProvider hostProvider = new StaticHostProvider(
connectStringParser.getServerAddresses());
cnxn = new ClientCnxn(connectStringParser.getChrootPath(),
hostProvider, sessionTimeout, this, watchManager,
getClientCnxnSocket(), canBeReadOnly);
cnxn.start();
}

  

    public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher,
long sessionId, byte[] sessionPasswd)
throws IOException{
this(connectString, sessionTimeout, watcher, sessionId, sessionPasswd, false);
}

  

    public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher,
long sessionId, byte[] sessionPasswd, boolean canBeReadOnly)
throws IOException{
LOG.info("Initiating client connection, connectString=" + connectString
+ " sessionTimeout=" + sessionTimeout
+ " watcher=" + watcher
+ " sessionId=" + Long.toHexString(sessionId)
+ " sessionPasswd="
+ (sessionPasswd == null ? "<null>" : "<hidden>")); watchManager.defaultWatcher = watcher; ConnectStringParser connectStringParser = new ConnectStringParser(
connectString);
HostProvider hostProvider = new StaticHostProvider(
connectStringParser.getServerAddresses());
cnxn = new ClientCnxn(connectStringParser.getChrootPath(),
hostProvider, sessionTimeout, this, watchManager,
getClientCnxnSocket(), sessionId, sessionPasswd, canBeReadOnly);
cnxn.seenRwServerBefore = true; // since user has provided sessionId
cnxn.start();
}

  

zookeeper Zookeeper的更多相关文章

  1. [Big Data - ZooKeeper] ZooKeeper: A Distributed Coordination Service for Distributed Applications

    ZooKeeper ZooKeeper: A Distributed Coordination Service for Distributed Applications Design Goals Da ...

  2. Zookeeper - zookeeper安装与配置

    1.什么时Zookeeper ZooKeeper:分布式服务框架 Zookeeper -- 管理分布式环境中的数据. 2.安装 1>官网下载压缩包并解压zookeeper-3.4.14.zip ...

  3. [ ZooKeeper]ZooKeeper 的功能和原理

    Zookeeper功能简介: ZooKeeper 是一个开源的分布式协调服务,由雅虎创建,是 Google Chubby 的开源实现.分布式应用程序可以基于 ZooKeeper 实现诸如数据发布/订阅 ...

  4. centos7下安装zookeeper&zookeeper集群的搭建

    一.centos7下安装zookeeper 1.zookeeper 下载地址 https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ 2.安装步骤 ...

  5. Zookeeper:Zookeeper集群概要

    1.下载解压zookeeper 使用官网的(http://zookeeper.apache.org/releases.html#download)推荐下载镜像https://mirrors.tuna. ...

  6. [zookeeper] Zookeeper伪分布式集群配置

    参考配置:http://blog.csdn.net/clementad/article/details/48057059 注意要点: 启动时注意分别启动 bin/zkServer.sh start c ...

  7. ZooKeeper1 利用虚拟机搭建自己的ZooKeeper集群

    前言:       前段时间自己参考网上的文章,梳理了一下基于分布式环境部署的业务系统在解决数据一致性问题上的方案,其中有一个方案是使用ZooKeeper,加之在大数据处理中,ZooKeeper确实起 ...

  8. 构建高可用ZooKeeper集群

    ZooKeeper 是 Apache 的一个顶级项目,为分布式应用提供高效.高可用的分布式协调服务,提供了诸如数据发布/订阅.负载均衡.命名服务.分布式协调/通知和分布式锁等分布式基础服务.由于 Zo ...

  9. 【分布式】Zookeeper使用--开源客户端

    一.前言 上一篇博客已经介绍了如何使用Zookeeper提供的原生态Java API进行操作,本篇博文主要讲解如何通过开源客户端来进行操作. 二.ZkClient ZkClient是在Zookeepe ...

随机推荐

  1. 将ts文件合并为mp4命令

    cmd: copy/b D:\*.ts D:\new.ts 参考:http://blog.sina.com.cn/s/blog_66b4f1180102uzxs.html

  2. LigerUi中表(Grid)控件的相关属性笔记

    http://blog.csdn.net/dxnn520/article/details/8216560 // ========================================= [每 ...

  3. 跟我一起从零开始学WCF系列课程

    http://www.microsoft.com/china/msdn/events/webcasts/shared/webcast/Series/WCF_Begin.aspx 服务和协定 服务协定使 ...

  4. Jquery点击数字切换图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 前端小记2——移动web解决方案

    面向用户级移动web解决方案: 1.代码结构规范 2.字体设置 body{ font-family: -apple-system, BlinkMacSystemFont, "PingFang ...

  6. Sql优化器究竟帮你做了哪些工作?

    关系型数据库的一大优势之一,用户无需关心数据的访问方式,因为这些优化器都帮我们处理好了,但sql查询优化的时候,我不得不要对此进行关注,因为这牵扯到查询性能问题. 有经验的程序员都会对一些sql优化了 ...

  7. Java基础面试题:super.getClass().getName() 执行结果是什么?

    package com.swift; import java.util.Date; public class Getclass_Test extends Date { public static vo ...

  8. Uva 派 (Pie,NWERC 2006,LA 3635)

    依然是一道二分查找 #include<iostream> #include<cstdio> #include<cmath> using namespace std; ...

  9. neo4j 安装

    查看 http://ip:7474/browser/

  10. Ansible指令和常用模块使用

    这里文章记录一下ansible的指令选项和常用的模块使用 ansible指令选项 -m:要执行的模块,默认为command -a:模块的参数 -u:ssh连接的用户名,默认用root,ansible. ...