package org.bench4q.master;

import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;

/**
 * 
 * @author coderfengyun
 * 
 */
public class Main {
	private static Logger logger = Logger.getLogger(Main.class);
	public static int Min_Sample_Cycle_InSecond = 10;
	public static int MAX_FAIL_TIMES = 10;
	public static int MIN_EXECUTE_INTERVAL_IN_SECONDS = 600;
	public static int PICK_CYCLE_IN_SECONDS = 60;
	public static String SCRIPT_PARAM_ROOT_FOLDER = "ScriptParameterization";
	public static String FILE_SEPARATOR = System.getProperty("file.separator");

	public static void main(String[] args) {
		try {
			MasterServer masterServer = new MasterServer(getPortToServe());
			masterServer.start();
		} catch (Exception e) {
			e.printStackTrace();
			return;
		}
	}

	public static int getPortToServe() {
		int portToUse = 0;
		Properties prop = new Properties();
		String configFile = "";
		try {
			InputStream inputStream = Main.class.getClassLoader()
					.getResourceAsStream(
							"org/bench4q/master/config/ServerPort.properties");
			prop.load(inputStream);
			portToUse = Integer.parseInt(prop.getProperty("portToServe"));
			MAX_FAIL_TIMES = Integer.parseInt(prop.getProperty("maxFailTime"));
			MIN_EXECUTE_INTERVAL_IN_SECONDS = Integer.parseInt(prop
					.getProperty("minExcuteIntervalInSeconds"));
			PICK_CYCLE_IN_SECONDS = Integer.parseInt(prop
					.getProperty("pickTestPlanCycleInSeconds"));
			Min_Sample_Cycle_InSecond = Integer.parseInt(prop
					.getProperty("minSampleCycleInSeconds"));
			SCRIPT_PARAM_ROOT_FOLDER = prop
					.getProperty("scriptParamRootFolder");
		} catch (Exception e) {
			e.printStackTrace();
			MAX_FAIL_TIMES = 10;
			MIN_EXECUTE_INTERVAL_IN_SECONDS = 600;
			PICK_CYCLE_IN_SECONDS = 60;
			Min_Sample_Cycle_InSecond = 10;
			SCRIPT_PARAM_ROOT_FOLDER = "ScriptParameterization";
			logger.error("There is no config file for port to serve! where path is "
					+ configFile);
		}
		return portToUse;
	}
}
