// Path: naive-core/src/main/java/com/goribun/naive/core/constants/SysErCode.java
// public enum SysErCode {
//     IO_ERROR(0001, "IO异常"),
//     OK_HTTP_ERROR(0002, "okhttp请求错误"),
//     RPC_ERROR(0003, "RPC调用失败"),
//     INIT_SERVER_ERR0R(0004, "初始化服务端失败"),
//     PROVIDE_ERR0R(0005, "提供rpc服务失败"),
//     ZK_ERR0R(0006, "zookeeper服务失败");
//     private int erCode;
//     private String msg;
// 
//     SysErCode(int erCode, String msg) {
//         this.erCode = erCode;
//         this.msg = msg;
//     }
// 
//     public int getErCode() {
//         return erCode;
//     }
// 
//     public String getMsg() {
//         return msg;
//     }
// 
//     public SysErCode getSysErCode(int erCode) {
//         for (SysErCode sys : SysErCode.values()) {
//             if (sys.getErCode() == erCode) {
//                 return sys;
//             }
//         }
//         return null;
//     }
// }
// 
// Path: naive-core/src/main/java/com/goribun/naive/core/exception/SysException.java
// public class SysException extends RuntimeException {
// 
//     private static final long serialVersionUID = 2363088507608422727L;
// 
//     private int errorCode;
// 
//     public SysException(SysErCode sysErCode) {
//         super(sysErCode.getMsg());
//         this.errorCode = sysErCode.getErCode();
//     }
// 
//     public SysException(SysErCode sysErCode, Throwable cause) {
//         super(sysErCode.getMsg(), cause);
//         this.errorCode = sysErCode.getErCode();
//     }
// }


import java.util.concurrent.CountDownLatch;
import com.goribun.naive.core.constants.SysErCode;
import com.goribun.naive.core.exception.SysException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
package com.goribun.navie.manage.regist;



/**
 * @author chenchuan@autohome.com.cn
 * @create 2017-04-13-下午8:22
 * @description
 */
public class ZkClient implements IZkClient, Watcher {
    private static final int TIME_OUT = 3000;
    private static final String HOST = "127.0.0.1:4181,127.0.0.1:4182,127.0.0.1:4183";
    private CountDownLatch countDownLatch = new CountDownLatch(1);

    protected ZooKeeper zooKeeper;

    @Override
    public void connection() {
        try {
            zooKeeper = new ZooKeeper(HOST, TIME_OUT, this);
            countDownLatch.await();
        } catch (Exception e) {
// Path: naive-core/src/main/java/com/goribun/naive/core/constants/SysErCode.java
// public enum SysErCode {
//     IO_ERROR(0001, "IO异常"),
//     OK_HTTP_ERROR(0002, "okhttp请求错误"),
//     RPC_ERROR(0003, "RPC调用失败"),
//     INIT_SERVER_ERR0R(0004, "初始化服务端失败"),
//     PROVIDE_ERR0R(0005, "提供rpc服务失败"),
//     ZK_ERR0R(0006, "zookeeper服务失败");
//     private int erCode;
//     private String msg;
// 
//     SysErCode(int erCode, String msg) {
//         this.erCode = erCode;
//         this.msg = msg;
//     }
// 
//     public int getErCode() {
//         return erCode;
//     }
// 
//     public String getMsg() {
//         return msg;
//     }
// 
//     public SysErCode getSysErCode(int erCode) {
//         for (SysErCode sys : SysErCode.values()) {
//             if (sys.getErCode() == erCode) {
//                 return sys;
//             }
//         }
//         return null;
//     }
// }
// 
// Path: naive-core/src/main/java/com/goribun/naive/core/exception/SysException.java
// public class SysException extends RuntimeException {
// 
//     private static final long serialVersionUID = 2363088507608422727L;
// 
//     private int errorCode;
// 
//     public SysException(SysErCode sysErCode) {
//         super(sysErCode.getMsg());
//         this.errorCode = sysErCode.getErCode();
//     }
// 
//     public SysException(SysErCode sysErCode, Throwable cause) {
//         super(sysErCode.getMsg(), cause);
//         this.errorCode = sysErCode.getErCode();
//     }
// }


// Path: naive-manage/src/main/java/com/goribun/navie/manage/regist/ZkClient.java
import java.util.concurrent.CountDownLatch;
import com.goribun.naive.core.constants.SysErCode;
import com.goribun.naive.core.exception.SysException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

package com.goribun.navie.manage.regist;



/**
 * @author chenchuan@autohome.com.cn
 * @create 2017-04-13-下午8:22
 * @description
 */
public class ZkClient implements IZkClient, Watcher {
    private static final int TIME_OUT = 3000;
    private static final String HOST = "127.0.0.1:4181,127.0.0.1:4182,127.0.0.1:4183";
    private CountDownLatch countDownLatch = new CountDownLatch(1);

    protected ZooKeeper zooKeeper;

    @Override
    public void connection() {
        try {
            zooKeeper = new ZooKeeper(HOST, TIME_OUT, this);
            countDownLatch.await();
        } catch (Exception e) {
            throw (SysException) new SysException(SysErCode.ZK_ERR0R).initCause(e);