// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Configure.java
// public class Configure {
// 
// 	public static final String CONF_DATA_PATH = "/shziiqiu-conf";
// 	
// 	private static final String ZK_LINUX_ADDRESS_FILE = "/home/appConfig/shiziqiu-conf.properties";
// 	
// 	private static final String ZK_WINDOWS_ADDRESS_FILE = "c:/shiziqiu-conf.properties";
// 	
// 	/**
// 	 * zk地址
// 	 * 例：zk地址：格式	ip1:port,ip2:port,ip3:port
// 	 */
// 	public static final String ZK_ADDRESS;
// 	
// 	static {
// 		/**
// 		 * loadFileProperties 根据路径加载文件
// 		 * loadProperties 当前路径下加载文件
// 		 */
// 		Properties props = System.getProperties(); //获得系统属性集
// 		String osName = props.getProperty("os.name"); //操作系统名称
// 		Properties prop = null;
// 		try {
// 			if(StringUtils.isNotBlank(osName)) {
// 				if((osName.substring(0, 7)).equals("Windows")) {
// 					prop = PropertiesUtil.loadFileProperties(ZK_WINDOWS_ADDRESS_FILE);
// 				} else {
// 					prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// 				}
// 			}
// 		} catch (Exception e) {
// 			prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// 		}
// 		
// 		ZK_ADDRESS = PropertiesUtil.getString(prop, "zkserver");
// 	}
// 	
// 	public static void main(String[] args) {
// 		System.out.println(ZK_ADDRESS);
// 		
// 	}
// 	
// }


import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.shiziqiu.configuration.util.Configure;
package com.shiziqiu.configuration.core.zk;



/**
 * @title : ShiZiQiuZkConfClient
 * @author : crazy
 * @date : 2017年9月6日 下午5:29:33
 * @Fun :
 */
public class ShiZiQiuZkConfClient implements Watcher{

	private static Logger logger = LoggerFactory.getLogger(ShiZiQiuZkConfClient.class);
	
	private static ZooKeeper zooKeeper;
	
	/**
	 * 常用的lock ，tryLock ，其中有个lockInterruptibly 。
	 */
	private static ReentrantLock INSTANCE_INIT_LOCK = new ReentrantLock(true);
	
	private static ZooKeeper getInstance() {
		if (null == zooKeeper) {
			try {
				/**
				 * 如果 lock 不可用，则以下代码将在 2秒后超时：
				 */
				if (INSTANCE_INIT_LOCK.tryLock(2, TimeUnit.SECONDS)) {
					try {
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Configure.java
// public class Configure {
// 
// 	public static final String CONF_DATA_PATH = "/shziiqiu-conf";
// 	
// 	private static final String ZK_LINUX_ADDRESS_FILE = "/home/appConfig/shiziqiu-conf.properties";
// 	
// 	private static final String ZK_WINDOWS_ADDRESS_FILE = "c:/shiziqiu-conf.properties";
// 	
// 	/**
// 	 * zk地址
// 	 * 例：zk地址：格式	ip1:port,ip2:port,ip3:port
// 	 */
// 	public static final String ZK_ADDRESS;
// 	
// 	static {
// 		/**
// 		 * loadFileProperties 根据路径加载文件
// 		 * loadProperties 当前路径下加载文件
// 		 */
// 		Properties props = System.getProperties(); //获得系统属性集
// 		String osName = props.getProperty("os.name"); //操作系统名称
// 		Properties prop = null;
// 		try {
// 			if(StringUtils.isNotBlank(osName)) {
// 				if((osName.substring(0, 7)).equals("Windows")) {
// 					prop = PropertiesUtil.loadFileProperties(ZK_WINDOWS_ADDRESS_FILE);
// 				} else {
// 					prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// 				}
// 			}
// 		} catch (Exception e) {
// 			prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// 		}
// 		
// 		ZK_ADDRESS = PropertiesUtil.getString(prop, "zkserver");
// 	}
// 	
// 	public static void main(String[] args) {
// 		System.out.println(ZK_ADDRESS);
// 		
// 	}
// 	
// }


// Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuZkConfClient.java
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.shiziqiu.configuration.util.Configure;

package com.shiziqiu.configuration.core.zk;



/**
 * @title : ShiZiQiuZkConfClient
 * @author : crazy
 * @date : 2017年9月6日 下午5:29:33
 * @Fun :
 */
public class ShiZiQiuZkConfClient implements Watcher{

	private static Logger logger = LoggerFactory.getLogger(ShiZiQiuZkConfClient.class);
	
	private static ZooKeeper zooKeeper;
	
	/**
	 * 常用的lock ，tryLock ，其中有个lockInterruptibly 。
	 */
	private static ReentrantLock INSTANCE_INIT_LOCK = new ReentrantLock(true);
	
	private static ZooKeeper getInstance() {
		if (null == zooKeeper) {
			try {
				/**
				 * 如果 lock 不可用，则以下代码将在 2秒后超时：
				 */
				if (INSTANCE_INIT_LOCK.tryLock(2, TimeUnit.SECONDS)) {
					try {
						zooKeeper = new ZooKeeper(Configure.ZK_ADDRESS, 20000, new Watcher() {