// Path: monica-starter/src/main/java/monica/starter/server/ServerStarter.java
// public class ServerStarter {
// 
// 	private final Logger log = LoggerFactory.getLogger(ServerStarter.class);
// 	private final String protocolPrefix = "monica.files";
// 
// 	public void start() throws Exception {
// 		// take note of the number arg for CountDownLatch() constructor.
// 		// CountDownLatch instance will wait the countDown number which is
// 		// specified here.
// 		final CountDownLatch zkSignal = new CountDownLatch(1);
// 		final CountDownLatch nettySignal = new CountDownLatch(1);
// 		ConfigurationContext.loadYamlServerConfig();
// 		YamlMonica monica = (YamlMonica) ConfigurationContext.propMap.get("yamlMonica");
// 		String protocolString = monica.getProtocol();
// 		String className = protocolString.substring(0, 1).toUpperCase()
// 				+ protocolString.substring(1, protocolString.length()) + "Server";
// 		String protocolPackageName = protocolPrefix + "." + monica.getProtocol();
// 		ClassPool pool = ClassPool.getDefault();
// 		CtClass cc = pool.get(protocolPackageName + "." + className);
// 		Object o = cc.toClass().newInstance();
// 		final Server server = (Server) o;
// 		Executors.newSingleThreadExecutor().execute(new NettyRunnable(zkSignal, server));
// 		Executors.newSingleThreadExecutor().execute(new ZookeeperRunnable(zkSignal));
// 		for (;;) {
// 			// the Server isStrated field is visible to multi-thread by volatile
// 			// modifier
// 			if (server.isStarted()) {
// 				nettySignal.countDown();
// 				break;
// 			}
// 		}
// 		nettySignal.await();
// 		ConfigServiceInit.init();
// 		new RegistryCentre().setUri(createUri(server)).setType(RegistryType.SERVER).start();
// 
// 		if (RegistryCentre.registryFinished()) {
// 			log.info("monica server start successfully!");
// 		}
// 		log.warn("monica server start successfully!");
// 	}
// 
// 	private UriSpec createUri(Server server) throws Exception {
// 		UriSpec uriSpec = new UriSpec();
// 		uriSpec.setIp(server.getHostIp());
// 		uriSpec.setPort(server.getPort() + "");
// 		return uriSpec;
// 	}
// 
// 	public static void main(String args[]) {
// 		try {
// 			ServerStarter container = new ServerStarter();
// 			container.start();
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		}
// 
// 	}
// 
// 	class ZookeeperRunnable implements Runnable {
// 		private CountDownLatch zkCountDown;
// 
// 		public ZookeeperRunnable(CountDownLatch latch) {
// 			this.zkCountDown = latch;
// 		}
// 
// 		public void run() {
// 			new ZookeeperMonicaClient().start();
// 			zkCountDown.countDown();
// 		}
// 	}
// 
// 	class NettyRunnable implements Runnable {
// 		private final CountDownLatch zkSignal;
// 		private Server server;
// 
// 		public NettyRunnable(CountDownLatch zkLatch, Server monicaServer) {
// 			this.zkSignal = zkLatch;
// 			server = monicaServer;
// 		}
// 
// 		public void run() {
// 			try {
// 				zkSignal.await();
// 				server.start();
// 			} catch (Exception e) {
// 				e.printStackTrace();
// 			}
// 
// 		}
// 
// 	}
// 
// }


import monica.starter.server.ServerStarter;

/*
 * Copyright 2017 The Monica Project
 *
 * The Monica 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.examples;


/**
 * 
 * @author lucy@polarcoral.com
 *
 *         2017-08-29
 */
public class MonicaServer {
	public static void main(String args[]) {

// Path: monica-starter/src/main/java/monica/starter/server/ServerStarter.java
// public class ServerStarter {
// 
// 	private final Logger log = LoggerFactory.getLogger(ServerStarter.class);
// 	private final String protocolPrefix = "monica.files";
// 
// 	public void start() throws Exception {
// 		// take note of the number arg for CountDownLatch() constructor.
// 		// CountDownLatch instance will wait the countDown number which is
// 		// specified here.
// 		final CountDownLatch zkSignal = new CountDownLatch(1);
// 		final CountDownLatch nettySignal = new CountDownLatch(1);
// 		ConfigurationContext.loadYamlServerConfig();
// 		YamlMonica monica = (YamlMonica) ConfigurationContext.propMap.get("yamlMonica");
// 		String protocolString = monica.getProtocol();
// 		String className = protocolString.substring(0, 1).toUpperCase()
// 				+ protocolString.substring(1, protocolString.length()) + "Server";
// 		String protocolPackageName = protocolPrefix + "." + monica.getProtocol();
// 		ClassPool pool = ClassPool.getDefault();
// 		CtClass cc = pool.get(protocolPackageName + "." + className);
// 		Object o = cc.toClass().newInstance();
// 		final Server server = (Server) o;
// 		Executors.newSingleThreadExecutor().execute(new NettyRunnable(zkSignal, server));
// 		Executors.newSingleThreadExecutor().execute(new ZookeeperRunnable(zkSignal));
// 		for (;;) {
// 			// the Server isStrated field is visible to multi-thread by volatile
// 			// modifier
// 			if (server.isStarted()) {
// 				nettySignal.countDown();
// 				break;
// 			}
// 		}
// 		nettySignal.await();
// 		ConfigServiceInit.init();
// 		new RegistryCentre().setUri(createUri(server)).setType(RegistryType.SERVER).start();
// 
// 		if (RegistryCentre.registryFinished()) {
// 			log.info("monica server start successfully!");
// 		}
// 		log.warn("monica server start successfully!");
// 	}
// 
// 	private UriSpec createUri(Server server) throws Exception {
// 		UriSpec uriSpec = new UriSpec();
// 		uriSpec.setIp(server.getHostIp());
// 		uriSpec.setPort(server.getPort() + "");
// 		return uriSpec;
// 	}
// 
// 	public static void main(String args[]) {
// 		try {
// 			ServerStarter container = new ServerStarter();
// 			container.start();
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		}
// 
// 	}
// 
// 	class ZookeeperRunnable implements Runnable {
// 		private CountDownLatch zkCountDown;
// 
// 		public ZookeeperRunnable(CountDownLatch latch) {
// 			this.zkCountDown = latch;
// 		}
// 
// 		public void run() {
// 			new ZookeeperMonicaClient().start();
// 			zkCountDown.countDown();
// 		}
// 	}
// 
// 	class NettyRunnable implements Runnable {
// 		private final CountDownLatch zkSignal;
// 		private Server server;
// 
// 		public NettyRunnable(CountDownLatch zkLatch, Server monicaServer) {
// 			this.zkSignal = zkLatch;
// 			server = monicaServer;
// 		}
// 
// 		public void run() {
// 			try {
// 				zkSignal.await();
// 				server.start();
// 			} catch (Exception e) {
// 				e.printStackTrace();
// 			}
// 
// 		}
// 
// 	}
// 
// }


// Path: monica-examples/src/main/java/monica/examples/MonicaServer.java
import monica.starter.server.ServerStarter;

/*
 * Copyright 2017 The Monica Project
 *
 * The Monica 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.examples;


/**
 * 
 * @author lucy@polarcoral.com
 *
 *         2017-08-29
 */
public class MonicaServer {
	public static void main(String args[]) {

		ServerStarter container = new ServerStarter();
