Skip to content

Commit

Permalink
Internal: Remove SpawnModules
Browse files Browse the repository at this point in the history
The last use case of spawn modules was for plugins. This change handles
plugin modules directly, and removes SpawnModules.

closes elastic#12783
  • Loading branch information
rjernst committed Aug 21, 2015
1 parent 47a0296 commit 2a726fe
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -132,7 +133,7 @@ public TransportClient build() {
try {
ModulesBuilder modules = new ModulesBuilder();
modules.add(new Version.Module(version));
modules.add(new PluginsModule(this.settings, pluginsService));
modules.add(new PluginsModule(pluginsService));
modules.add(new EnvironmentModule(environment));
modules.add(new SettingsModule(this.settings));
modules.add(new NetworkModule());
Expand All @@ -149,6 +150,11 @@ protected void configure() {
modules.add(new ClientTransportModule());
modules.add(new CircuitBreakerModule(this.settings));

for (Module pluginModule : pluginsService.nodeModules()) {
modules.add(pluginModule);
}
pluginsService.processModules(modules);

Injector injector = modules.createInjector();
injector.getInstance(TransportService.class).start();
TransportClient transportClient = new TransportClient(injector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,9 @@ public class ModulesBuilder implements Iterable<Module> {

private final List<Module> modules = Lists.newArrayList();

public ModulesBuilder add(Module... modules) {
for (Module module : modules) {
add(module);
}
return this;
}

public ModulesBuilder add(Module module) {
modules.add(module);
if (module instanceof SpawnModules) {
Iterable<? extends Module> spawned = ((SpawnModules) module).spawnModules();
for (Module spawn : spawned) {
add(spawn);
}
public ModulesBuilder add(Module... newModules) {
for (Module module : newModules) {
modules.add(module);
}
return this;
}
Expand Down

This file was deleted.

8 changes: 6 additions & 2 deletions core/src/main/java/org/elasticsearch/index/IndexService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.elasticsearch.indices.InternalIndicesLifecycle;
import org.elasticsearch.indices.cache.query.IndicesQueryCache;
import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.plugins.ShardsPluginsModule;

import java.io.Closeable;
import java.io.IOException;
Expand Down Expand Up @@ -317,7 +316,6 @@ public synchronized IndexShard createShard(int sShardId, ShardRouting routing) {
final boolean canDeleteShardContent = IndexMetaData.isOnSharedFilesystem(indexSettings) == false ||
(primary && IndexMetaData.isOnSharedFilesystem(indexSettings));
ModulesBuilder modules = new ModulesBuilder();
modules.add(new ShardsPluginsModule(indexSettings, pluginsService));
modules.add(new IndexShardModule(shardId, primary, indexSettings));
modules.add(new StoreModule(injector.getInstance(IndexStore.class).shardDirectory(), lock,
new StoreCloseListener(shardId, canDeleteShardContent, new Closeable() {
Expand All @@ -327,6 +325,12 @@ public void close() throws IOException {
}
}), path));
modules.add(new DeletionPolicyModule());

for (Module pluginModule : pluginsService.shardModules(indexSettings)) {
modules.add(pluginModule);
}
pluginsService.processModules(modules);

try {
shardInjector = modules.createChildInjector(injector);
} catch (CreationException e) {
Expand Down
34 changes: 28 additions & 6 deletions core/src/main/java/org/elasticsearch/indices/IndicesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
package org.elasticsearch.indices;

import com.google.common.base.Function;
import com.google.common.collect.*;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.CollectionUtil;
import org.apache.lucene.util.IOUtils;
Expand All @@ -35,15 +40,25 @@
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.*;
import org.elasticsearch.common.inject.CreationException;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.Injectors;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.env.ShardLock;
import org.elasticsearch.gateway.MetaDataStateFormat;
import org.elasticsearch.index.*;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexNameModule;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.LocalNodeIdModule;
import org.elasticsearch.index.aliases.IndexAliasesServiceModule;
import org.elasticsearch.index.analysis.AnalysisModule;
import org.elasticsearch.index.analysis.AnalysisService;
Expand Down Expand Up @@ -71,13 +86,16 @@
import org.elasticsearch.index.store.IndexStoreModule;
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
import org.elasticsearch.indices.recovery.RecoverySettings;
import org.elasticsearch.plugins.IndexPluginsModule;
import org.elasticsearch.plugins.PluginsService;

import java.io.Closeable;
import java.io.IOException;
import java.nio.file.Files;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -306,7 +324,6 @@ public synchronized IndexService createIndex(String sIndexName, @IndexSettings S
modules.add(new IndexNameModule(index));
modules.add(new LocalNodeIdModule(localNodeId));
modules.add(new IndexSettingsModule(index, indexSettings));
modules.add(new IndexPluginsModule(indexSettings, pluginsService));
modules.add(new IndexStoreModule(indexSettings));
modules.add(new AnalysisModule(indexSettings, indicesAnalysisService));
modules.add(new SimilarityModule(indexSettings));
Expand All @@ -316,6 +333,11 @@ public synchronized IndexService createIndex(String sIndexName, @IndexSettings S
modules.add(new IndexAliasesServiceModule());
modules.add(new IndexModule(indexSettings));

for (Module pluginModule : pluginsService.indexModules(indexSettings)) {
modules.add(pluginModule);
}
pluginsService.processModules(modules);

Injector indexInjector;
try {
indexInjector = modules.createChildInjector(injector);
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/org/elasticsearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.elasticsearch.common.component.Lifecycle;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lease.Releasables;
Expand Down Expand Up @@ -159,7 +160,7 @@ public Node(Settings preparedSettings, boolean loadConfigSettings) {
ModulesBuilder modules = new ModulesBuilder();
modules.add(new Version.Module(version));
modules.add(new CircuitBreakerModule(settings));
modules.add(new PluginsModule(settings, pluginsService));
modules.add(new PluginsModule(pluginsService));
modules.add(new SettingsModule(settings));
modules.add(new NodeModule(this));
modules.add(new NetworkModule());
Expand Down Expand Up @@ -187,6 +188,11 @@ public Node(Settings preparedSettings, boolean loadConfigSettings) {
modules.add(new RepositoriesModule());
modules.add(new TribeModule());

for (Module pluginModule : pluginsService.nodeModules()) {
modules.add(pluginModule);
}
pluginsService.processModules(modules);

injector = modules.createInjector();

client = injector.getInstance(Client.class);
Expand Down

This file was deleted.

24 changes: 2 additions & 22 deletions core/src/main/java/org/elasticsearch/plugins/PluginsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,15 @@
package org.elasticsearch.plugins;

import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.PreProcessModule;
import org.elasticsearch.common.inject.SpawnModules;
import org.elasticsearch.common.settings.Settings;

/**
*
*/
public class PluginsModule extends AbstractModule implements SpawnModules, PreProcessModule {

private final Settings settings;
public class PluginsModule extends AbstractModule {

private final PluginsService pluginsService;

public PluginsModule(Settings settings, PluginsService pluginsService) {
this.settings = settings;
public PluginsModule(PluginsService pluginsService) {
this.pluginsService = pluginsService;
}

@Override
public Iterable<? extends Module> spawnModules() {
return pluginsService.nodeModules();
}

@Override
public void processModule(Module module) {
pluginsService.processModule(module);
}

@Override
protected void configure() {
bind(PluginsService.class).toInstance(pluginsService);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@
package org.elasticsearch.repositories;

import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.Modules;
import org.elasticsearch.common.inject.SpawnModules;
import org.elasticsearch.common.settings.Settings;

import java.util.Arrays;
import java.util.Collections;

/**
* Binds repository classes for the specific repository type.
*/
Expand Down

0 comments on commit 2a726fe

Please sign in to comment.