skywalking~插件加载

插件加载的入口

new PluginFinder(new PluginBootstrap().loadPlugins());

加载插件过程
public List loadPlugins() throws AgentPackageNotFoundException {
        //1.初始化类加载器
        AgentClassLoader.initDefaultLoader();

        //2.获取插件集合文件地址url
        PluginResourcesResolver resolver = new PluginResourcesResolver();
        List resources = resolver.getResources();

        if (resources == null || resources.size() == 0) {
            LOGGER.info("no plugin files (skywalking-plugin.def) found, continue to start application.");
            return new ArrayList();
        }

        //3.通过url解析插件
        for (URL pluginUrl : resources) {
            try {
                LOGGER.info("loading pluginUrl:{}",pluginUrl);
                PluginCfg.INSTANCE.load(pluginUrl.openStream());
            } catch (Throwable t) {
                LOGGER.error(t, "plugin file [{}] init failure.", pluginUrl);
            }
        }

        //3.获取定义类实体,加载插件对象
        List pluginClassList = PluginCfg.INSTANCE.getPluginClassList();

        List plugins = new ArrayList();
        for (PluginDefine pluginDefine : pluginClassList) {
            try {
                LOGGER.debug("loading plugin class {}.", pluginDefine.getDefineClass());
                AbstractClassEnhancePluginDefine plugin = (AbstractClassEnhancePluginDefine) Class.forName(pluginDefine.getDefineClass(), true, AgentClassLoader
                    .getDefault()).newInstance();
                plugins.add(plugin);
            } catch (Throwable t) {
     

你可能感兴趣的:(skywalking,java,skywalking,java)