use of com.github.joschi.jadconfig.guice.NamedConfigParametersModule in project graylog2-server by Graylog2.
the class CmdLineTool method setupInjector.
protected Injector setupInjector(NamedConfigParametersModule configModule, Module... otherModules) {
try {
final ImmutableList.Builder<Module> modules = ImmutableList.builder();
modules.add(configModule);
modules.addAll(getSharedBindingsModules());
modules.addAll(getCommandBindings());
modules.addAll(Arrays.asList(otherModules));
modules.add(new Module() {
@Override
public void configure(Binder binder) {
binder.bind(String.class).annotatedWith(Names.named("BootstrapCommand")).toInstance(commandName);
}
});
return GuiceInjectorHolder.createInjector(modules.build());
} catch (CreationException e) {
annotateInjectorCreationException(e);
return null;
} catch (Exception e) {
LOG.error("Injector creation failed!", e);
return null;
}
}
use of com.github.joschi.jadconfig.guice.NamedConfigParametersModule in project graylog2-server by Graylog2.
the class CmdLineTool method setupCoreConfigInjector.
/**
* Set up a separate injector, containing only the core configuration bindings. It can be used to look up
* configuration values in modules at binding time.
*/
protected Injector setupCoreConfigInjector() {
final NamedConfigParametersModule configModule = new NamedConfigParametersModule(jadConfig.getConfigurationBeans());
Injector coreConfigInjector = null;
try {
coreConfigInjector = Guice.createInjector(Stage.PRODUCTION, ImmutableList.of(configModule, (Module) Binder::requireExplicitBindings, this::featureFlagsBinding));
} catch (CreationException e) {
annotateInjectorCreationException(e);
} catch (Exception e) {
LOG.error("Injector creation failed!", e);
}
if (coreConfigInjector == null) {
LOG.error("Injector for core configuration could not be created, exiting! (Please include the previous " + "error messages in bug reports.)");
System.exit(1);
}
return coreConfigInjector;
}
use of com.github.joschi.jadconfig.guice.NamedConfigParametersModule in project graylog2-server by Graylog2.
the class CmdLineTool method run.
@Override
public void run() {
final Level logLevel = setupLogger();
if (isDumpDefaultConfig()) {
dumpDefaultConfigAndExit();
}
// This is holding all our metrics.
MetricRegistry metricRegistry = MetricRegistryFactory.create();
featureFlags = getFeatureFlags(metricRegistry);
installConfigRepositories();
installCommandConfig();
beforeStart();
beforeStart(parseAndGetTLSConfiguration(), parseAndGetPathConfiguration(configFile));
processConfiguration(jadConfig);
coreConfigInjector = setupCoreConfigInjector();
final Set<Plugin> plugins = loadPlugins(getPluginPath(configFile), chainingClassLoader);
installPluginConfig(plugins);
processConfiguration(jadConfig);
if (isDumpConfig()) {
dumpCurrentConfigAndExit();
}
if (!validateConfiguration()) {
LOG.error("Validating configuration file failed - exiting.");
System.exit(1);
}
final List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
LOG.info("Running with JVM arguments: {}", Joiner.on(' ').join(arguments));
beforeInjectorCreation(plugins);
injector = setupInjector(new NamedConfigParametersModule(jadConfig.getConfigurationBeans()), new PluginBindings(plugins), binder -> binder.bind(MetricRegistry.class).toInstance(metricRegistry));
if (injector == null) {
LOG.error("Injector could not be created, exiting! (Please include the previous error messages in bug " + "reports.)");
System.exit(1);
}
addInstrumentedAppender(metricRegistry, logLevel);
// Report metrics via JMX.
final JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).build();
reporter.start();
startCommand();
}
Aggregations