package cn.aleader;

import org.apache.log4j.Logger;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import cn.acx.AcxConst;
import cn.amq.business.AmqMainPoint;
import cn.base.bean.BeanHelper;
import cn.base.conf.ModuleConfFactory;
import cn.map.szmap.schedule.CacheRefreshPool;

import com.jtiny.utility.JtinyEvent;

public class MainPoint {
	static Logger logger = Logger.getLogger(MainPoint.class);
	//通过schedulerFactory获取一个调度器
	static SchedulerFactory schedulerfactory=new StdSchedulerFactory();
	static Scheduler scheduler=null;
	public static void init() {
		if("1".equals(ModuleConfFactory.getModuleConfService().getScatter().getAmqSwitch())){
			initAmq();
		}
		if("1".equals(ModuleConfFactory.getModuleConfService().getScatter().getIceClientSwitch())){
			initDacClient();
		}
		try{
			if("1".equals(ModuleConfFactory.getModuleConfService().getScatter().getSzMapSwitch())){
				Thread.sleep(5000);
	    		CacheRefreshPool.getInstance().init();
	    		logger.info("SzMap start success..");
	    	}
		} catch (Exception e) {   
			logger.error("SzMap start error.."+e);
	    } 	
		/*已取消Grpc算法规则传输，算法自带配置界面
		try {
			//调用grpcClient对象，创建客户端
			initTrafficGrpcClient();
			//调用算法RPC接口，后台定时轮询（每五分钟执行一次算法规则同步任务）
			//已修改为前台同步，界面点击启动或停止后将数据实时传输给算法
			//initRpcJob();
		} catch (Exception e) {   
			logger.error("TrafficGrpc start error..");
	    } 	
	    */
		try{
			initAmq() ;
		}catch(Exception e){
			e.printStackTrace();
			logger.error("amq初始化失败："+e);
		}
		
	}
	
	public static void initAmq() {
		logger.info("AMQ module start...[START]...");
		AmqMainPoint.initAmq();
		logger.info("AMQ module start...[OK]...");
	}

	public static void initAce() {
		
	}

	public static void initFbpc() {
		
	}

	public static void initDacClient() {
		BeanHelper.getIcxDacClient().start();
		JtinyEvent dacEventTimer = new JtinyEvent(AcxConst.CLIENT_CONNECT_MSG,0, 0, null, null, null);
		BeanHelper.getIcxDacClient().registerTimer(dacEventTimer, 1 * 1 * 1000);
		logger.info("**************Start dac client task ... ...[OK]");
	}
	
	

}
