@Override public void configure(Binder binder) { Multibinder<Procedure> procedures = newSetBinder(binder, Procedure.class); procedures.addBinding().toProvider(CreateEmptyPartitionProcedure.class).in(Scopes.SINGLETON); } }
public static void bindAnnouncer( final Binder binder, final Class<? extends Annotation> annotation, final DiscoverySideEffectsProvider provider ) { binder.bind(DiscoverySideEffectsProvider.Child.class) .annotatedWith(annotation) .toProvider(provider) .in(LazySingleton.class); LifecycleModule.registerKey(binder, Key.get(DiscoverySideEffectsProvider.Child.class, annotation)); }
@Override protected void configure() { bind(ConfigManager.class).to(DefaultConfigManager.class).in(Singleton.class); bind(ConfigFactoryManager.class).to(DefaultConfigFactoryManager.class).in(Singleton.class); bind(ConfigRegistry.class).to(DefaultConfigRegistry.class).in(Singleton.class); bind(ConfigFactory.class).to(DefaultConfigFactory.class).in(Singleton.class); bind(ConfigUtil.class).in(Singleton.class); bind(HttpUtil.class).in(Singleton.class); bind(ConfigServiceLocator.class).in(Singleton.class); bind(RemoteConfigLongPollService.class).in(Singleton.class); } }
bind(LocalMetricRegistry.class).in(Scopes.NO_SCOPE); // must not be a singleton! bind(InputBuffer.class).to(InputBufferImpl.class); bind(NodeId.class).toProvider(NodeIdProvider.class); bind(EventBus.class).toProvider(EventBusProvider.class).in(Scopes.SINGLETON); bind(OkHttpClient.class).annotatedWith(Names.named("systemHttpClient")).toProvider(SystemOkHttpClientProvider.class).asEagerSingleton(); bind(ExecutorService.class).annotatedWith(Names.named("proxiedRequestsExecutorService")).toProvider(ProxiedRequestsExecutorService.class).asEagerSingleton();
@Override public void configure(Binder binder) { binder.bind(HostAndPort.class).annotatedWith(named(HTTP_HOST_AND_PORT)).toProvider(SingularityHostAndPortProvider.class).in(Scopes.SINGLETON); binder.bind(LeaderLatch.class).to(SingularityLeaderLatch.class).in(Scopes.SINGLETON); binder.bind(CuratorFramework.class).toProvider(SingularityCuratorProvider.class).in(Scopes.SINGLETON); connectionStateListeners.addBinding().to(SingularityAbort.class).in(Scopes.SINGLETON); leaderLatchListeners.addBinding().to(SingularityLeaderController.class).in(Scopes.SINGLETON); binder.bind(SingularityLeaderController.class).in(Scopes.SINGLETON); if (configuration.getSmtpConfigurationOptional().isPresent()) { binder.bind(SingularityMailer.class).to(SmtpMailer.class).in(Scopes.SINGLETON); binder.bind(SingularitySmtpSender.class).in(Scopes.SINGLETON); binder.bind(MailTemplateHelpers.class).in(Scopes.SINGLETON); binder.bind(SingularityExceptionNotifier.class).in(Scopes.SINGLETON); binder.bind(LoadBalancerClient.class).to(LoadBalancerClientImpl.class).in(Scopes.SINGLETON); binder.bind(ObjectMapper.class).toProvider(DropwizardObjectMapperProvider.class).in(Scopes.SINGLETON); binder.bind(MetricRegistry.class).toProvider(DropwizardMetricRegistryProvider.class).in(Scopes.SINGLETON); binder.bind(AsyncHttpClient.class).to(SingularityAsyncHttpClient.class).in(Scopes.SINGLETON); binder.bind(ScheduledExecutorService.class).annotatedWith(HEALTHCHECK_THREADPOOL_NAMED).toProvider(new SingularityManagedScheduledExecutorServiceProvider(configuration.getHealthcheckStartThreads(), configuration.getThreadpoolShutdownDelayInSeconds(), "healthcheck")).in(Scopes.SINGLETON); binder.bind(ScheduledExecutorService.class).annotatedWith(NEW_TASK_THREADPOOL_NAMED).toProvider(new SingularityManagedScheduledExecutorServiceProvider(configuration.getCheckNewTasksScheduledThreads(),
private static void bindEventClientClasses(Set<String> eventClientTypes, Multibinder<EventClient> multibinder) { for (String eventClientType : eventClientTypes) { if (eventClientType.equals("human-readable")) { multibinder.addBinding().to(HumanReadableEventClient.class).in(Scopes.SINGLETON); } else if (eventClientType.equals("file")) { multibinder.addBinding().to(JsonEventClient.class).in(Scopes.SINGLETON); } } } }
@Override protected void configure() { install( new AetherModule() ); bind( ArtifactDescriptorReader.class ).to( DefaultArtifactDescriptorReader.class ).in( Singleton.class ); bind( VersionResolver.class ).to( DefaultVersionResolver.class ).in( Singleton.class ); bind( VersionRangeResolver.class ).to( DefaultVersionRangeResolver.class ).in( Singleton.class ); bind( MetadataGeneratorFactory.class ).annotatedWith( Names.named( "snapshot" ) ) .to( SnapshotMetadataGeneratorFactory.class ).in( Singleton.class ); bind( MetadataGeneratorFactory.class ).annotatedWith( Names.named( "versions" ) ) .to( VersionsMetadataGeneratorFactory.class ).in( Singleton.class ); bind( ModelBuilder.class ).toInstance( new DefaultModelBuilderFactory().newInstance() ); }
@Override public void configure(Binder binder) { if (annotation != null) { JsonConfigProvider.bind(binder, propertyPrefix, DruidHttpClientConfig.class, annotation); binder.bind(HttpClient.class) .annotatedWith(annotation) .toProvider(new HttpClientProvider(annotation)) .in(LazySingleton.class); } else if (annotationClazz != null) { JsonConfigProvider.bind(binder, propertyPrefix, DruidHttpClientConfig.class, annotationClazz); binder.bind(HttpClient.class) .annotatedWith(annotationClazz) .toProvider(new HttpClientProvider(annotationClazz)) .in(LazySingleton.class); } else { JsonConfigProvider.bind(binder, propertyPrefix, DruidHttpClientConfig.class); binder.bind(HttpClient.class) .toProvider(new HttpClientProvider()) .in(LazySingleton.class); } }
@Override protected void configure() { bind(Datastore.class).to(CassandraDatastore.class).in(Scopes.SINGLETON); bind(ServiceKeyStore.class).to(CassandraDatastore.class).in(Scopes.SINGLETON); bind(CassandraDatastore.class).in(Scopes.SINGLETON); bind(CleanRowKeyCache.class).in(Scopes.SINGLETON); bind(CassandraConfiguration.class).in(Scopes.SINGLETON); //bind(CassandraClient.class).to(CassandraClientImpl.class); //bind(CassandraClientImpl.class).in(Scopes.SINGLETON); bind(BatchStats.class).in(Scopes.SINGLETON); bind(new TypeLiteral<Map<String, String>>(){}).annotatedWith(Names.named(CASSANDRA_AUTH_MAP)) .toInstance(m_authMap); /*bind(new TypeLiteral<Map<String, Object>>(){}).annotatedWith(Names.named(CASSANDRA_HECTOR_MAP)) .toInstance(m_hectorMap);*/ install(new FactoryModuleBuilder().build(BatchHandlerFactory.class)); install(new FactoryModuleBuilder().build(DeleteBatchHandlerFactory.class)); install(new FactoryModuleBuilder().build(CQLBatchFactory.class)); install(new FactoryModuleBuilder().build(CQLFilteredRowKeyIteratorFactory.class)); }
@Override public void configure(Binder binder) { createBindingChoices(binder, TYPE); super.configure(binder); binder.bind(MetadataStorage.class).toProvider(NoopMetadataStorageProvider.class); PolyBind.optionBinder(binder, Key.get(MetadataStorageProvider.class)) .addBinding(TYPE) .to(DerbyMetadataStorageProvider.class) .in(LazySingleton.class); PolyBind.optionBinder(binder, Key.get(MetadataStorageConnector.class)) .addBinding(TYPE) .to(DerbyConnector.class) .in(LazySingleton.class); PolyBind.optionBinder(binder, Key.get(SQLMetadataConnector.class)) .addBinding(TYPE) .to(DerbyConnector.class) .in(LazySingleton.class); PolyBind.optionBinder(binder, Key.get(MetadataStorageActionHandlerFactory.class)) .addBinding(TYPE) .to(DerbyMetadataStorageActionHandlerFactory.class) .in(LazySingleton.class); } }
/** * Initializes optional default command that will be executed if no explicit command is found in startup arguments. * * @param commandType a class of the default command. * @return this extender instance. */ public BQCoreModuleExtender setDefaultCommand(Class<? extends Command> commandType) { binder.bind(Key.get(Command.class, DefaultCommand.class)).to(commandType).in(Singleton.class); return this; }
@Override protected void configure() { bind(a).to(b); bind(b).to(c); bind(c).toProvider(Providers.of("c")).in(Scopes.NO_SCOPE); bind(d).toInstance("d"); bind(e).toProvider(Providers.of("e")).asEagerSingleton(); bind(f).toProvider(Providers.of("f")).in(Scopes.SINGLETON); bind(g).toProvider(Providers.of("g")).in(Singleton.class); bind(h).toProvider(Providers.of("h")).in(CustomScoped.class); bindScope(CustomScoped.class, Scopes.NO_SCOPE); install( new PrivateModule() { @Override protected void configure() { bind(i).toProvider(Providers.of("i")).in(CustomScoped.class); expose(i); } }); }
@Override protected void configure() { bind(a).to(b); bind(b).to(c); bind(c).toProvider(Providers.of("c")).in(ServletScopes.REQUEST); bind(d).toProvider(Providers.of("d")).in(RequestScoped.class); bind(e).to(AnnotatedRequestScopedClass.class); install( new PrivateModule() { @Override protected void configure() { bind(f).toProvider(Providers.of("f")).in(RequestScoped.class); expose(f); } }); }
.setDefault().toProvider(ObjectMapperProvider.class).in(Singleton.class); .setDefault().toProvider(XmlMapperProvider.class).in(Singleton.class);
@Override public void configure(Binder binder) { MapBinder<String, RowDecoderFactory> decoderFactoriesByName = MapBinder.newMapBinder(binder, String.class, RowDecoderFactory.class); decoderFactoriesByName.addBinding(DummyRowDecoder.NAME).to(DummyRowDecoderFactory.class).in(SINGLETON); decoderFactoriesByName.addBinding(CsvRowDecoder.NAME).to(CsvRowDecoderFactory.class).in(SINGLETON); decoderFactoriesByName.addBinding(JsonRowDecoder.NAME).to(JsonRowDecoderFactory.class).in(SINGLETON); decoderFactoriesByName.addBinding(RawRowDecoder.NAME).to(RawRowDecoderFactory.class).in(SINGLETON); decoderFactoriesByName.addBinding(AvroRowDecoder.NAME).to(AvroRowDecoderFactory.class).in(SINGLETON); binder.bind(DispatchingRowDecoderFactory.class).in(SINGLETON); } }
public void bindJsonCodec(Class<?> type) { requireNonNull(type, "type is null"); binder.bind(getJsonCodecKey(type)).toProvider(new JsonCodecProvider(type)).in(Scopes.SINGLETON); }