Skip to content

Instantly share code, notes, and snippets.

@Romain-P
Created June 8, 2014 19:11
Show Gist options
  • Save Romain-P/bcf099d8c5dbda559e70 to your computer and use it in GitHub Desktop.
Save Romain-P/bcf099d8c5dbda559e70 to your computer and use it in GitHub Desktop.
no comment
package org.heater.core.plugin;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.multibindings.Multibinder;
import org.heater.api.HeaterActivator;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class PluginManager {
private final List<HeaterActivator> instances;
private AbstractModule module;
@Inject Set<HeaterActivator> plugins;
public PluginManager() {
this.instances = new ArrayList<>();
}
public PluginManager initialize() {
//TODO: insert modules main class
return this;
}
public void finalize() {
if(plugins == null) return;
for(HeaterActivator plugin: plugins)
plugin.stop();
}
private AbstractModule buildModule() {
return new AbstractModule() {
@Override
protected void configure() {
bind(PluginManager.class).toInstance(PluginManager.this);
Multibinder<HeaterActivator> binder = Multibinder.newSetBinder(binder(), HeaterActivator.class);
for(HeaterActivator instance: instances) {
binder.addBinding().toInstance(instance);
install(instance.pluginModule());
}
}
};
}
public AbstractModule getModule() {
return module != null ? module : (module = buildModule());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment