Plugins: Add some basic services to createComponents

This adds the first few basic services needed for any plugin to create
its own components that interact with the rest of the system.
This commit is contained in:
Ryan Ernst 2016-07-11 23:16:23 -07:00
parent 7195d1e0ff
commit 86d0d67036
3 changed files with 36 additions and 33 deletions

View File

@ -303,7 +303,9 @@ public class Node implements Closeable {
resourcesToClose.add(bigArrays);
modules.add(settingsModule);
client = new NodeClient(settings, threadPool);
Collection<Object> pluginComponents = pluginsService.createComponenents();
Collection<Object> pluginComponents = pluginsService.filterPlugins(Plugin.class).stream()
.flatMap(p -> p.createComponents(client, clusterService, threadPool).stream())
.collect(Collectors.toList());
modules.add(b -> {
b.bind(PluginsService.class).toInstance(pluginsService);
b.bind(Client.class).toInstance(client);

View File

@ -19,8 +19,13 @@
package org.elasticsearch.plugins;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.elasticsearch.action.ActionModule;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.settings.Setting;
@ -30,10 +35,7 @@ import org.elasticsearch.index.IndexModule;
import org.elasticsearch.indices.analysis.AnalysisModule;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.threadpool.ExecutorBuilder;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.elasticsearch.threadpool.ThreadPool;
/**
* An extension point allowing to plug in custom functionality.
@ -65,13 +67,17 @@ public abstract class Plugin {
}
/**
* Returns components maintained by this plugin.
* Returns components added by this plugin.
*
* Any components returned that implement {@link LifecycleComponent} will have their lifecycle managed.
* Note: To aid in the migration away from guice, all objects returned as components will be bound in guice
* to themselves.
*
* @param client A client to make requests to the system
* @param clusterService A service to allow watching and updating cluster state
* @param threadPool A service to allow retrieving an executor to run an async action
*/
public Collection<Object> createComponents() {
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool) {
return Collections.emptyList();
}

View File

@ -19,6 +19,26 @@
package org.elasticsearch.plugins;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.lucene.analysis.util.CharFilterFactory;
import org.apache.lucene.analysis.util.TokenFilterFactory;
import org.apache.lucene.analysis.util.TokenizerFactory;
@ -42,26 +62,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.threadpool.ExecutorBuilder;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import static org.elasticsearch.common.io.FileSystemUtils.isAccessibleDirectory;
/**
@ -293,11 +293,6 @@ public class PluginsService extends AbstractComponent {
return services;
}
/** Gets components from each plugin. This method should be called exactly once. */
public Collection<Object> createComponenents() {
return plugins.stream().flatMap(p -> p.v2().createComponents().stream()).collect(Collectors.toList());
}
public void onIndexModule(IndexModule indexModule) {
for (Tuple<PluginInfo, Plugin> plugin : plugins) {
plugin.v2().onIndexModule(indexModule);