首页 > 其他分享 >graylog 插件模型之PluginModule

graylog 插件模型之PluginModule

时间:2022-10-01 08:55:15浏览次数:80  
标签:插件 graylog2 server graylog PluginModule loader class

graylog 的PluginModule 可以简化graylog 插件的开发,方便我们进行扩展

参考功能

  • 类结构
    从下图可以看出是依赖了guice 进行的包装,代码中好多都是支持依赖PluginModule开发的,PluginModule 提供了功能模块bean 的注册

 

 

  • 包含的能力
    从下图可以看出,提供的功能还是不少的,核心都是关于bean 注册的,利用了guice 的多bena binding,包含了消息处理,权限处理,通道处理,编码处理等功能

 

 

PluginModule 的使用

PluginModule 是有Plugin 接口实现使用的,如下图

 

 

插件的加载

插件加载并没有多少太复杂的东西,基于了spi 处理

  • 参考代码
 
public Set<Plugin> loadPlugins() {
    return ImmutableSortedSet.orderedBy(new PluginComparator())
            .addAll(Iterables.transform(loadJarPlugins(), new PluginAdapterFunction()))
            .addAll(Iterables.transform(loadClassPathPlugins(), new PluginAdapterFunction()))
            .build();
}

以上包含了基于jar 的以及classpath 的,同时也进行了类隔离的处理(包含共享以及独立)

final List<URL> sharedClassLoaderUrls = new ArrayList<>();
        urls.forEach(url -> {
            final PluginProperties properties = PluginProperties.fromJarFile(url.getFile());
 
            // Decide whether to create a separate, isolated class loader for the plugin. When the plugin is isolated
            // (the default), it gets its own class loader and cannot see other plugins. Plugins which are not
            // isolated share one class loader so they can see each other. (makes plugin inter-dependencies work)
            if (properties.isIsolated()) {
                LOG.debug("Creating isolated class loader for <{}>", url);
                classLoader.addClassLoader(URLClassLoader.newInstance(new URL[]{url}));
            } else {
                LOG.debug("Using shared class loader for <{}>", url);
                sharedClassLoaderUrls.add(url);
            }
        });
 
        // Only create the shared class loader if any plugin requests to be shared.
        if (!sharedClassLoaderUrls.isEmpty()) {
            LOG.debug("Creating shared class loader for {} plugins: {}", sharedClassLoaderUrls.size(), sharedClassLoaderUrls);
            classLoader.addClassLoader(URLClassLoader.newInstance(sharedClassLoaderUrls.toArray(new URL[0])));
        }
 
        final ServiceLoader<Plugin> pluginServiceLoader = ServiceLoader.load(Plugin.class, classLoader);
 
        return ImmutableSet.copyOf(pluginServiceLoader);

说明

graylog 一开guice 进行插件化的处理,使用比较方便,包装的功能丰富

参考资料

https://github.com/Graylog2/graylog2-server
https://github.com/Graylog2/graylog2-server/blob/626be1f0d80506705b5ba41fbea33c2ec0164bc0/graylog2-server/src/main/java/org/graylog2/shared/plugins/PluginLoader.java
https://github.com/Graylog2/graylog2-server/blob/626be1f0d80506705b5ba41fbea33c2ec0164bc0/graylog2-server/src/main/java/org/graylog2/plugin/Plugin.java
https://github.com/Graylog2/graylog2-server/blob/626be1f0d80506705b5ba41fbea33c2ec0164bc0/graylog2-server/src/main/java/org/graylog2/shared/plugins/ChainingClassLoader.java

标签:插件,graylog2,server,graylog,PluginModule,loader,class
From: https://www.cnblogs.com/rongfengliang/p/16746736.html

相关文章

  • graylog grn介绍
    grn是graylog的资源名称,属于一种urn,从功能上类似aws的arn主要用来进行权限以及资源分配管理参考格式grn:<cluster>:<tenant>:<scope>:<type>:<entity>......
  • nonebot2插件入门-你的第一个机器人插件(发送文字消息)
    机器人需要各种插件来实现各种功能,只有个机器人框架是不够的。......
  • vue element-ui 基本使用和按需加载的2种方式(推荐安装插件的方式)
    element-ui官网:https://element.eleme.cn/#/zh-CN/component/installation 安装npminstallelement-ui-S不太清楚这里为什么是-S的朋友可以看看我的这篇文章......
  • 浏览器必备的上网工具,同样也是收藏党必备工具, 网页图片收藏工具,可以收藏全网的网页图
    浏览器必备的上网工具,同样也是收藏党必备工具,网页图片收藏工具,可以收藏全网的网页图片,无需下载到本地了,太方便了工具名称:BdTab新标签页插件,支持图片收藏......
  • v-viewer图片预览插件使用
    链接:https://www.jianshu.com/p/1fd3b4e6911c今天介绍一款用于图片浏览的Vue组件,支持旋转、缩放、翻转等操作,它是基于viewer.js做的二次开发,我感觉用起来挺方便的,Github......
  • chrome插件下载地址
    收藏猫:https://chrome.pictureknow.com/Chrome官方应用店只支持在线安装不支持将安装包.crx保存到本地,我们可以通过第三方Chrome扩展插件下载网站获取需要的.crx安装......
  • 分享一个Vue实现图片水平瀑布流的插件
    这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助一.需求来源今天碰到了一个需求,需要在页面里,用水平瀑布流的方式,将一些图片进行加载,这让我突然想起我很久......
  • Vue插件
    Vue插件插件作用插件通常用来为Vue添加全局功能例如:1、添加全局资源:指令/过滤器/过渡等。如vue-touch2、通过全局混入来添加一些组件选项。3、添加Vue实例方法,......
  • spotbugs插件汉化
    spotbugs-translatespotbugs汉化,目前使用百度翻译进行机翻已经汉化好的插件(使用IDEA的InstallPluginfromDisk选择zip文件再重新安装):https://github.com/tyzou/spotb......
  • VUE2速成-5(插件及打包)
    文章目录​​一、Vue的插件大全​​​​二、Vue插件举例​​​​1.轮播图插件(vue-awesome-swiper)​​​​2.UI组件库(ElementUI)​​​​三、vue-cli打包部署​​一、Vue的......