com.netflix.governator.guice.LifecycleInjectorBuilder Java Examples

The following examples show how to use com.netflix.governator.guice.LifecycleInjectorBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bootstrap.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public Injector bootstrap() {
   try {
      // Construct the injector
      LifecycleInjectorBuilder builder = LifecycleInjector.builder()
         .withBootstrapModule(new BootstrapModule() {
            @Override
            public void configure(@Nullable BootstrapBinder binder) {
               Preconditions.checkNotNull(binder);
               binder.bindConfigurationProvider().to(AgentConfigurationProvider.class);
            }
         })
         .withAdditionalBootstrapModules(boostrapModules);

      builder.withAdditionalModuleClasses(moduleClasses);
      if(!modules.isEmpty()) {
         builder.withAdditionalModules(modules);
      }

      LifecycleInjector inj = builder.build();
      Injector result = inj.createInjector();
      LifeCycleService.setState(LifeCycle.STARTING_UP, LifeCycle.STARTED);
      return result;
   } catch(Exception ex) {
      throw new BootException("error bootstrapping", ex);
   }
}
 
Example #2
Source File: Bootstrap.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public Injector bootstrap() throws BootstrapException {
   try {
      final Properties merged = mergeProperties();

      LifecycleInjectorBuilder builder = LifecycleInjector.builder()
         .withBootstrapModule(new BootstrapModule() {
            @Override
            public void configure(BootstrapBinder binder) {
               Names.bindProperties(binder, merged);
               binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(merged));
            }
         })
         .withAdditionalBootstrapModules(boostrapModules);

      if(merged.containsKey(PROP_MODULES)) {
         String [] classnames = StringUtils.split(merged.getProperty(PROP_MODULES));
         Set<Class<? extends Module>> modules = classnamesToClasses(Arrays.asList(classnames));
         modules.addAll(moduleClasses);
         builder.withAdditionalModuleClasses(modules);
      }
      else if(!moduleClasses.isEmpty()) {
         builder.withAdditionalModuleClasses(moduleClasses);
      }
      if(!modules.isEmpty()) {
         builder.withAdditionalModules(modules);
      }

      return builder.build().createInjector();
   } catch(Exception e) {
      throw new BootstrapException("Error bootstrapping the injection context", e);
   }
}
 
Example #3
Source File: DIBase.java    From EVCache with Apache License 2.0 5 votes vote down vote up
@BeforeSuite
public void setupEnv() {
    Properties props = getProps();

    try {

        LifecycleInjectorBuilder builder = LifecycleInjector.builder();
        builder.withModules(
                new EurekaClientModule(),
                new EVCacheModule(),
                new DIConnectionModule(),
                new SpectatorModule(),
                new ArchaiusModule() {
                	protected void configureArchaius() {
                		bindApplicationConfigurationOverride().toInstance(MapConfig.from(props));
                	};
                }
                );

        injector = builder.build().createInjector();
        lifecycleManager = injector.getInstance(LifecycleManager.class);

        lifecycleManager.start();
        injector.getInstance(ApplicationInfoManager.class);
        final EVCacheModule lib = injector.getInstance(EVCacheModule.class);
        manager = injector.getInstance(EVCacheClientPoolManager.class);
    } catch (Throwable e) {
        e.printStackTrace();
        log.error(e.getMessage(), e);
    }

}
 
Example #4
Source File: ScriptManagerBootstrap.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
@Override
protected void beforeInjectorCreation(@SuppressWarnings("unused") LifecycleInjectorBuilder builderToBeUsed) {

   JerseyServletModule jerseyServletModule = new JerseyServletModule() {
        @Override
        protected void configureServlets() {
            bind(String.class).annotatedWith(Names.named("explorerAppName")).toInstance("scriptmanager");
            bind(GsonMessageBodyHandler.class).in(Scopes.SINGLETON);
            bind(GlobalModelContext.class).to(AppConfigGlobalModelContext.class);
            bind(ExplorerManager.class).to(ExplorersManagerImpl.class);
            bind(ScriptManagerExplorer.class);

            bind(GuiceContainer.class).asEagerSingleton();

            Map<String, String> params = new HashMap<String, String>();
            params.put(PackagesResourceConfig.PROPERTY_PACKAGES,
                // pytheas resources
                "com.netflix.explorers.resources;" +
                "com.netflix.explorers.providers;" +
                // nicobar resources
                "com.netflix.nicobar.manager.explorer.resources");

            // Route all requests through GuiceContainer
            serve("/*").with(GuiceContainer.class, params);
        }
    };
    builderToBeUsed.withAdditionalModules(jerseyServletModule);
    LOG.debug("HelloWorldBootstrap injected jerseyServletModule in LifecycleInjectorBuilder");
}