// Path: monica-configuration/src/main/java/monica/configuration/context/ConfigurationContext.java
// public class ConfigurationContext {
// 	private static String yamlBaseFilePath = "yaml";
// 	
// 	public static ConcurrentHashMap<String, Object> propMap = new ConcurrentHashMap<String, Object>();
// 	
// 	/**
// 	 * need to adapt to different registry framework.  below just be customized to zookeeper
// 	 * @throws FileNotFoundException
// 	 * @throws IOException
// 	 */
// 	public static void loadYamlServerConfig() throws FileNotFoundException, IOException{		
// 		Yaml yaml = new Yaml();
// 		File path = Utils.getPropertiesPath("yaml\\monica.yaml");
// 		//YamlMonica yamlMonica = yaml.loadAs(new FileInputStream(path), YamlMonica.class);		
// 		YamlMonica yamlMonica = yaml.loadAs(Utils.loadResources("yaml/monica.yaml").openStream(), YamlMonica.class);
// 		propMap.putIfAbsent("yamlMonica", yamlMonica);
// 		propMap.putIfAbsent("serverString", yamlMonica.toServerString());
// 		propMap.putIfAbsent("storage", yamlMonica.getStorage());
// 	}
// 	
// 	
// 	public static void loadYamlClientConfig() throws FileNotFoundException, IOException{
// 		Yaml yaml = new Yaml();
// 		File path = Utils.getPropertiesPath("\\yaml\\client.yaml");
// 		//YamlClient yamlClient = yaml.loadAs(new FileInputStream(path), YamlClient.class);		
// 		YamlClient yamlClient = yaml.loadAs(Utils.loadResources("yaml/client.yaml").openStream(), YamlClient.class);
// 		propMap.putIfAbsent("client", yamlClient);
// 		propMap.putIfAbsent("serverString", yamlClient.toServerString());
// 	}
// 	
// 	public static List<String> loadYamlRouterConfig() throws FileNotFoundException, IOException{
// 		Yaml yaml = new Yaml();
// 		File path = Utils.getPropertiesPath("\\yaml\\router.yaml");
// 		//YamlRouter yamlRouter = yaml.loadAs(new FileInputStream(path), YamlRouter.class);	
// 		YamlRouter yamlRouter = yaml.loadAs(Utils.loadResources("yaml/router.yaml").openStream(), YamlRouter.class);
// 		return yamlRouter.toStringList();
// 	}
// 	
// 	
// 	private static ClassLoader getClassLoader(){
// 		return ConfigurationContext.class.getClassLoader();
// 	}
// 	
// 	public static void main(String args[]){	
// 		try {
// 			//loadYamlServerConfig();
// 			//YamlMonica monica = (YamlMonica)propMap.get("yamlMonica");
// 			List<String> rules = loadYamlRouterConfig();
// 			System.out.println("zk --------  "+rules.get(0));
// 		} catch (FileNotFoundException e) {
// 			e.printStackTrace();
// 		} catch (IOException e) {
// 			e.printStackTrace();
// 		}
// 		
// 	}
// 
// }
// 
// Path: monica-coordinator/src/main/java/monica/coordinator/ConfigService.java
// @SPI(ZookeeperConfigService.NAME)
// public interface ConfigService {
// 	public void initService() throws Exception;
// 
// 	public void rulesStore(List<String> rules) throws Exception;
// 
// 	public void rulesStore() throws Exception;
// }
// 
// Path: monica-registry/src/main/java/monica/registry/context/RegistryContext.java
// public class RegistryContext {
// 	// caheKey: curatorClient providers server usefulProviders
// 	public static ConcurrentHashMap<String, Object> clientCache = new ConcurrentHashMap<String, Object>();
// }


import java.net.URLEncoder;
import java.util.List;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.api.CuratorWatcher;
import org.apache.zookeeper.WatchedEvent;
import monica.configuration.context.ConfigurationContext;
import monica.coordinator.ConfigService;
import monica.registry.context.RegistryContext;

package monica.coordinator.impl.zookeeper;



/**
 * 
 * @author lucy@polarcoral.com
 *
 *         2017-08-29
 */
public class ZookeeperConfigService implements ConfigService {
	public final static String NAME = "zookeeper";

// Path: monica-configuration/src/main/java/monica/configuration/context/ConfigurationContext.java
// public class ConfigurationContext {
// 	private static String yamlBaseFilePath = "yaml";
// 	
// 	public static ConcurrentHashMap<String, Object> propMap = new ConcurrentHashMap<String, Object>();
// 	
// 	/**
// 	 * need to adapt to different registry framework.  below just be customized to zookeeper
// 	 * @throws FileNotFoundException
// 	 * @throws IOException
// 	 */
// 	public static void loadYamlServerConfig() throws FileNotFoundException, IOException{		
// 		Yaml yaml = new Yaml();
// 		File path = Utils.getPropertiesPath("yaml\\monica.yaml");
// 		//YamlMonica yamlMonica = yaml.loadAs(new FileInputStream(path), YamlMonica.class);		
// 		YamlMonica yamlMonica = yaml.loadAs(Utils.loadResources("yaml/monica.yaml").openStream(), YamlMonica.class);
// 		propMap.putIfAbsent("yamlMonica", yamlMonica);
// 		propMap.putIfAbsent("serverString", yamlMonica.toServerString());
// 		propMap.putIfAbsent("storage", yamlMonica.getStorage());
// 	}
// 	
// 	
// 	public static void loadYamlClientConfig() throws FileNotFoundException, IOException{
// 		Yaml yaml = new Yaml();
// 		File path = Utils.getPropertiesPath("\\yaml\\client.yaml");
// 		//YamlClient yamlClient = yaml.loadAs(new FileInputStream(path), YamlClient.class);		
// 		YamlClient yamlClient = yaml.loadAs(Utils.loadResources("yaml/client.yaml").openStream(), YamlClient.class);
// 		propMap.putIfAbsent("client", yamlClient);
// 		propMap.putIfAbsent("serverString", yamlClient.toServerString());
// 	}
// 	
// 	public static List<String> loadYamlRouterConfig() throws FileNotFoundException, IOException{
// 		Yaml yaml = new Yaml();
// 		File path = Utils.getPropertiesPath("\\yaml\\router.yaml");
// 		//YamlRouter yamlRouter = yaml.loadAs(new FileInputStream(path), YamlRouter.class);	
// 		YamlRouter yamlRouter = yaml.loadAs(Utils.loadResources("yaml/router.yaml").openStream(), YamlRouter.class);
// 		return yamlRouter.toStringList();
// 	}
// 	
// 	
// 	private static ClassLoader getClassLoader(){
// 		return ConfigurationContext.class.getClassLoader();
// 	}
// 	
// 	public static void main(String args[]){	
// 		try {
// 			//loadYamlServerConfig();
// 			//YamlMonica monica = (YamlMonica)propMap.get("yamlMonica");
// 			List<String> rules = loadYamlRouterConfig();
// 			System.out.println("zk --------  "+rules.get(0));
// 		} catch (FileNotFoundException e) {
// 			e.printStackTrace();
// 		} catch (IOException e) {
// 			e.printStackTrace();
// 		}
// 		
// 	}
// 
// }
// 
// Path: monica-coordinator/src/main/java/monica/coordinator/ConfigService.java
// @SPI(ZookeeperConfigService.NAME)
// public interface ConfigService {
// 	public void initService() throws Exception;
// 
// 	public void rulesStore(List<String> rules) throws Exception;
// 
// 	public void rulesStore() throws Exception;
// }
// 
// Path: monica-registry/src/main/java/monica/registry/context/RegistryContext.java
// public class RegistryContext {
// 	// caheKey: curatorClient providers server usefulProviders
// 	public static ConcurrentHashMap<String, Object> clientCache = new ConcurrentHashMap<String, Object>();
// }


// Path: monica-coordinator/src/main/java/monica/coordinator/impl/zookeeper/ZookeeperConfigService.java
import java.net.URLEncoder;
import java.util.List;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.api.CuratorWatcher;
import org.apache.zookeeper.WatchedEvent;
import monica.configuration.context.ConfigurationContext;
import monica.coordinator.ConfigService;
import monica.registry.context.RegistryContext;

package monica.coordinator.impl.zookeeper;



/**
 * 
 * @author lucy@polarcoral.com
 *
 *         2017-08-29
 */
public class ZookeeperConfigService implements ConfigService {
	public final static String NAME = "zookeeper";

	private CuratorFramework zkClient = (CuratorFramework) RegistryContext.clientCache.get("curatorClient");
