private Factory shellFactory() { return dbInjector .createChildInjector( new FactoryModule() { @Override protected void configure() { factory(QueryShell.Factory.class); } }) .getInstance(QueryShell.Factory.class); }
private Injector getPluginInjector(Path jarPath) throws IOException { final String pluginName = MoreObjects.firstNonNull( JarPluginProvider.getJarPluginName(jarPath), PluginLoader.nameOf(jarPath)); return initInjector.createChildInjector( new AbstractModule() { @Override protected void configure() { bind(String.class).annotatedWith(PluginName.class).toInstance(pluginName); } }); }
public Injector createInjector() { Injector bootstrapInjector = Guice.createInjector(new ConfigurationProviderModule()); try { return bootstrapInjector.createChildInjector( new ChainOverrideAwareModule( bootstrapInjector, DslTransformation.class, Transformation.class, Class.forName("org.sculptor.generator.template.RootTmpl")), new SculptordslRuntimeModule()); } catch (ClassNotFoundException e) { throw new RuntimeException("Emergency - 'RootTmpl' not available on classpath"); } }
public static Injector getBotInjector(Version v, boolean login) { final String wikiUrl = getWikiUrl(v, LiveTestFather.getValue("localwikihost")); TestHelper.assumeReachable(wikiUrl); Injector injector = masterInjector.createChildInjector( new AbstractModule() { @Override protected void configure() { bind(CacheActionClient.class) // .toInstance(Mockito.spy(new CacheActionClient(wikiUrl, new WireRegister()))); bind(HttpBot.class).to(CacheHttpBot.class); bind(MediaWikiBot.class).asEagerSingleton(); } }); MediaWikiBot bot = injector.getInstance(MediaWikiBot.class); if (login) { bot.login(getWikiUser(v), getWikiPass(v)); } return injector; }
private void createInjector() { logger.info("Loading struts2 Guice support..."); // Something is wrong, since this should be there if GuiceServletContextListener // was present. if (injector == null) { logger.severe(ERROR_NO_INJECTOR); throw new RuntimeException(ERROR_NO_INJECTOR); } this.strutsInjector = injector.createChildInjector( new AbstractModule() { protected void configure() { // Tell the injector about all the action classes, etc., so it // can validate them at startup. for (Class<?> boundClass : boundClasses) { // TODO: Set source from Struts XML. bind(boundClass); } // Validate the interceptor class. for (ProvidedInterceptor interceptor : interceptors) { interceptor.validate(binder()); } } }); // Inject interceptors. for (ProvidedInterceptor interceptor : interceptors) { interceptor.inject(); } logger.info("Injector created successfully."); }
/** * Create an injector that is a child of the bootstrap bindings only * * @param modules binding modules * @return injector */ public Injector createChildInjector(Collection<Module> modules) { return injector.createChildInjector(modules); }
/** * Starts the container and hence the embedded jetty server. * * @throws Exception if there is an issue while starting the server */ @PostConstruct public void init() throws Exception { try { if (alreadyInited.compareAndSet(false, true)) { initAdminContainerConfigIfNeeded(); initAdminRegistryIfNeeded(); if (!adminContainerConfig.shouldEnable()) { return; } if (adminContainerConfig.shouldScanClassPathForPluginDiscovery()) { adminPageRegistry.registerAdminPagesWithClasspathScan(); } Injector adminResourceInjector; if (shouldShareResourcesWithParentInjector()) { adminResourceInjector = appInjector.createChildInjector(buildAdminPluginsGuiceModules()); } else { adminResourceInjector = LifecycleInjector.builder() .inStage(Stage.DEVELOPMENT) .usingBasePackages("com.netflix.explorers") .withModules(buildAdminPluginsGuiceModules()) .build() .createInjector(); adminResourceInjector.getInstance(LifecycleManager.class).start(); } server = new Server(adminContainerConfig.listenPort()); // redirect filter based on configurable RedirectRules final Context rootHandler = new Context(); rootHandler.setContextPath("/"); rootHandler.addFilter( new FilterHolder(adminResourceInjector.getInstance(RedirectFilter.class)), "/*", Handler.DEFAULT); rootHandler.addServlet(new ServletHolder(new DefaultServlet()), "/*"); // admin page template resources AdminResourcesFilter arfTemplatesResources = adminResourceInjector.getInstance(AdminResourcesFilter.class); arfTemplatesResources.setPackages(adminContainerConfig.jerseyViewableResourcePkgList()); final Context adminTemplatesResHandler = new Context(); adminTemplatesResHandler.setContextPath(adminContainerConfig.templateResourceContext()); adminTemplatesResHandler.setSessionHandler(new SessionHandler()); adminTemplatesResHandler.addFilter(LoggingFilter.class, "/*", Handler.DEFAULT); adminTemplatesResHandler.addFilter( new FilterHolder(adminResourceInjector.getInstance(RedirectFilter.class)), "/*", Handler.DEFAULT); adminTemplatesResHandler.addFilter( new FilterHolder(arfTemplatesResources), "/*", Handler.DEFAULT); adminTemplatesResHandler.addServlet(new ServletHolder(new DefaultServlet()), "/*"); // admin page data resources final String jerseyPkgListForAjaxResources = appendCoreJerseyPackages(adminPageRegistry.buildJerseyResourcePkgListForAdminPages()); AdminResourcesFilter arfDataResources = adminResourceInjector.getInstance(AdminResourcesFilter.class); arfDataResources.setPackages(jerseyPkgListForAjaxResources); final Context adminDataResHandler = new Context(); adminDataResHandler.setContextPath(adminContainerConfig.ajaxDataResourceContext()); adminDataResHandler.addFilter( new FilterHolder(adminResourceInjector.getInstance(RedirectFilter.class)), "/*", Handler.DEFAULT); adminDataResHandler.addFilter(new FilterHolder(arfDataResources), "/*", Handler.DEFAULT); adminDataResHandler.addServlet(new ServletHolder(new DefaultServlet()), "/*"); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); server.setThreadPool(threadPool); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers( new Handler[] {adminTemplatesResHandler, adminDataResHandler, rootHandler}); server.setHandler(handlers); server.start(); final Connector connector = server.getConnectors()[0]; serverPort = connector.getLocalPort(); } } catch (Exception e) { logger.error("Exception in building AdminResourcesContainer ", e); } }
protected Destination( Injector injector, DestinationConfiguration cfg, RemoteSiteUser.Factory replicationUserFactory, PluginUser pluginUser, GitRepositoryManager gitRepositoryManager, GroupBackend groupBackend, ReplicationStateListener stateLog, GroupIncludeCache groupIncludeCache) { config = cfg; gitManager = gitRepositoryManager; this.stateLog = stateLog; final CurrentUser remoteUser; if (!cfg.getAuthGroupNames().isEmpty()) { ImmutableSet.Builder<AccountGroup.UUID> builder = ImmutableSet.builder(); for (String name : cfg.getAuthGroupNames()) { GroupReference g = GroupBackends.findExactSuggestion(groupBackend, name); if (g != null) { builder.add(g.getUUID()); addRecursiveParents(g.getUUID(), builder, groupIncludeCache); } else { repLog.warn(String.format("Group \"%s\" not recognized, removing from authGroup", name)); } } remoteUser = replicationUserFactory.create(new ListGroupMembership(builder.build())); } else { remoteUser = pluginUser; } Injector child = injector.createChildInjector( new FactoryModule() { @Override protected void configure() { bindScope(RequestScoped.class, PerThreadRequestScope.REQUEST); bind(PerThreadRequestScope.Propagator.class); bind(PerRequestProjectControlCache.class).in(RequestScoped.class); bind(Destination.class).toInstance(Destination.this); bind(RemoteConfig.class).toInstance(config.getRemoteConfig()); install(new FactoryModuleBuilder().build(PushOne.Factory.class)); } @Provides public PerThreadRequestScope.Scoper provideScoper( final PerThreadRequestScope.Propagator propagator, final Provider<RequestScopedReviewDbProvider> dbProvider) { final RequestContext requestContext = new RequestContext() { @Override public CurrentUser getUser() { return remoteUser; } @Override public Provider<ReviewDb> getReviewDbProvider() { return dbProvider.get(); } }; return new PerThreadRequestScope.Scoper() { @Override public <T> Callable<T> scope(Callable<T> callable) { return propagator.scope(requestContext, callable); } }; } }); projectControlFactory = child.getInstance(ProjectControl.Factory.class); opFactory = child.getInstance(PushOne.Factory.class); threadScoper = child.getInstance(PerThreadRequestScope.Scoper.class); }