Search in sources :

Example 1 with PluginBinder

use of org.apache.inlong.manager.workflow.plugin.PluginBinder in project incubator-inlong by apache.

the class PluginService method pluginReload.

/**
 * Reload the plugin from the plugin path
 */
public void pluginReload() {
    Path path = Paths.get(pluginLoc).toAbsolutePath();
    log.info("search for plugin in {}", path);
    if (!path.toFile().exists()) {
        log.warn("plugin directory not found");
        return;
    }
    PluginClassLoader pluginLoader = PluginClassLoader.getFromPluginUrl(path.toString(), Thread.currentThread().getContextClassLoader());
    Map<String, PluginDefinition> pluginDefinitions = pluginLoader.getPluginDefinitions();
    if (MapUtils.isEmpty(pluginDefinitions)) {
        log.warn("pluginDefinition not found in {}", pluginLoc);
        return;
    }
    List<Plugin> plugins = new ArrayList<>();
    for (PluginDefinition pluginDefinition : pluginDefinitions.values()) {
        String pluginClassName = pluginDefinition.getPluginClass();
        try {
            Class<?> pluginClass = pluginLoader.loadClass(pluginClassName);
            Object plugin = pluginClass.getDeclaredConstructor().newInstance();
            plugins.add((Plugin) plugin);
        } catch (Throwable e) {
            throw new RuntimeException(e.getMessage());
        }
    }
    this.plugins.addAll(plugins);
    for (PluginBinder pluginBinder : pluginBinders) {
        for (Plugin plugin : plugins) {
            log.info(String.format("PluginBinder:%s load Plugin:%s", pluginBinder.getClass().getSimpleName(), plugin.getClass().getSimpleName()));
            pluginBinder.acceptPlugin(plugin);
        }
    }
}
Also used : Path(java.nio.file.Path) PluginBinder(org.apache.inlong.manager.workflow.plugin.PluginBinder) ArrayList(java.util.ArrayList) PluginDefinition(org.apache.inlong.manager.workflow.plugin.PluginDefinition) Plugin(org.apache.inlong.manager.workflow.plugin.Plugin)

Aggregations

Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Plugin (org.apache.inlong.manager.workflow.plugin.Plugin)1 PluginBinder (org.apache.inlong.manager.workflow.plugin.PluginBinder)1 PluginDefinition (org.apache.inlong.manager.workflow.plugin.PluginDefinition)1