mycat源码解析

来源:互联网 发布:淘宝商品展示页面html 编辑:程序博客网 时间:2024/06/13 23:51

MycatStartup启动类

    private static final String dateFormat = "yyyy-MM-dd HH:mm:ss";    private static final Logger LOGGER = LoggerFactory.getLogger(MycatStartup.class);    public static void main(String[] args) {        //use zk ?        ZkConfig.getInstance().initZk();//初始化zk        try {            String home = SystemConfig.getHomePath();            if (home == null) {                System.out.println(SystemConfig.SYS_HOME + "  is not set.");                System.exit(-1);            }            // init            MycatServer server = MycatServer.getInstance();            server.beforeStart();            // startup            server.startup();//启动server            System.out.println("MyCAT Server startup successfully. see logs in logs/mycat.log");        } catch (Exception e) {            SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);            LOGGER.error(sdf.format(new Date()) + " startup error", e);            System.exit(-1);        }    }

MycatServer服务初始化
读取配置文件、启动、启动心跳检测

        private MycatServer() {        //读取文件配置        this.config = new MycatConfig();        //定时线程池,单线程线程池,删除没有的动态类        scheduler = Executors.newSingleThreadScheduledExecutor();        //心跳调度独立出来,避免被其他任务影响        heartbeatScheduler = Executors.newSingleThreadScheduledExecutor();        //SQL记录器        this.sqlRecorder = new SQLRecorder(config.getSystem().getSqlRecordCount());        /**         * 是否在线,MyCat manager中有命令控制         * | offline | Change MyCat status to OFF |         * | online | Change MyCat status to ON |         */        this.isOnline = new AtomicBoolean(true);        //缓存服务初始化        cacheService = new CacheService();        //路由计算初始化        routerService = new RouteService(cacheService);        // load datanode active index from properties        dnIndexProperties = loadDnIndexProps();        try {            //SQL解析器            sqlInterceptor = (SQLInterceptor) Class.forName(                    config.getSystem().getSqlInterceptor()).newInstance();        } catch (Exception e) {            throw new RuntimeException(e);        }        //catlet加载器        catletClassLoader = new DynaClassLoader(SystemConfig.getHomePath()                + File.separator + "catlet", config.getSystem().getCatletClassCheckSeconds());        //记录启动时间        this.startupTime = TimeUtil.currentTimeMillis();         if(isUseZkSwitch()) {             String path=     ZKUtils.getZKBasePath()+"lock/dnindex.lock";             dnindexLock = new InterProcessMutex(ZKUtils.getConnection(), path);         }    }
0 0
原创粉丝点击