// 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/Storage.java
// public interface Storage {
// 	public void storage(TransportFile file);
//     
// }
// 
// Path: monica-framework/src/main/java/monica/framework/storage/AbstractStorageFactory.java
// public abstract class AbstractStorageFactory {
// 	public  abstract Storage newStorageInstance();
// }
// 
// Path: monica-framework/src/main/java/monica/framework/transport/TransportFile.java
// public class TransportFile implements Serializable{
// 
// 	private static final long serialVersionUID = 1L;
// 	private String fileName;
// 	private byte[] content;
// 	
// 	
// 	public String getFileName() {
// 		return fileName;
// 	}
// 	public void setFileName(String fileName) {
// 		this.fileName = fileName;
// 	}
// 	public byte[] getContent() {
// 		return content;
// 	}
// 	public void setContent(byte[] content) {
// 		this.content = content;
// 	}
// 	
// 	
// }


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import monica.configuration.context.ConfigurationContext;
import monica.framework.Storage;
import monica.framework.storage.AbstractStorageFactory;
import monica.framework.transport.TransportFile;
import io.netty.channel.ChannelHandler.Sharable;
/*
 * Copyright 2014 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package monica.files.socket;




/**
 * 
 * @author lucy@polarcoral.com
 *
 *         2017-08-29
 */
@Sharable
public class FileServerHandler extends SimpleChannelInboundHandler<Object> {
	private String STORAGE_CONFIG_KEY = "storage";
    private final int poolSize=20;

	@Override
	public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
		  ExecutorService storageService = Executors.newFixedThreadPool(poolSize);	 		
// 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/Storage.java
// public interface Storage {
// 	public void storage(TransportFile file);
//     
// }
// 
// Path: monica-framework/src/main/java/monica/framework/storage/AbstractStorageFactory.java
// public abstract class AbstractStorageFactory {
// 	public  abstract Storage newStorageInstance();
// }
// 
// Path: monica-framework/src/main/java/monica/framework/transport/TransportFile.java
// public class TransportFile implements Serializable{
// 
// 	private static final long serialVersionUID = 1L;
// 	private String fileName;
// 	private byte[] content;
// 	
// 	
// 	public String getFileName() {
// 		return fileName;
// 	}
// 	public void setFileName(String fileName) {
// 		this.fileName = fileName;
// 	}
// 	public byte[] getContent() {
// 		return content;
// 	}
// 	public void setContent(byte[] content) {
// 		this.content = content;
// 	}
// 	
// 	
// }


// Path: monica-files/monica-files-socket/src/main/java/monica/files/socket/FileServerHandler.java
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import monica.configuration.context.ConfigurationContext;
import monica.framework.Storage;
import monica.framework.storage.AbstractStorageFactory;
import monica.framework.transport.TransportFile;
import io.netty.channel.ChannelHandler.Sharable;

/*
 * Copyright 2014 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package monica.files.socket;




/**
 * 
 * @author lucy@polarcoral.com
 *
 *         2017-08-29
 */
@Sharable
public class FileServerHandler extends SimpleChannelInboundHandler<Object> {
	private String STORAGE_CONFIG_KEY = "storage";
    private final int poolSize=20;

	@Override
	public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
		  ExecutorService storageService = Executors.newFixedThreadPool(poolSize);	 		
		  String storageFactoryName = String.valueOf(ConfigurationContext.propMap.get(STORAGE_CONFIG_KEY));		   