// 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-framework/src/main/java/monica/framework/Client.java
// public interface Client {
// 	public void start(String ip, int port) throws Exception;
//     public  boolean isStarted();
// }


import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import monica.configuration.context.ConfigurationContext;
import monica.framework.Client;

package monica.files.socket;


/**
 * 
 * @author lucy@polarcoral.com
 *
 *         2017-08-29
 */
public class SocketClient implements Client {
	public final static String NAME = "socket";
	private final String SOCKET_CHANNEL = "channel";
	private volatile boolean isStarted = false;
	static final boolean SSL = System.getProperty("ssl") != null;

	public void start(String ip, int port) throws Exception {
		// Configure SSL.
		final SslContext sslCtx;
		if (SSL) {
			sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
		} else {
			sslCtx = null;
		}
		EventLoopGroup group = new NioEventLoopGroup();
		try {
			Bootstrap b = new Bootstrap();
			b.group(group).channel(NioSocketChannel.class).handler(new FileClientInitializer(sslCtx));
			Channel ch = b.connect(ip, port).sync().channel();

// 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-framework/src/main/java/monica/framework/Client.java
// public interface Client {
// 	public void start(String ip, int port) throws Exception;
//     public  boolean isStarted();
// }


// Path: monica-files/monica-files-socket/src/main/java/monica/files/socket/SocketClient.java
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import monica.configuration.context.ConfigurationContext;
import monica.framework.Client;

package monica.files.socket;


/**
 * 
 * @author lucy@polarcoral.com
 *
 *         2017-08-29
 */
public class SocketClient implements Client {
	public final static String NAME = "socket";
	private final String SOCKET_CHANNEL = "channel";
	private volatile boolean isStarted = false;
	static final boolean SSL = System.getProperty("ssl") != null;

	public void start(String ip, int port) throws Exception {
		// Configure SSL.
		final SslContext sslCtx;
		if (SSL) {
			sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
		} else {
			sslCtx = null;
		}
		EventLoopGroup group = new NioEventLoopGroup();
		try {
			Bootstrap b = new Bootstrap();
			b.group(group).channel(NioSocketChannel.class).handler(new FileClientInitializer(sslCtx));
			Channel ch = b.connect(ip, port).sync().channel();

			ConfigurationContext.propMap.putIfAbsent(SOCKET_CHANNEL, ch);			
