@Override public void configure(final Binder binder) { final ExportBuilder builder = MBeanModule.newExporter(binder); binder.bind(PersistentWriterFactory.class).to(EventSpoolWriterFactory.class).asEagerSingleton(); Multibinder<EventSpoolProcessor> defaultSpoolProcessors = Multibinder.newSetBinder(binder, EventSpoolProcessor.class); MapBinder<String, EventSpoolProcessor> perEventSpoolDispatchers = MapBinder.newMapBinder(binder, String.class, EventSpoolProcessor.class).permitDuplicates(); String spoolWriterClasses = config.getSpoolWriterClassNames(); final Iterable<String> spoolDispatcherClasses; if (!Strings.isNullOrEmpty(spoolWriterClasses)) { spoolDispatcherClasses = Splitter.on(",").trimResults().omitEmptyStrings().split(spoolWriterClasses); } else { spoolDispatcherClasses = Lists.newArrayList(); } // Bind the classes for default spoolClasses for (String className : spoolDispatcherClasses) { try { defaultSpoolProcessors .addBinding() .to(Class.forName(className).asSubclass(EventSpoolProcessor.class)) .asEagerSingleton(); } catch (ClassNotFoundException e) { log.error("Could not bind " + className, e); } } // Find and bind the classes used for per event spool writers Map<String, Iterable<String>> perEventSpoolWriterClasses = getSpoolWriterClassesByEventType(); for (Map.Entry<String, Iterable<String>> eventToSpoolWriters : perEventSpoolWriterClasses.entrySet()) { for (String spoolWriterClass : eventToSpoolWriters.getValue()) { try { perEventSpoolDispatchers .addBinding(eventToSpoolWriters.getKey()) .to(Class.forName(spoolWriterClass).asSubclass(EventSpoolProcessor.class)); } catch (ClassNotFoundException ex) { log.error("Could not bind " + spoolWriterClass, ex); } } } builder .export(EventSpoolWriterFactory.class) .as("com.ning.metrics.collector:name=EventSpoolWriter"); }
@Override protected void configure() { LOGGER.debug("Configuring guice"); bind(MyriadConfiguration.class).toInstance(cfg); bind(Configuration.class).toInstance(hadoopConf); bind(RMContext.class).toInstance(rmContext); bind(AbstractYarnScheduler.class).toInstance(yarnScheduler); bind(InterceptorRegistry.class).toInstance(interceptorRegistry); bind(MyriadDriverManager.class).in(Scopes.SINGLETON); bind(org.apache.myriad.scheduler.MyriadScheduler.class).in(Scopes.SINGLETON); bind(ServiceProfileManager.class).in(Scopes.SINGLETON); bind(DisruptorManager.class).in(Scopes.SINGLETON); bind(ReconcileService.class).in(Scopes.SINGLETON); bind(HttpConnectorProvider.class).in(Scopes.SINGLETON); bind(MyriadWebServer.class).in(Scopes.SINGLETON); // add special binding between TaskFactory and NMTaskFactory to ease up // usage of TaskFactory bind(TaskFactory.class).annotatedWith(NMTaskFactoryAnnotation.class).to(NMTaskFactory.class); bind(YarnNodeCapacityManager.class).in(Scopes.SINGLETON); bind(NodeStore.class).in(Scopes.SINGLETON); bind(OfferLifecycleManager.class).in(Scopes.SINGLETON); bind(NMHeartBeatHandler.class).asEagerSingleton(); MapBinder<String, TaskFactory> mapBinder = MapBinder.newMapBinder(binder(), String.class, TaskFactory.class); mapBinder .addBinding(NodeManagerConfiguration.DEFAULT_NM_TASK_PREFIX) .to(NMTaskFactory.class) .in(Scopes.SINGLETON); Map<String, ServiceConfiguration> auxServicesConfigs = cfg.getServiceConfigurations(); for (Map.Entry<String, ServiceConfiguration> entry : auxServicesConfigs.entrySet()) { if (entry.getValue().getTaskFactoryImplName().isPresent()) { String taskFactoryClass = entry.getValue().getTaskFactoryImplName().get(); try { Class<? extends TaskFactory> implClass = getTaskFactoryClass(taskFactoryClass); mapBinder.addBinding(entry.getKey()).to(implClass).in(Scopes.SINGLETON); } catch (ClassNotFoundException e) { LOGGER.error("ClassNotFoundException", e); } } else { // TODO (hokiegeek2) Confirm if this else statement and logic should still be here mapBinder.addBinding(entry.getKey()).to(ServiceTaskFactory.class).in(Scopes.SINGLETON); } } // TODO(Santosh): Should be configurable as well bind(NodeScaleDownPolicy.class).to(LeastAMNodesFirstPolicy.class).in(Scopes.SINGLETON); }
@Override protected void configureConnections(PrivateBinder binder) { binder.bind(QueryFactory.class).to(LdapQueryFactory.class); binder.bind(LdapTokenAttributeConversion.class); binder.bind(LdapSearchHandler.class); binder.bind(EntryPartialTokenConverter.class); binder.bind(EntryTokenConverter.class); binder.bind(LdapQueryBuilder.class); binder.bind(LdapQueryFactory.class); binder .bind(ConnectionConfig.class) .annotatedWith(Names.named(DataLayerConstants.EXTERNAL_CONFIG)) .toProvider(ExternalConnectionConfigProvider.class); binder.bind(ConnectionFactoryProvider.class).to(LdapConnectionFactoryProvider.class); binder.bind(ConnectionFactory.class).toProvider(getConnectionFactoryProviderType()); MapBinder<Class, EntryConverter> entryConverterBinder = MapBinder.newMapBinder(binder, Class.class, EntryConverter.class); entryConverterBinder.addBinding(String.class).to(EntryStringConverter.class); entryConverterBinder.addBinding(PartialToken.class).to(EntryPartialTokenConverter.class); entryConverterBinder.addBinding(Token.class).to(EntryTokenConverter.class); binder .bind(LdapDataLayerConfiguration.class) .to(getLdapConfigurationType()) .in(Singleton.class); binder .bind(Key.get(LdapDataLayerConfiguration.class, DataLayer.Types.typed(connectionType))) .toProvider(binder.getProvider(LdapDataLayerConfiguration.class)); binder.expose(Key.get(LdapDataLayerConfiguration.class, DataLayer.Types.typed(connectionType))); }
protected void configureEventHandlers() { MapBinder<String, EventHandler> eventBinder = MapBinder.newMapBinder(binder(), String.class, EventHandler.class); for (Class<? extends EventHandler> clazz : EventHandlerLoader.getClasses()) { if (clazz.isAnnotationPresent(HandlerTarget.class)) { HandlerTarget targetAnnotation = clazz.getAnnotation(HandlerTarget.class); eventBinder.addBinding(targetAnnotation.value()).to(clazz).asEagerSingleton(); } } }
@Override public void configure(Binder binder) { PolyBind.createChoice( binder, "druid.indexer.logs.type", Key.get(TaskLogs.class), Key.get(FileTaskLogs.class)); JsonConfigProvider.bind(binder, "druid.indexer.logs", FileTaskLogsConfig.class); final MapBinder<String, TaskLogs> taskLogBinder = Binders.taskLogsBinder(binder); taskLogBinder.addBinding("noop").to(NoopTaskLogs.class).in(LazySingleton.class); taskLogBinder.addBinding("file").to(FileTaskLogs.class).in(LazySingleton.class); binder.bind(NoopTaskLogs.class).in(LazySingleton.class); binder.bind(FileTaskLogs.class).in(LazySingleton.class); binder.bind(TaskLogPusher.class).to(TaskLogs.class); }
@BeforeMethod public void startUp() { Injector injector = Guice.createInjector( Stage.PRODUCTION, new JsonModule(), new HandleJsonModule(), binder -> { MapBinder<String, ConnectorHandleResolver> connectorHandleResolverBinder = MapBinder.newMapBinder(binder, String.class, ConnectorHandleResolver.class); connectorHandleResolverBinder .addBinding("system") .toInstance(new SystemHandleResolver(CONNECTOR_ID)); }); objectMapper = injector.getInstance(ObjectMapper.class); }
protected void serve( HttpMethod method, String pattern, Class<? extends RequestHandler> withHttpHandler) { logger.debug("Registering {} on {} to {}", new Object[] {method, pattern, withHttpHandler}); RequestMatcher matcher = new RequestMatcher(method, pattern); matchers.add(matcher); MapBinder.newMapBinder(binder(), RequestMatcher.class, RequestHandler.class) .addBinding(matcher) .to(withHttpHandler) .in(RequestScoped.class); }
public static LinkedBindingBuilder<Transformer> bindDecodingTransformer( final Binder binder, final Class<?> clazz) { final MapBinder<Class<?>, Transformer> transformerBinder = MapBinder.newMapBinder( binder, new TypeLiteral<Class<?>>() {}, new TypeLiteral<Transformer>() {}, DECODING_NAMED); return transformerBinder.addBinding(clazz); }
@Override protected void configure() { bindInterceptor( Matchers.any(), Matchers.annotatedWith(Span.class), new TracerSpanInterceptor( getProvider(Tracer.class), getProvider(Key.get(new TypeLiteral<Map<String, Labeler>>() {})), labelHost)); MapBinder<String, Labeler> mapBinder = MapBinder.newMapBinder(binder(), String.class, Labeler.class); }
/** * Starts the test app in a background thread. * * @param args String[] emulating command-line arguments passed to a Java app. * @return {@link BQDaemonTestRuntime} instance created by the builder. The caller doesn't need * to shut it down. Usually JUnit lifecycle takes care of it. */ public BQDaemonTestRuntime start(String... args) { Consumer<Bootique> localConfigurator = configurator; if (!properties.isEmpty()) { Consumer<Bootique> propsConfigurator = bootique -> bootique.module( binder -> { MapBinder<String, String> mapBinder = BQCoreModule.contributeProperties(binder); properties.forEach((k, v) -> mapBinder.addBinding(k).toInstance(v)); }); localConfigurator = localConfigurator.andThen(propsConfigurator); } BQDaemonTestRuntime runtime = new BQDaemonTestRuntime(localConfigurator, startupCheck, args); runtimes.add(runtime); runtime.start(startupTimeout, startupTimeoutTimeUnit); return runtime; }
@Override protected void configure() { MapBinder<String, PluginRestResource> pluginRestResourceMapBinder = MapBinder.newMapBinder(binder(), String.class, PluginRestResource.class).permitDuplicates(); }
@Override protected void configureHandlers() { // Handler bindings in alphabetical order serve(GET, handlerPrefix.prefixPath("/"), HomeHandler.class); serve(POST, handlerPrefix.prefixPath("/cache"), FileCacheHandler.class); serve(GET, handlerPrefix.prefixPath("/capture"), CaptureHandler.class); serve(GET, handlerPrefix.prefixPath("/capture/*"), CaptureHandler.class); serve(GET, handlerPrefix.prefixPath("/cmd"), CommandGetHandler.class); serve(POST, handlerPrefix.prefixPath("/cmd"), CommandPostHandler.class); serve(GET, handlerPrefix.prefixPath("/favicon.ico"), FaviconHandler.class); serve(GET, handlerPrefix.prefixPath("/fileSet"), FileSetGetHandler.class); serve(POST, handlerPrefix.prefixPath("/fileSet"), FileSetPostHandler.class); for (HttpMethod method : HttpMethod.values()) { serve(method, handlerPrefix.prefixPath("/forward/*"), ForwardingHandler.class); } serve(GET, handlerPrefix.prefixPath("/heartbeat"), HeartbeatGetHandler.class); serve(POST, handlerPrefix.prefixPath("/heartbeat"), HeartbeatPostHandler.class); serve(GET, handlerPrefix.prefixPath("/proxy", JSTD), GatewayConfigurationHandler.class); serve(POST, handlerPrefix.prefixPath("/proxy", JSTD), GatewayConfigurationHandler.class); serve(GET, handlerPrefix.prefixPath("/gateway", JSTD), GatewayConfigurationHandler.class); serve(POST, handlerPrefix.prefixPath("/gateway", JSTD), GatewayConfigurationHandler.class); serve(GET, handlerPrefix.prefixPath("/hello"), HelloHandler.class); serve(POST, handlerPrefix.prefixPath("/log"), BrowserLoggingHandler.class); serve(POST, handlerPrefix.prefixPath("/query/*"), BrowserQueryResponseHandler.class); serve(GET, handlerPrefix.prefixPath("/runner/*"), StandaloneRunnerHandler.class); serve(GET, handlerPrefix.prefixPath("/slave/*"), SlaveResourceHandler.class); if (executionType == ExecutionType.STANDALONE) { serve(GET, handlerPrefix.prefixPath("/test/*"), CachingTestResourceHandler.class); } else { serve(GET, handlerPrefix.prefixPath("/test/*"), NonCachingTestResourceHandler.class); } serve(GET, handlerPrefix.prefixPath("/quit"), QuitHandler.class); serve(GET, handlerPrefix.prefixPath("/quit/*"), QuitHandler.class); serve(GET, handlerPrefix.prefixPath("/static/*"), StaticResourceHandler.class); serve(GET, handlerPrefix.prefixPath("/bcr"), BrowserControlledRunnerHandler.class); serve(GET, handlerPrefix.prefixPath("/bcr/*"), BrowserControlledRunnerHandler.class); // Constant bindings bindConstant() .annotatedWith(BaseResourceLocation.class) .to(SlaveResourceService.RESOURCE_LOCATION); bindConstant().annotatedWith(BrowserTimeout.class).to(browserTimeout); // Miscellaneous bindings bind(CapturedBrowsers.class).toInstance(capturedBrowsers); bind(JstdTestCaseStore.class).toInstance(testCaseStore); bind(new Key<ConcurrentMap<SlaveBrowser, List<String>>>() {}) .toInstance(new ConcurrentHashMap<SlaveBrowser, List<String>>()); bind(new Key<ConcurrentMap<SlaveBrowser, Thread>>() {}) .toInstance(new ConcurrentHashMap<SlaveBrowser, Thread>()); bind(new Key<Set<FileInfo>>() {}).toInstance(new HashSet<FileInfo>()); bind(StandaloneRunnerFilesFilter.class).to(StandaloneRunnerFilesFilterImpl.class); bind(HandlerPathPrefix.class).toInstance(handlerPrefix); bind(Time.class).to(TimeImpl.class); bind(Boolean.class).annotatedWith(Names.named("debug")).toInstance(debug); bind(new TypeLiteral<Set<FileInfoScheme>>() {}).toInstance(schemes); bind(ExecutionType.class).toInstance(executionType); MapBinder<PageType, Page> pageBinder = newMapBinder(binder(), PageType.class, Page.class); pageBinder.addBinding(CONSOLE).to(ConsolePage.class).in(RequestScoped.class); pageBinder.addBinding(HEARTBEAT).to(HeartbeatPage.class).in(RequestScoped.class); pageBinder.addBinding(RUNNER).to(RunnerPage.class).in(RequestScoped.class); pageBinder.addBinding(STANDALONE_RUNNER).to(StandaloneRunnerPage.class).in(RequestScoped.class); pageBinder .addBinding(VISUAL_STANDALONE_RUNNER) .to(BrowserControlledRunnerPage.class) .in(RequestScoped.class); }
/** {@inheritDoc} */ @Override protected void configure() { bind(AuthorizationService.class).to(AuthorizationServiceImpl.class); bind(new TypeLiteral<OAuth2RequestFactory<Request>>() {}).to(RestletOAuth2RequestFactory.class); bind(ResourceOwnerConsentVerifier.class).to(OpenIdResourceOwnerConsentVerifier.class); bind(ClientRegistrationStore.class).to(OpenAMClientRegistrationStore.class); bind(OpenIdConnectClientRegistrationStore.class).to(OpenAMClientRegistrationStore.class); bind(OAuth2ProviderSettingsFactory.class).to(OpenAMOAuth2ProviderSettingsFactory.class); bind(ResourceOwnerSessionValidator.class).to(OpenAMResourceOwnerSessionValidator.class); bind(ClientAuthenticator.class).to(ClientAuthenticatorImpl.class); bind(TokenStore.class).to(OpenAMTokenStore.class); bind(OpenIdConnectTokenStore.class).to(OpenAMTokenStore.class); bind(AccessTokenService.class).to(AccessTokenServiceImpl.class); bind(ResourceOwnerAuthenticator.class).to(OpenAMResourceOwnerAuthenticator.class); bind(UserInfoService.class).to(UserInfoServiceImpl.class); bind(TokenInfoService.class).to(TokenInfoServiceImpl.class); bind(AccessTokenVerifier.class).to(RestletHeaderAccessTokenVerifier.class); bind(AccessTokenVerifier.class) .annotatedWith(named(HEADER)) .to(RestletHeaderAccessTokenVerifier.class); bind(AccessTokenVerifier.class) .annotatedWith(named(FORM_BODY)) .to(RestletFormBodyAccessTokenVerifier.class); bind(AccessTokenVerifier.class) .annotatedWith(named(QUERY_PARAM)) .to(RestletQueryParameterAccessTokenVerifier.class); bind(OpenIDConnectProvider.class).to(OpenAMOpenIDConnectProvider.class); bind(ClientDAO.class).to(OpenAMClientDAO.class); bind(OpenIdConnectClientRegistrationService.class) .to(OpenAMOpenIdConnectClientRegistrationService.class); bind(OpenAMSettings.class) .toProvider( new Provider<OpenAMSettings>() { public OpenAMSettings get() { return new OpenAMSettingsImpl( OAuth2Constants.OAuth2ProviderService.NAME, OAuth2Constants.OAuth2ProviderService.VERSION); } }); bind(OpenIDTokenIssuer.class).to(OpenAMOpenIdTokenIssuer.class); final Multibinder<AuthorizeRequestValidator> authorizeRequestValidators = Multibinder.newSetBinder(binder(), AuthorizeRequestValidator.class); authorizeRequestValidators.addBinding().to(AuthorizeRequestValidatorImpl.class); authorizeRequestValidators.addBinding().to(OpenIdConnectAuthorizeRequestValidator.class); final Multibinder<AuthorizationCodeRequestValidator> authorizationCodeRequestValidators = Multibinder.newSetBinder(binder(), AuthorizationCodeRequestValidator.class); authorizationCodeRequestValidators.addBinding().to(AuthorizationCodeRequestValidatorImpl.class); final Multibinder<ClientCredentialsRequestValidator> clientCredentialsRequestValidators = Multibinder.newSetBinder(binder(), ClientCredentialsRequestValidator.class); clientCredentialsRequestValidators.addBinding().to(ClientCredentialsRequestValidatorImpl.class); final Multibinder<PasswordCredentialsRequestValidator> passwordCredentialsRequestValidators = Multibinder.newSetBinder(binder(), PasswordCredentialsRequestValidator.class); passwordCredentialsRequestValidators .addBinding() .to(PasswordCredentialsRequestValidatorImpl.class); final MapBinder<String, GrantTypeHandler> grantTypeHandlers = MapBinder.newMapBinder(binder(), String.class, GrantTypeHandler.class); grantTypeHandlers.addBinding("client_credentials").to(ClientCredentialsGrantTypeHandler.class); grantTypeHandlers.addBinding("password").to(PasswordCredentialsGrantTypeHandler.class); grantTypeHandlers.addBinding("authorization_code").to(AuthorizationCodeGrantTypeHandler.class); grantTypeHandlers .addBinding(OAuth2Constants.TokenEndpoint.JWT_BEARER) .to(JwtBearerGrantTypeHandler.class); final Multibinder<AuthorizeRequestHook> authorizeRequestHooks = Multibinder.newSetBinder(binder(), AuthorizeRequestHook.class); authorizeRequestHooks.addBinding().to(LoginHintHook.class); final Multibinder<TokenRequestHook> tokenRequestHooks = Multibinder.newSetBinder(binder(), TokenRequestHook.class); tokenRequestHooks.addBinding().to(LoginHintHook.class); }