@Override @SuppressWarnings("unchecked") public final void initialize(Bootstrap<?> bootstrap) { final Class<T> klass = (Class<T>) bootstrap.getApplication().getConfigurationClass(); bootstrap.addCommand(new DbCommand<>(name(), this, klass, getMigrationsFileName())); }
@Override @SuppressWarnings("unchecked") public void run(Bootstrap<?> wildcardBootstrap, Namespace namespace) throws Exception { final Bootstrap<T> bootstrap = (Bootstrap<T>) wildcardBootstrap; configuration = parseConfiguration(bootstrap.getConfigurationFactoryFactory(), bootstrap.getConfigurationSourceProvider(), bootstrap.getValidatorFactory().getValidator(), namespace.getString("file"), getConfigurationClass(), bootstrap.getObjectMapper()); try { if (configuration != null) { configuration.getLoggingFactory().configure(bootstrap.getMetricRegistry(), bootstrap.getApplication().getName()); } run(bootstrap, namespace, configuration); } finally { if (!asynchronous) { cleanup(); } } }
@Override protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception { final Environment environment = new Environment(bootstrap.getApplication().getName(), bootstrap.getObjectMapper(), bootstrap.getValidatorFactory(), bootstrap.getMetricRegistry(), bootstrap.getClassLoader(), bootstrap.getHealthCheckRegistry()); configuration.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry()); configuration.getServerFactory().configure(environment); bootstrap.run(configuration, environment); application.run(configuration, environment); run(environment, namespace, configuration); }
@Override @SuppressWarnings("unchecked") public void run(Bootstrap<?> wildcardBootstrap, Namespace namespace) throws Exception { final Bootstrap<T> bootstrap = (Bootstrap<T>) wildcardBootstrap; configuration = parseConfiguration(bootstrap.getConfigurationFactoryFactory(), bootstrap.getConfigurationSourceProvider(), bootstrap.getValidatorFactory().getValidator(), namespace.getString("file"), getConfigurationClass(), bootstrap.getObjectMapper()); try { if (configuration != null) { configuration.getLoggingFactory().configure(bootstrap.getMetricRegistry(), bootstrap.getApplication().getName()); } run(bootstrap, namespace, configuration); } finally { if (!asynchronous) { cleanup(); } } }
@Override protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception { final Environment environment = new Environment(bootstrap.getApplication().getName(), bootstrap.getObjectMapper(), bootstrap.getValidatorFactory().getValidator(), bootstrap.getMetricRegistry(), bootstrap.getClassLoader(), bootstrap.getHealthCheckRegistry()); configuration.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry()); configuration.getServerFactory().configure(environment); bootstrap.run(configuration, environment); application.run(configuration, environment); run(environment, namespace, configuration); }
/** * @return application class package (most likely root package for entire application) */ protected String appPackage() { return bootstrap().getApplication().getClass().getPackage().getName(); }
/** * @return application class package (most likely root package for entire application) */ protected String appPackage() { return bootstrap().getApplication().getClass().getPackage().getName(); }
/** * Application instance may be useful for complex (half manual) integrations where access for * injector is required. * For example, manually registered * {@link io.dropwizard.lifecycle.Managed} may access injector in it's start method by calling * {@link ru.vyarus.dropwizard.guice.injector.lookup.InjectorLookup#getInjector(Application)}. * <p> * NOTE: it will work in this example, because injector access will be after injector creation. * Directly inside bundle initialization method injector could not be obtained as it's not exists yet. * * @return dropwizard application instance */ public Application application() { return context.getBootstrap().getApplication(); }
/** * Application instance may be useful for complex (half manual) integrations where access for * injector is required. * For example, manually registered * {@link io.dropwizard.lifecycle.Managed} may access injector in it's start method by calling * {@link ru.vyarus.dropwizard.guice.injector.lookup.InjectorLookup#getInjector(Application)}. * <p> * NOTE: it will work in this example, because injector access will be after injector creation. * Directly inside bundle initialization method injector could not be obtained as it's not exists yet. * * @return dropwizard application instance */ public Application application() { return context.getBootstrap().getApplication(); }
@Override @SuppressWarnings("unchecked") public void visit(final Class<?> type) { if (FeatureUtils.is(type, Command.class)) { try { final Command cmd; if (EnvironmentCommand.class.isAssignableFrom(type)) { cmd = (Command) type.getConstructor(Application.class) .newInstance(bootstrap.getApplication()); } else { cmd = (Command) type.newInstance(); } commands.add((Class<Command>) type); commandList.add(cmd); bootstrap.addCommand(cmd); LOGGER.debug("Command registered: {}", type.getSimpleName()); } catch (Exception e) { throw new IllegalStateException("Failed to instantiate command: " + type.getSimpleName(), e); } } }
@Override @SuppressWarnings("unchecked") public void visit(final Class<?> type) { if (FeatureUtils.is(type, Command.class)) { try { final Command cmd; if (EnvironmentCommand.class.isAssignableFrom(type)) { cmd = (Command) type.getConstructor(Application.class) .newInstance(bootstrap.getApplication()); } else { cmd = (Command) type.newInstance(); } commands.add((Class<Command>) type); commandList.add(cmd); bootstrap.addCommand(cmd); LOGGER.debug("Command registered: {}", type.getSimpleName()); } catch (Exception e) { throw new IllegalStateException("Failed to instantiate command: " + type.getSimpleName(), e); } } }
@Override public void initialize(Bootstrap<?> bootstrap) { Class<T> configurationClass = (Class<T>) bootstrap.getApplication().getConfigurationClass(); bootstrap.addCommand(new AtlasDbConfiguredCommand<T>(configurationClass)); }
protected T loadConfiguration(Bootstrap bootstrap) { if (config == null) { try { config = (T) bootstrap.getConfigurationFactoryFactory().create( bootstrap.getApplication().getConfigurationClass(), bootstrap.getValidatorFactory().getValidator(), bootstrap.getObjectMapper(), "") .build(new File(configurationPath)); } catch (Exception e) { throw new RobeRuntimeException("Can't load configuration :" + configurationPath, e); } } return config; }
@Override @SuppressWarnings("unchecked") public final void initialize(Bootstrap<?> bootstrap) { final Class<T> klass = (Class<T>) bootstrap.getApplication().getConfigurationClass(); bootstrap.addCommand(new DbCommand<>(name(), this, klass, getMigrationsFileName())); }
private void createInjector(final Environment environment) { final Stopwatch timer = context.stat().timer(InjectorCreationTime); injector = injectorFactory.createInjector( context.option(InjectorStage), ModulesSupport.prepareModules(context)); // registering as managed to cleanup injector on application stop environment.lifecycle().manage( InjectorLookup.registerInjector(context.getBootstrap().getApplication(), injector)); timer.stop(); }
private void createInjector(final Environment environment) { final Stopwatch timer = context.stat().timer(InjectorCreationTime); injector = injectorFactory.createInjector( context.option(InjectorStage), ModulesSupport.prepareModules(context)); // registering as managed to cleanup injector on application stop environment.lifecycle().manage( InjectorLookup.registerInjector(context.getBootstrap().getApplication(), injector)); timer.stop(); }
@Override protected void configure() { bindScope(Prototype.class, Scopes.NO_SCOPE); bindEnvironment(); install(new InstallerModule(scanner, context)); install(new Jersey2Module(bootstrap().getApplication(), environment(), context)); // let guice beans use options the same way as bundles (with usage tracking) bind(Options.class).toInstance(options()); // provide access for configuration info collected during startup bind(ConfigurationInfo.class).toInstance(new ConfigurationInfo(context)); bind(StatsInfo.class).toInstance(new StatsInfo(context.stat())); bind(OptionsInfo.class).toInstance(new OptionsInfo(context.options())); bind(GuiceyConfigurationInfo.class).in(Singleton.class); }
@Override protected void configure() { bindScope(Prototype.class, Scopes.NO_SCOPE); bindEnvironment(); install(new InstallerModule(scanner, context)); install(new Jersey2Module(bootstrap().getApplication(), environment(), context)); // let guice beans use options the same way as bundles (with usage tracking) bind(Options.class).toInstance(options()); // provide access for configuration info collected during startup bind(ConfigurationInfo.class).toInstance(new ConfigurationInfo(context)); bind(StatsInfo.class).toInstance(new StatsInfo(context.stat())); bind(OptionsInfo.class).toInstance(new OptionsInfo(context.options())); bind(GuiceyConfigurationInfo.class).in(Singleton.class); }
bootstrap.addBundle(new GuiceBundle<T>(modules, bootstrap.getApplication().getConfigurationClass()));