Plugins: Simplify Plugin API for constructing modules

The Plugin interface currently contains 6 different methods for
adding modules. Elasticsearch has 3 different levels of injectors,
and for each of those, there are two methods. The first takes no
arguments and returns a collection of class objects to construct. The
second takes a Settings object and returns a collection of module
objects already constructed. The settings argument is unecessary because
the plugin can already get the settings from its constructor. Removing
that, the only difference between the two versions is returning an
already constructed Module, or a module Class, and there is no reason
the plugin can't construct all their modules themselves.

This change reduces the plugin api down to just 3 methods for adding
modules. Each returns a Collection<Module>. It also removes the
processModule method, which was unnecessary since onModule
implementations fullfill the same requirement. And finally, it renames
the modules() method to nodeModules() so it is clear these are created
once for each node.
This commit is contained in:
Ryan Ernst 2015-08-17 20:11:38 -07:00
parent 75ced057ed
commit 2bf84593e0
27 changed files with 100 additions and 322 deletions

View File

@ -260,7 +260,7 @@ public class TransportClient extends AbstractClient {
// ignore, might not be bounded // ignore, might not be bounded
} }
for (Class<? extends LifecycleComponent> plugin : injector.getInstance(PluginsService.class).services()) { for (Class<? extends LifecycleComponent> plugin : injector.getInstance(PluginsService.class).nodeServices()) {
injector.getInstance(plugin).close(); injector.getInstance(plugin).close();
} }
try { try {

View File

@ -230,7 +230,7 @@ public class Node implements Releasable {
// hack around dependency injection problem (for now...) // hack around dependency injection problem (for now...)
injector.getInstance(Discovery.class).setRoutingService(injector.getInstance(RoutingService.class)); injector.getInstance(Discovery.class).setRoutingService(injector.getInstance(RoutingService.class));
for (Class<? extends LifecycleComponent> plugin : pluginsService.services()) { for (Class<? extends LifecycleComponent> plugin : pluginsService.nodeServices()) {
injector.getInstance(plugin).start(); injector.getInstance(plugin).start();
} }
@ -297,7 +297,7 @@ public class Node implements Releasable {
injector.getInstance(RestController.class).stop(); injector.getInstance(RestController.class).stop();
injector.getInstance(TransportService.class).stop(); injector.getInstance(TransportService.class).stop();
for (Class<? extends LifecycleComponent> plugin : pluginsService.services()) { for (Class<? extends LifecycleComponent> plugin : pluginsService.nodeServices()) {
injector.getInstance(plugin).stop(); injector.getInstance(plugin).stop();
} }
// we should stop this last since it waits for resources to get released // we should stop this last since it waits for resources to get released
@ -364,7 +364,7 @@ public class Node implements Releasable {
stopWatch.stop().start("percolator_service"); stopWatch.stop().start("percolator_service");
injector.getInstance(PercolatorService.class).close(); injector.getInstance(PercolatorService.class).close();
for (Class<? extends LifecycleComponent> plugin : pluginsService.services()) { for (Class<? extends LifecycleComponent> plugin : pluginsService.nodeServices()) {
stopWatch.stop().start("plugin(" + plugin.getName() + ")"); stopWatch.stop().start("plugin(" + plugin.getName() + ")");
injector.getInstance(plugin).close(); injector.getInstance(plugin).close();
} }

View File

@ -19,20 +19,16 @@
package org.elasticsearch.plugins; package org.elasticsearch.plugins;
import com.google.common.collect.ImmutableList;
import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import java.io.Closeable; import java.io.Closeable;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
/** /**
* A base class for a plugin. * A base class for a plugin which returns no services or modules.
* <p/>
* A plugin can be dynamically injected with {@link Module} by implementing <tt>onModule(AnyModule)</tt> method
* removing the need to override {@link #processModule(org.elasticsearch.common.inject.Module)} and check using
* instanceof.
*/ */
public abstract class AbstractPlugin implements Plugin { public abstract class AbstractPlugin implements Plugin {
@ -40,40 +36,24 @@ public abstract class AbstractPlugin implements Plugin {
* Defaults to return an empty list. * Defaults to return an empty list.
*/ */
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
return ImmutableList.of(); return Collections.emptyList();
} }
/** /**
* Defaults to return an empty list. * Defaults to return an empty list.
*/ */
@Override @Override
public Collection<Module> modules(Settings settings) { public Collection<Class<? extends LifecycleComponent>> nodeServices() {
return ImmutableList.of(); return Collections.emptyList();
} }
/** /**
* Defaults to return an empty list. * Defaults to return an empty list.
*/ */
@Override @Override
public Collection<Class<? extends LifecycleComponent>> services() { public Collection<Module> indexModules() {
return ImmutableList.of(); return Collections.emptyList();
}
/**
* Defaults to return an empty list.
*/
@Override
public Collection<Class<? extends Module>> indexModules() {
return ImmutableList.of();
}
/**
* Defaults to return an empty list.
*/
@Override
public Collection<Module> indexModules(Settings settings) {
return ImmutableList.of();
} }
/** /**
@ -81,23 +61,15 @@ public abstract class AbstractPlugin implements Plugin {
*/ */
@Override @Override
public Collection<Class<? extends Closeable>> indexServices() { public Collection<Class<? extends Closeable>> indexServices() {
return ImmutableList.of(); return Collections.emptyList();
} }
/** /**
* Defaults to return an empty list. * Defaults to return an empty list.
*/ */
@Override @Override
public Collection<Class<? extends Module>> shardModules() { public Collection<Module> shardModules() {
return ImmutableList.of(); return Collections.emptyList();
}
/**
* Defaults to return an empty list.
*/
@Override
public Collection<Module> shardModules(Settings settings) {
return ImmutableList.of();
} }
/** /**
@ -105,12 +77,7 @@ public abstract class AbstractPlugin implements Plugin {
*/ */
@Override @Override
public Collection<Class<? extends Closeable>> shardServices() { public Collection<Class<? extends Closeable>> shardServices() {
return ImmutableList.of(); return Collections.emptyList();
}
@Override
public void processModule(Module module) {
// nothing to do here
} }
@Override @Override

View File

@ -19,18 +19,12 @@
package org.elasticsearch.plugins; package org.elasticsearch.plugins;
import com.google.common.collect.Lists;
import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.PreProcessModule; import org.elasticsearch.common.inject.PreProcessModule;
import org.elasticsearch.common.inject.SpawnModules; import org.elasticsearch.common.inject.SpawnModules;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import java.util.Collection;
import java.util.List;
import static org.elasticsearch.common.inject.Modules.createModule;
/** /**
* *
*/ */
@ -47,13 +41,7 @@ public class IndexPluginsModule extends AbstractModule implements SpawnModules,
@Override @Override
public Iterable<? extends Module> spawnModules() { public Iterable<? extends Module> spawnModules() {
List<Module> modules = Lists.newArrayList(); return pluginsService.indexModules();
Collection<Class<? extends Module>> modulesClasses = pluginsService.indexModules();
for (Class<? extends Module> moduleClass : modulesClasses) {
modules.add(createModule(moduleClass, settings));
}
modules.addAll(pluginsService.indexModules(settings));
return modules;
} }
@Override @Override

View File

@ -29,9 +29,8 @@ import java.util.Collection;
/** /**
* An extension point allowing to plug in custom functionality. * An extension point allowing to plug in custom functionality.
* <p/> * <p/>
* A plugin can be dynamically injected with {@link Module} by implementing <tt>onModule(AnyModule)</tt> method * A plugin can be register custom extensions to builtin behavior by implementing <tt>onModule(AnyModule)</tt>,
* removing the need to override {@link #processModule(org.elasticsearch.common.inject.Module)} and check using * and registering the extension with the given module.
* instanceof.
*/ */
public interface Plugin { public interface Plugin {
@ -46,31 +45,19 @@ public interface Plugin {
String description(); String description();
/** /**
* Node level modules (classes, will automatically be created). * Node level modules.
*/ */
Collection<Class<? extends Module>> modules(); Collection<Module> nodeModules();
/**
* Node level modules (instances)
*
* @param settings The node level settings.
*/
Collection<? extends Module> modules(Settings settings);
/** /**
* Node level services that will be automatically started/stopped/closed. * Node level services that will be automatically started/stopped/closed.
*/ */
Collection<Class<? extends LifecycleComponent>> services(); Collection<Class<? extends LifecycleComponent>> nodeServices();
/** /**
* Per index modules. * Per index modules.
*/ */
Collection<Class<? extends Module>> indexModules(); Collection<Module> indexModules();
/**
* Per index modules.
*/
Collection<? extends Module> indexModules(Settings settings);
/** /**
* Per index services that will be automatically closed. * Per index services that will be automatically closed.
@ -80,24 +67,13 @@ public interface Plugin {
/** /**
* Per index shard module. * Per index shard module.
*/ */
Collection<Class<? extends Module>> shardModules(); Collection<Module> shardModules();
/**
* Per index shard module.
*/
Collection<? extends Module> shardModules(Settings settings);
/** /**
* Per index shard service that will be automatically closed. * Per index shard service that will be automatically closed.
*/ */
Collection<Class<? extends Closeable>> shardServices(); Collection<Class<? extends Closeable>> shardServices();
/**
* Process a specific module. Note, its simpler to implement a custom <tt>onModule(AnyModule module)</tt>
* method, which will be automatically be called by the relevant type.
*/
void processModule(Module module);
/** /**
* Additional node settings loaded by the plugin. Note that settings that are explicit in the nodes settings can't be * Additional node settings loaded by the plugin. Note that settings that are explicit in the nodes settings can't be
* overwritten with the additional settings. These settings added if they don't exist. * overwritten with the additional settings. These settings added if they don't exist.

View File

@ -19,18 +19,12 @@
package org.elasticsearch.plugins; package org.elasticsearch.plugins;
import com.google.common.collect.Lists;
import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.PreProcessModule; import org.elasticsearch.common.inject.PreProcessModule;
import org.elasticsearch.common.inject.SpawnModules; import org.elasticsearch.common.inject.SpawnModules;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import java.util.Collection;
import java.util.List;
import static org.elasticsearch.common.inject.Modules.createModule;
/** /**
* *
*/ */
@ -47,13 +41,7 @@ public class PluginsModule extends AbstractModule implements SpawnModules, PrePr
@Override @Override
public Iterable<? extends Module> spawnModules() { public Iterable<? extends Module> spawnModules() {
List<Module> modules = Lists.newArrayList(); return pluginsService.nodeModules();
Collection<Class<? extends Module>> modulesClasses = pluginsService.modules();
for (Class<? extends Module> moduleClass : modulesClasses) {
modules.add(createModule(moduleClass, settings));
}
modules.addAll(pluginsService.modules(settings));
return modules;
} }
@Override @Override

View File

@ -184,7 +184,6 @@ public class PluginsService extends AbstractComponent {
public void processModule(Module module) { public void processModule(Module module) {
for (Tuple<PluginInfo, Plugin> plugin : plugins()) { for (Tuple<PluginInfo, Plugin> plugin : plugins()) {
plugin.v2().processModule(module);
// see if there are onModule references // see if there are onModule references
List<OnModuleReference> references = onModuleReferences.get(plugin.v2()); List<OnModuleReference> references = onModuleReferences.get(plugin.v2());
if (references != null) { if (references != null) {
@ -209,42 +208,26 @@ public class PluginsService extends AbstractComponent {
return builder.put(this.settings).build(); return builder.put(this.settings).build();
} }
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
List<Class<? extends Module>> modules = new ArrayList<>();
for (Tuple<PluginInfo, Plugin> plugin : plugins) {
modules.addAll(plugin.v2().modules());
}
return modules;
}
public Collection<Module> modules(Settings settings) {
List<Module> modules = new ArrayList<>(); List<Module> modules = new ArrayList<>();
for (Tuple<PluginInfo, Plugin> plugin : plugins) { for (Tuple<PluginInfo, Plugin> plugin : plugins) {
modules.addAll(plugin.v2().modules(settings)); modules.addAll(plugin.v2().nodeModules());
} }
return modules; return modules;
} }
public Collection<Class<? extends LifecycleComponent>> services() { public Collection<Class<? extends LifecycleComponent>> nodeServices() {
List<Class<? extends LifecycleComponent>> services = new ArrayList<>(); List<Class<? extends LifecycleComponent>> services = new ArrayList<>();
for (Tuple<PluginInfo, Plugin> plugin : plugins) { for (Tuple<PluginInfo, Plugin> plugin : plugins) {
services.addAll(plugin.v2().services()); services.addAll(plugin.v2().nodeServices());
} }
return services; return services;
} }
public Collection<Class<? extends Module>> indexModules() { public Collection<Module> indexModules() {
List<Class<? extends Module>> modules = new ArrayList<>();
for (Tuple<PluginInfo, Plugin> plugin : plugins) {
modules.addAll(plugin.v2().indexModules());
}
return modules;
}
public Collection<Module> indexModules(Settings settings) {
List<Module> modules = new ArrayList<>(); List<Module> modules = new ArrayList<>();
for (Tuple<PluginInfo, Plugin> plugin : plugins) { for (Tuple<PluginInfo, Plugin> plugin : plugins) {
modules.addAll(plugin.v2().indexModules(settings)); modules.addAll(plugin.v2().indexModules());
} }
return modules; return modules;
} }
@ -257,18 +240,10 @@ public class PluginsService extends AbstractComponent {
return services; return services;
} }
public Collection<Class<? extends Module>> shardModules() { public Collection<Module> shardModules() {
List<Class<? extends Module>> modules = new ArrayList<>();
for (Tuple<PluginInfo, Plugin> plugin : plugins) {
modules.addAll(plugin.v2().shardModules());
}
return modules;
}
public Collection<Module> shardModules(Settings settings) {
List<Module> modules = new ArrayList<>(); List<Module> modules = new ArrayList<>();
for (Tuple<PluginInfo, Plugin> plugin : plugins) { for (Tuple<PluginInfo, Plugin> plugin : plugins) {
modules.addAll(plugin.v2().shardModules(settings)); modules.addAll(plugin.v2().shardModules());
} }
return modules; return modules;
} }

View File

@ -19,18 +19,12 @@
package org.elasticsearch.plugins; package org.elasticsearch.plugins;
import com.google.common.collect.Lists;
import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.PreProcessModule; import org.elasticsearch.common.inject.PreProcessModule;
import org.elasticsearch.common.inject.SpawnModules; import org.elasticsearch.common.inject.SpawnModules;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import java.util.Collection;
import java.util.List;
import static org.elasticsearch.common.inject.Modules.createModule;
/** /**
* *
*/ */
@ -47,13 +41,7 @@ public class ShardsPluginsModule extends AbstractModule implements SpawnModules,
@Override @Override
public Iterable<? extends Module> spawnModules() { public Iterable<? extends Module> spawnModules() {
List<Module> modules = Lists.newArrayList(); return pluginsService.shardModules();
Collection<Class<? extends Module>> modulesClasses = pluginsService.shardModules();
for (Class<? extends Module> moduleClass : modulesClasses) {
modules.add(createModule(moduleClass, settings));
}
modules.addAll(pluginsService.shardModules(settings));
return modules;
} }
@Override @Override

View File

@ -19,16 +19,8 @@
package org.elasticsearch.plugins; package org.elasticsearch.plugins;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.settings.Settings;
import java.io.Closeable;
import java.util.Collection;
import java.util.Collections;
/** A site-only plugin, just serves resources */ /** A site-only plugin, just serves resources */
final class SitePlugin implements Plugin { final class SitePlugin extends AbstractPlugin {
final String name; final String name;
final String description; final String description;
@ -46,58 +38,4 @@ final class SitePlugin implements Plugin {
public String description() { public String description() {
return description; return description;
} }
@Override
public Collection<Class<? extends Module>> modules() {
return Collections.emptyList();
}
@Override
public Collection<? extends Module> modules(Settings settings) {
return Collections.emptyList();
}
@Override
public Collection<Class<? extends LifecycleComponent>> services() {
return Collections.emptyList();
}
@Override
public Collection<Class<? extends Module>> indexModules() {
return Collections.emptyList();
}
@Override
public Collection<? extends Module> indexModules(Settings settings) {
return Collections.emptyList();
}
@Override
public Collection<Class<? extends Closeable>> indexServices() {
return Collections.emptyList();
}
@Override
public Collection<Class<? extends Module>> shardModules() {
return Collections.emptyList();
}
@Override
public Collection<? extends Module> shardModules(Settings settings) {
return Collections.emptyList();
}
@Override
public Collection<Class<? extends Closeable>> shardServices() {
return Collections.emptyList();
}
@Override
public void processModule(Module module) {
}
@Override
public Settings additionalSettings() {
return Settings.EMPTY;
}
} }

View File

@ -1005,7 +1005,7 @@ public class ClusterServiceIT extends ESIntegTestCase {
} }
@Override @Override
public Collection<Class<? extends LifecycleComponent>> services() { public Collection<Class<? extends LifecycleComponent>> nodeServices() {
List<Class<? extends LifecycleComponent>> services = new ArrayList<>(1); List<Class<? extends LifecycleComponent>> services = new ArrayList<>(1);
services.add(MasterAwareService.class); services.add(MasterAwareService.class);
return services; return services;

View File

@ -31,6 +31,7 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.junit.Test; import org.junit.Test;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newArrayList;
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
@ -67,10 +68,8 @@ public class SettingsFilteringIT extends ESIntegTestCase {
} }
@Override @Override
public Collection<Class<? extends Module>> indexModules() { public Collection<Module> indexModules() {
Collection<Class<? extends Module>> modules = newArrayList(); return Collections.<Module>singletonList(new SettingsFilteringModule());
modules.add(SettingsFilteringModule.class);
return modules;
} }
} }

View File

@ -23,30 +23,23 @@ import org.elasticsearch.common.inject.Module;
import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.plugins.AbstractPlugin;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newArrayList;
public class ExternalMapperPlugin extends AbstractPlugin { public class ExternalMapperPlugin extends AbstractPlugin {
/**
* The name of the plugin.
*/
@Override @Override
public String name() { public String name() {
return "external-mappers"; return "external-mappers";
} }
/**
* The description of the plugin.
*/
@Override @Override
public String description() { public String description() {
return "External Mappers Plugin"; return "External Mappers Plugin";
} }
@Override @Override
public Collection<Class<? extends Module>> indexModules() { public Collection<Module> indexModules() {
Collection<Class<? extends Module>> modules = newArrayList(); return Collections.<Module>singletonList(new ExternalIndexModule());
modules.add(ExternalIndexModule.class);
return modules;
} }
} }

View File

@ -23,9 +23,8 @@ import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.test.engine.MockEngineFactory; import org.elasticsearch.test.engine.MockEngineFactory;
import org.elasticsearch.test.engine.MockEngineSupportModule; import org.elasticsearch.test.engine.MockEngineSupportModule;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.Collections;
// this must exist in the same package as IndexShardModule to allow access to setting the impl // this must exist in the same package as IndexShardModule to allow access to setting the impl
public class MockEngineFactoryPlugin extends AbstractPlugin { public class MockEngineFactoryPlugin extends AbstractPlugin {
@ -38,10 +37,8 @@ public class MockEngineFactoryPlugin extends AbstractPlugin {
return "a mock engine factory for testing"; return "a mock engine factory for testing";
} }
@Override @Override
public Collection<Class<? extends Module>> indexModules() { public Collection<Module> indexModules() {
List<Class<? extends Module>> modules = new ArrayList<>(); return Collections.<Module>singletonList(new MockEngineSupportModule());
modules.add(MockEngineSupportModule.class);
return modules;
} }
public void onModule(IndexShardModule module) { public void onModule(IndexShardModule module) {
module.engineFactoryImpl = MockEngineFactory.class; module.engineFactoryImpl = MockEngineFactory.class;

View File

@ -19,12 +19,12 @@
package org.elasticsearch.indices.analysis; package org.elasticsearch.indices.analysis;
import com.google.common.collect.ImmutableList;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.AnalysisModule;
import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.plugins.AbstractPlugin;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
public class DummyAnalysisPlugin extends AbstractPlugin { public class DummyAnalysisPlugin extends AbstractPlugin {
/** /**
@ -44,8 +44,8 @@ public class DummyAnalysisPlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
return ImmutableList.<Class<? extends Module>>of(DummyIndicesAnalysisModule.class); return Collections.<Module>singletonList(new DummyIndicesAnalysisModule());
} }
public void onModule(AnalysisModule module) { public void onModule(AnalysisModule module) {

View File

@ -128,14 +128,10 @@ public class CustomScriptContextIT extends ESIntegTestCase {
return "Custom script context plugin"; return "Custom script context plugin";
} }
@Override public void onModule(ScriptModule scriptModule) {
public void processModule(Module module) { scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_op"));
if (module instanceof ScriptModule) { scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op"));
ScriptModule scriptModule = (ScriptModule) module; scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op"));
scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_op"));
scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op"));
scriptModule.registerScriptContext(new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op"));
}
} }
} }
} }

View File

@ -27,6 +27,7 @@ import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.RepositoriesModule;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newArrayList;
@ -47,10 +48,8 @@ public class MockRepositoryPlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
Collection<Class<? extends Module>> modules = newArrayList(); return Collections.<Module>singletonList(new SettingsFilteringModule());
modules.add(SettingsFilteringModule.class);
return modules;
} }
public static class SettingsFilteringModule extends AbstractModule { public static class SettingsFilteringModule extends AbstractModule {

View File

@ -378,10 +378,8 @@ public class ContextAndHeaderTransportIT extends ESIntegTestCase {
} }
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
Collection<Class<? extends Module>> classes = new ArrayList<>(); return Collections.<Module>singletonList(new ActionLoggingModule());
classes.add(ActionLoggingModule.class);
return classes;
} }
} }

View File

@ -27,6 +27,7 @@ import org.elasticsearch.plugins.AbstractPlugin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
/** /**
* *
@ -44,10 +45,8 @@ public class AnalysisICUPlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
Collection<Class<? extends Module>> classes = new ArrayList<>(); return Collections.<Module>singletonList(new IcuIndicesAnalysisModule());
classes.add(IcuIndicesAnalysisModule.class);
return classes;
} }
/** /**

View File

@ -20,12 +20,21 @@
package org.elasticsearch.plugin.analysis.kuromoji; package org.elasticsearch.plugin.analysis.kuromoji;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.index.analysis.*; import org.elasticsearch.index.analysis.AnalysisModule;
import org.elasticsearch.index.analysis.JapaneseStopTokenFilterFactory;
import org.elasticsearch.index.analysis.KuromojiAnalyzerProvider;
import org.elasticsearch.index.analysis.KuromojiBaseFormFilterFactory;
import org.elasticsearch.index.analysis.KuromojiIterationMarkCharFilterFactory;
import org.elasticsearch.index.analysis.KuromojiKatakanaStemmerFactory;
import org.elasticsearch.index.analysis.KuromojiPartOfSpeechFilterFactory;
import org.elasticsearch.index.analysis.KuromojiReadingFormFilterFactory;
import org.elasticsearch.index.analysis.KuromojiTokenizerFactory;
import org.elasticsearch.indices.analysis.KuromojiIndicesAnalysisModule; import org.elasticsearch.indices.analysis.KuromojiIndicesAnalysisModule;
import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.plugins.AbstractPlugin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
/** /**
* *
@ -43,10 +52,8 @@ public class AnalysisKuromojiPlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
Collection<Class<? extends Module>> classes = new ArrayList<>(); return Collections.<Module>singletonList(new KuromojiIndicesAnalysisModule());
classes.add(KuromojiIndicesAnalysisModule.class);
return classes;
} }
public void onModule(AnalysisModule module) { public void onModule(AnalysisModule module) {

View File

@ -27,6 +27,7 @@ import org.elasticsearch.plugins.AbstractPlugin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
/** /**
* *
@ -44,10 +45,8 @@ public class AnalysisSmartChinesePlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
Collection<Class<? extends Module>> classes = new ArrayList<>(); return Collections.<Module>singletonList(new SmartChineseIndicesAnalysisModule());
classes.add(SmartChineseIndicesAnalysisModule.class);
return classes;
} }
public void onModule(AnalysisModule module) { public void onModule(AnalysisModule module) {

View File

@ -43,10 +43,8 @@ public class AnalysisStempelPlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
Collection<Class<? extends Module>> classes = new ArrayList<>(); return Collections.<Module>singletonList(new PolishIndicesAnalysisModule());
classes.add(PolishIndicesAnalysisModule.class);
return classes;
} }
public void onModule(AnalysisModule module) { public void onModule(AnalysisModule module) {

View File

@ -56,7 +56,7 @@ public class CloudAwsPlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Module> modules(Settings settings) { public Collection<Module> nodeModules() {
Collection<Module> modules = new ArrayList<>(); Collection<Module> modules = new ArrayList<>();
if (settings.getAsBoolean("cloud.enabled", true)) { if (settings.getAsBoolean("cloud.enabled", true)) {
modules.add(new AwsModule()); modules.add(new AwsModule());
@ -65,7 +65,7 @@ public class CloudAwsPlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Class<? extends LifecycleComponent>> services() { public Collection<Class<? extends LifecycleComponent>> nodeServices() {
Collection<Class<? extends LifecycleComponent>> services = new ArrayList<>(); Collection<Class<? extends LifecycleComponent>> services = new ArrayList<>();
if (settings.getAsBoolean("cloud.enabled", true)) { if (settings.getAsBoolean("cloud.enabled", true)) {
services.add(AwsModule.getS3ServiceImpl()); services.add(AwsModule.getS3ServiceImpl());

View File

@ -36,6 +36,7 @@ import org.elasticsearch.repositories.azure.AzureRepositoryModule;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import static org.elasticsearch.cloud.azure.AzureModule.isSnapshotReady; import static org.elasticsearch.cloud.azure.AzureModule.isSnapshotReady;
@ -63,20 +64,16 @@ public class CloudAzurePlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
Collection<Class<? extends Module>> modules = new ArrayList<>(); List<Module> modules = new ArrayList<>();
if (AzureModule.isCloudReady(settings)) { if (AzureModule.isCloudReady(settings)) {
modules.add(AzureModule.class); modules.add(new AzureModule(settings));
} }
return modules; return modules;
} }
@Override public void onModule(RepositoriesModule module) {
public void processModule(Module module) { module.registerRepository(AzureRepository.TYPE, AzureRepositoryModule.class);
if (isSnapshotReady(settings, logger)
&& module instanceof RepositoriesModule) {
((RepositoriesModule)module).registerRepository(AzureRepository.TYPE, AzureRepositoryModule.class);
}
} }
public void onModule(DiscoveryModule discoveryModule) { public void onModule(DiscoveryModule discoveryModule) {

View File

@ -29,6 +29,7 @@ import org.elasticsearch.plugins.AbstractPlugin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
/** /**
* *
@ -52,16 +53,16 @@ public class CloudGcePlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
Collection<Class<? extends Module>> modules = new ArrayList<>(); List<Module> modules = new ArrayList<>();
if (settings.getAsBoolean("cloud.enabled", true)) { if (settings.getAsBoolean("cloud.enabled", true)) {
modules.add(GceModule.class); modules.add(new GceModule());
} }
return modules; return modules;
} }
@Override @Override
public Collection<Class<? extends LifecycleComponent>> services() { public Collection<Class<? extends LifecycleComponent>> nodeServices() {
Collection<Class<? extends LifecycleComponent>> services = new ArrayList<>(); Collection<Class<? extends LifecycleComponent>> services = new ArrayList<>();
if (settings.getAsBoolean("cloud.enabled", true)) { if (settings.getAsBoolean("cloud.enabled", true)) {
services.add(GceModule.getComputeServiceImpl()); services.add(GceModule.getComputeServiceImpl());

View File

@ -20,11 +20,10 @@
package org.elasticsearch.plugin.deletebyquery; package org.elasticsearch.plugin.deletebyquery;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.plugins.AbstractPlugin;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
public class DeleteByQueryPlugin extends AbstractPlugin { public class DeleteByQueryPlugin extends AbstractPlugin {
@ -41,7 +40,7 @@ public class DeleteByQueryPlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Module> modules(Settings settings) { public Collection<Module> nodeModules() {
return Arrays.asList((Module) new DeleteByQueryModule()); return Collections.<Module>singletonList(new DeleteByQueryModule());
} }
} }

View File

@ -25,7 +25,6 @@ import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.inject.multibindings.Multibinder;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.RepositoriesModule;
import org.elasticsearch.rest.action.cat.AbstractCatAction; import org.elasticsearch.rest.action.cat.AbstractCatAction;
@ -56,31 +55,18 @@ public class JvmExamplePlugin implements Plugin {
} }
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Module> nodeModules() {
Collection<Class<? extends Module>> modules = new ArrayList<>(); return Collections.<Module>singletonList(new ConfiguredExampleModule());
modules.add(ConfiguredExampleModule.class);
return modules;
} }
@Override @Override
public Collection<Module> modules(Settings settings) { public Collection<Class<? extends LifecycleComponent>> nodeServices() {
Collection<Module> modules = new ArrayList<>();
return modules;
}
@Override
public Collection<Class<? extends LifecycleComponent>> services() {
Collection<Class<? extends LifecycleComponent>> services = new ArrayList<>(); Collection<Class<? extends LifecycleComponent>> services = new ArrayList<>();
return services; return services;
} }
@Override @Override
public Collection<Class<? extends Module>> indexModules() { public Collection<Module> indexModules() {
return Collections.emptyList();
}
@Override
public Collection<? extends Module> indexModules(Settings settings) {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -90,12 +76,7 @@ public class JvmExamplePlugin implements Plugin {
} }
@Override @Override
public Collection<Class<? extends Module>> shardModules() { public Collection<Module> shardModules() {
return Collections.emptyList();
}
@Override
public Collection<? extends Module> shardModules(Settings settings) {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -104,11 +85,6 @@ public class JvmExamplePlugin implements Plugin {
return Collections.emptyList(); return Collections.emptyList();
} }
@Override
public void processModule(Module module) {
}
@Override @Override
public Settings additionalSettings() { public Settings additionalSettings() {
return Settings.EMPTY; return Settings.EMPTY;

View File

@ -38,8 +38,8 @@ public class MapperSizePlugin extends AbstractPlugin {
} }
@Override @Override
public Collection<Class<? extends Module>> indexModules() { public Collection<Module> indexModules() {
return Collections.<Class<? extends Module>>singleton(MapperSizeIndexModule.class); return Collections.<Module>singletonList(new MapperSizeIndexModule());
} }
} }