第三章 shardingsphere源码-项目启动前到底干了些什么?

本文详细描述了SpringBoot项目启动时,如何加载配置文件、解析配置对象、进行持久化,并利用SPI机制降低耦合度的过程,特别关注了ProxyConfigurationLoader和ContextManager的初始化工作。


一、项目启动核心源码

上一篇文章说了项目是如何启动的,仍然与springboot一样,找到启动类Bootstarp.java,本篇讲讲启动之前到底干了些什么,还是使用的web服务器吗如tomcat等?

1.ProxyConfigurationLoader.load 就是将我们填写的配置文件server.yaml 或者 config-encrypt.yaml 来解析出来封装为YamlProxyConfiguration 对象。
2.下面的port 、addresses 都是配置文件中定义的,项目的端口是什么
3.核心方法 new BootstrapInitializer().init 初始化了些什么,具体参考下面
4.new ShardingSphereProxy().start(port, addresses); 使用了netty作为服务器

    public static void main(final String[] args) throws IOException, SQLException {
   
   
        BootstrapArguments bootstrapArgs = new BootstrapArguments(args);
        // 读取配置文件,创建Yaml对象
        YamlProxyConfiguration yamlConfig = ProxyConfigurationLoader.load(bootstrapArgs.getConfigurationPath());
        int port = bootstrapArgs.getPort().orElseGet(() -> new ConfigurationProperties(yamlConfig.getServerConfiguration().getProps()).getValue(ConfigurationPropertyKey.PROXY_DEFAULT_PORT));
        List<String> addresses = bootstrapArgs.getAddresses();
        // 初始化 -如:将配置持久化到存储设备等等
        new BootstrapInitializer().init(yamlConfig, port, bootstrapArgs.getForce());
        boolean cdcEnabled = null != yamlConfig.getServerConfiguration().getCdc() && yamlConfig.getServerConfiguration().getCdc().isEnabled();
        if (cdcEnabled) {
   
   
            new CDCServer(addresses, yamlConfig.getServerConfiguration().getCdc().getPort()).start();
        }
        // 类似netty启动,里面注册了很多消息处理器,规定了客户端发送消息服务端到底如何接收
        new ShardingSphereProxy().start(port, addresses);
    }

1.核心方法 new BootstrapInitializer().init

其中唯一的核心方法就是createContextManager(proxyConfig, modeConfig, port, force);创建上下文的管理器,剩下的几乎都是将配置信息封装为元数据对象。

    public void init(final YamlProxyConfiguration yamlConfig, final int port, final boolean force) throws 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值