mycat源码解析

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值