@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 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);
 }
 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();
     }
   }
 }
 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);
 }
  @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);
  }
 @Override
 protected void configure() {
   MapBinder<String, PluginRestResource> pluginRestResourceMapBinder =
       MapBinder.newMapBinder(binder(), String.class, PluginRestResource.class).permitDuplicates();
 }
  /** {@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);
  }