allow plugins to provide actual Module instances, not just classes to create the modules from

This commit is contained in:
Shay Banon 2012-01-18 21:18:29 +02:00
parent 0a3c941947
commit 5325bf4bec
6 changed files with 69 additions and 1 deletions

View File

@ -45,6 +45,14 @@ public abstract class AbstractPlugin implements Plugin {
return ImmutableList.of();
}
/**
* Defaults to return an empty list.
*/
@Override
public Collection<Module> modules(Settings settings) {
return ImmutableList.of();
}
/**
* Defaults to return an empty list.
*/
@ -61,6 +69,14 @@ public abstract class AbstractPlugin implements Plugin {
return ImmutableList.of();
}
/**
* Defaults to return an empty list.
*/
@Override
public Collection<Module> indexModules(Settings settings) {
return ImmutableList.of();
}
/**
* Defaults to return an empty list.
*/
@ -77,6 +93,14 @@ public abstract class AbstractPlugin implements Plugin {
return ImmutableList.of();
}
/**
* Defaults to return an empty list.
*/
@Override
public Collection<Module> shardModules(Settings settings) {
return ImmutableList.of();
}
/**
* Defaults to return an empty list.
*/

View File

@ -52,6 +52,7 @@ public class IndexPluginsModule extends AbstractModule implements SpawnModules,
for (Class<? extends Module> moduleClass : modulesClasses) {
modules.add(createModule(moduleClass, settings));
}
modules.addAll(pluginsService.indexModules(settings));
return modules;
}

View File

@ -46,10 +46,17 @@ public interface Plugin {
String description();
/**
* Node level modules.
* Node level modules (classes, will automatically be created).
*/
Collection<Class<? extends Module>> modules();
/**
* Node level modules (instances)
*
* @param settings The node level settings.
*/
Collection<Module> modules(Settings settings);
/**
* Node level services that will be automatically started/stopped/closed.
*/
@ -60,6 +67,11 @@ public interface Plugin {
*/
Collection<Class<? extends Module>> indexModules();
/**
* Per index modules.
*/
Collection<Module> indexModules(Settings settings);
/**
* Per index services that will be automatically closed.
*/
@ -70,6 +82,11 @@ public interface Plugin {
*/
Collection<Class<? extends Module>> shardModules();
/**
* Per index shard module.
*/
Collection<Module> shardModules(Settings settings);
/**
* Per index shard service that will be automatically closed.
*/

View File

@ -52,6 +52,7 @@ public class PluginsModule extends AbstractModule implements SpawnModules, PrePr
for (Class<? extends Module> moduleClass : modulesClasses) {
modules.add(createModule(moduleClass, settings));
}
modules.addAll(pluginsService.modules(settings));
return modules;
}

View File

@ -151,6 +151,14 @@ public class PluginsService extends AbstractComponent {
return modules;
}
public Collection<Module> modules(Settings settings) {
List<Module> modules = Lists.newArrayList();
for (Plugin plugin : plugins.values()) {
modules.addAll(plugin.modules(settings));
}
return modules;
}
public Collection<Class<? extends LifecycleComponent>> services() {
List<Class<? extends LifecycleComponent>> services = Lists.newArrayList();
for (Plugin plugin : plugins.values()) {
@ -167,6 +175,14 @@ public class PluginsService extends AbstractComponent {
return modules;
}
public Collection<Module> indexModules(Settings settings) {
List<Module> modules = Lists.newArrayList();
for (Plugin plugin : plugins.values()) {
modules.addAll(plugin.indexModules(settings));
}
return modules;
}
public Collection<Class<? extends CloseableIndexComponent>> indexServices() {
List<Class<? extends CloseableIndexComponent>> services = Lists.newArrayList();
for (Plugin plugin : plugins.values()) {
@ -183,6 +199,14 @@ public class PluginsService extends AbstractComponent {
return modules;
}
public Collection<Module> shardModules(Settings settings) {
List<Module> modules = Lists.newArrayList();
for (Plugin plugin : plugins.values()) {
modules.addAll(plugin.shardModules(settings));
}
return modules;
}
public Collection<Class<? extends CloseableIndexComponent>> shardServices() {
List<Class<? extends CloseableIndexComponent>> services = Lists.newArrayList();
for (Plugin plugin : plugins.values()) {

View File

@ -52,6 +52,7 @@ public class ShardsPluginsModule extends AbstractModule implements SpawnModules,
for (Class<? extends Module> moduleClass : modulesClasses) {
modules.add(createModule(moduleClass, settings));
}
modules.addAll(pluginsService.shardModules(settings));
return modules;
}