欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【dolphinscheduler之MasterServer 启动分析】

程序员文章站 2022-03-01 20:12:51
...

/**

 *  master server

 */

@ComponentScan(value = "org.apache.dolphinscheduler", excludeFilters = {

        @ComponentScan.Filter(type = FilterType.REGEX, pattern = {

                "org.apache.dolphinscheduler.server.worker.*",

                "org.apache.dolphinscheduler.server.monitor.*",

                "org.apache.dolphinscheduler.server.log.*"

        })

})

@EnableTransactionManagement

public class MasterServer implements IStoppable {

 

    /**

     * master server startup, not use web service

     *

     * @param args arguments

     */

    public static void main(String[] args) {

        Thread.currentThread().setName(Constants.THREAD_NAME_MASTER_SERVER);

        new SpringApplicationBuilder(MasterServer.class).web(WebApplicationType.NONE).run(args);

    }

 

    /**

     * run master server

     */

    @PostConstruct

    public void run() {

        // init remoting server

        NettyServerConfig serverConfig = new NettyServerConfig();

        serverConfig.setListenPort(masterConfig.getListenPort());

        this.nettyRemotingServer = new NettyRemotingServer(serverConfig);

        this.nettyRemotingServer.registerProcessor(CommandType.TASK_EXECUTE_RESPONSE, new TaskResponseProcessor());

        this.nettyRemotingServer.registerProcessor(CommandType.TASK_EXECUTE_ACK, new TaskAckProcessor());

        this.nettyRemotingServer.registerProcessor(CommandType.TASK_KILL_RESPONSE, new TaskKillResponseProcessor());

        this.nettyRemotingServer.start();

 

        // self tolerant

        this.zkMasterClient.start();

        this.zkMasterClient.setStoppable(this);

 

        // scheduler start

        this.masterSchedulerService.start();

 

        // start QuartzExecutors

        // what system should do if exception

        try {

            logger.info("start Quartz server...");

            QuartzExecutors.getInstance().start();

        } catch (Exception e) {

            try {

                QuartzExecutors.getInstance().shutdown();

            } catch (SchedulerException e1) {

                logger.error("QuartzExecutors shutdown failed : " + e1.getMessage(), e1);

            }

            logger.error("start Quartz failed", e);

        }

 

        /**

         * register hooks, which are called before the process exits

         */

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {

            if (Stopper.isRunning()) {

                close("shutdownHook");

            }

        }));

 

    }

 

 

代码来自dolphinscheduler版本1.3.6