下面列出了com.google.inject.Binder#install ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void configure(Binder binder)
{
binder.bind(ConnectorMetadata.class).to(KafkaMetadata.class).in(Scopes.SINGLETON);
binder.bind(ConnectorSplitManager.class).annotatedWith(ForClassLoaderSafe.class).to(KafkaSplitManager.class).in(Scopes.SINGLETON);
binder.bind(ConnectorSplitManager.class).to(ClassLoaderSafeConnectorSplitManager.class).in(Scopes.SINGLETON);
binder.bind(ConnectorRecordSetProvider.class).annotatedWith(ForClassLoaderSafe.class).to(KafkaRecordSetProvider.class).in(Scopes.SINGLETON);
binder.bind(ConnectorRecordSetProvider.class).to(ClassLoaderSafeConnectorRecordSetProvider.class).in(Scopes.SINGLETON);
binder.bind(KafkaConnector.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(KafkaConfig.class);
newSetBinder(binder, TableDescriptionSupplier.class).addBinding().toProvider(KafkaTableDescriptionSupplier.class).in(Scopes.SINGLETON);
jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
jsonCodecBinder(binder).bindJsonCodec(KafkaTopicDescription.class);
binder.install(new DecoderModule());
}
@Override
public void configure(Binder binder)
{
binder.bind(RedisConnector.class).in(Scopes.SINGLETON);
binder.bind(RedisMetadata.class).in(Scopes.SINGLETON);
binder.bind(RedisSplitManager.class).in(Scopes.SINGLETON);
binder.bind(RedisRecordSetProvider.class).in(Scopes.SINGLETON);
binder.bind(RedisJedisManager.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(RedisConnectorConfig.class);
jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
jsonCodecBinder(binder).bindJsonCodec(RedisTableDescription.class);
binder.install(new RedisDecoderModule());
}
@Override
public void configure(Binder binder)
{
binder.install(new JdbcDiagnosticModule(catalogName));
newOptionalBinder(binder, ConnectorAccessControl.class);
procedureBinder(binder);
binder.bind(JdbcMetadataFactory.class).in(Scopes.SINGLETON);
newOptionalBinder(binder, ConnectorSplitManager.class).setDefault().to(JdbcSplitManager.class).in(Scopes.SINGLETON);
newOptionalBinder(binder, ConnectorRecordSetProvider.class).setDefault().to(JdbcRecordSetProvider.class).in(Scopes.SINGLETON);
newOptionalBinder(binder, ConnectorPageSinkProvider.class).setDefault().to(JdbcPageSinkProvider.class).in(Scopes.SINGLETON);
binder.bind(JdbcConnector.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(JdbcMetadataConfig.class);
configBinder(binder).bindConfig(BaseJdbcConfig.class);
configBinder(binder).bindConfig(TypeHandlingJdbcConfig.class);
bindSessionPropertiesProvider(binder, TypeHandlingJdbcSessionProperties.class);
bindSessionPropertiesProvider(binder, JdbcMetadataSessionProperties.class);
binder.bind(JdbcClient.class).to(CachingJdbcClient.class).in(Scopes.SINGLETON);
binder.bind(ConnectionFactory.class).to(Key.get(ConnectionFactory.class, StatsCollecting.class));
}
@Override
public void configure(Binder binder)
{
binder.bind(PortBinder.class);
binder.bind(EnvironmentFactory.class);
binder.bind(Standard.class);
binder.bind(Hadoop.class);
binder.bind(Kerberos.class);
binder.bind(KerberosKms.class);
binder.bind(Kafka.class);
MapBinder<String, EnvironmentProvider> environments = newMapBinder(binder, String.class, EnvironmentProvider.class);
Environments.findByBasePackage(BASE_PACKAGE).forEach(clazz -> environments.addBinding(Environments.nameForClass(clazz)).to(clazz));
binder.install(additionalEnvironments);
}
@SuppressWarnings("unchecked")
@Override
public void resolve(Binder binder) {
FactoryModuleBuilder guiceFactoryBuilder = new FactoryModuleBuilder();
for (Map.Entry<Type, Class<?>> classes : typeVariables.entries()) {
Type producedType = classes.getKey();
Class<? extends T> producedImplementationType = (Class<? extends T>) classes.getValue();
Key<T> key = BindingUtils.resolveKey(injecteeClass, producedImplementationType, producedType);
Provider<T> provider = new GenericGuiceProvider<>(injectedClass, producedImplementationType);
binder.requestInjection(provider);
binder.bind(key).toProvider(provider);
guiceFactoryBuilder.implement(key, injectedClass);
}
// Assisted factory should not be bound twice
if (bindGuiceFactory) {
TypeLiteral<?> guiceAssistedFactory = TypeLiteral.get(newParameterizedType(FACTORY_CLASS, injectedClass));
binder.install(guiceFactoryBuilder.build(guiceAssistedFactory));
}
}
@Override
protected void configure() {
final Binder lowPriorityBinder = binder().withSource(Sources.prioritize(Integer.MIN_VALUE));
lowPriorityBinder.install(new ServletModule()
{
@Override
protected void configureServlets() {
serve("/*").with(WebResourceServlet.class);
filter("/*").through(SecurityFilter.class);
}
});
lowPriorityBinder.install(new FilterChainModule()
{
@Override
protected void configure() {
addFilterChain("/**", AnonymousFilter.NAME, AntiCsrfFilter.NAME);
}
});
}
@Override
public void configure(Binder binder)
{
binder.bind(JdbcClient.class).annotatedWith(ForBaseJdbc.class).to(PostgreSqlClient.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(PostgreSqlConfig.class);
bindSessionPropertiesProvider(binder, PostgreSqlSessionProperties.class);
binder.install(new DecimalModule());
}
@Override
protected void configure() {
bind(GuiceFilter.class).to(DynamicGuiceFilter.class);
// our configuration needs to be first-most when calculating order (some fudge room for edge-cases)
final Binder highPriorityBinder = binder().withSource(Sources.prioritize(0x70000000));
highPriorityBinder.install(new ServletModule()
{
@Override
protected void configureServlets() {
bind(HeaderPatternFilter.class);
bind(EnvironmentFilter.class);
bind(ErrorPageFilter.class);
filter("/*").through(HeaderPatternFilter.class);
filter("/*").through(EnvironmentFilter.class);
filter("/*").through(ErrorPageFilter.class);
bind(ErrorPageServlet.class);
serve("/error.html").with(ErrorPageServlet.class);
serve("/throw.html").with(ThrowServlet.class);
}
});
highPriorityBinder.install(new MetricsModule());
if (getBoolean("nexus.orient.enabled", true)) {
install(new OrientModule());
}
}
@Override
public void resolve(Binder binder) {
for (Class<? extends T> impl : implementations) {
if (Arrays.stream(impl.getMethods()).anyMatch(m -> isAbstract(m.getModifiers()))) {
LOGGER.warn("Skipping default repository implementation {}: abstract methods are still present",
impl.getName());
} else {
Key<T> key = BusinessUtils.getQualifier(impl)
.map(qualifier -> Key.get(repositoryInterface, qualifier))
.orElseThrow(() -> new IllegalStateException("Missing qualifier on implementation" + impl));
if (defaultKey != null) {
binder.bind(repositoryInterface).to(defaultKey);
}
Provider<T> provider = new GenericGuiceProvider<>(impl, generics);
binder.requestInjection(provider);
binder.bind(key).toProvider(provider);
FactoryModuleBuilder guiceFactoryBuilder = new FactoryModuleBuilder();
guiceFactoryBuilder.implement(key, impl);
binder.install(guiceFactoryBuilder.build(
TypeLiteral.get(Types.newParameterizedType(FACTORY_CLASS, impl))
));
}
}
}
@Override
public void configure(Binder binder)
{
binder.install(new HiveHdfsModule());
binder.bind(IcebergTransactionManager.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(IcebergConfig.class);
binder.bind(IcebergSessionProperties.class).in(Scopes.SINGLETON);
binder.bind(IcebergTableProperties.class).in(Scopes.SINGLETON);
binder.bind(ConnectorSplitManager.class).to(IcebergSplitManager.class).in(Scopes.SINGLETON);
binder.bind(ConnectorPageSourceProvider.class).to(IcebergPageSourceProvider.class).in(Scopes.SINGLETON);
binder.bind(ConnectorPageSinkProvider.class).to(IcebergPageSinkProvider.class).in(Scopes.SINGLETON);
binder.bind(ConnectorNodePartitioningProvider.class).to(HiveNodePartitioningProvider.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(OrcReaderConfig.class);
configBinder(binder).bindConfig(OrcWriterConfig.class);
configBinder(binder).bindConfig(ParquetReaderConfig.class);
configBinder(binder).bindConfig(ParquetWriterConfig.class);
binder.bind(IcebergMetadataFactory.class).in(Scopes.SINGLETON);
jsonCodecBinder(binder).bindJsonCodec(CommitTaskData.class);
binder.bind(FileFormatDataSourceStats.class).in(Scopes.SINGLETON);
newExporter(binder).export(FileFormatDataSourceStats.class).withGeneratedName();
binder.bind(IcebergFileWriterFactory.class).in(Scopes.SINGLETON);
newExporter(binder).export(IcebergFileWriterFactory.class).withGeneratedName();
}
@Override
protected void setup(Binder binder)
{
configBinder(binder).bindConfig(GlueHiveMetastoreConfig.class);
newOptionalBinder(binder, GlueColumnStatisticsProvider.class)
.setDefault().to(DisabledGlueColumnStatisticsProvider.class).in(Scopes.SINGLETON);
newOptionalBinder(binder, Key.get(RequestHandler2.class, ForGlueHiveMetastore.class));
if (buildConfigObject(HiveConfig.class).getRecordingPath() != null) {
binder.bind(HiveMetastore.class)
.annotatedWith(ForRecordingHiveMetastore.class)
.to(GlueHiveMetastore.class)
.in(Scopes.SINGLETON);
binder.bind(GlueHiveMetastore.class).in(Scopes.SINGLETON);
newExporter(binder).export(GlueHiveMetastore.class).withGeneratedName();
binder.bind(HiveMetastore.class)
.annotatedWith(ForCachingHiveMetastore.class)
.to(RecordingHiveMetastore.class)
.in(Scopes.SINGLETON);
binder.bind(RecordingHiveMetastore.class).in(Scopes.SINGLETON);
newExporter(binder).export(RecordingHiveMetastore.class).withGeneratedName();
Multibinder<Procedure> procedures = newSetBinder(binder, Procedure.class);
procedures.addBinding().toProvider(WriteHiveMetastoreRecordingProcedure.class).in(Scopes.SINGLETON);
}
else {
binder.bind(HiveMetastore.class)
.annotatedWith(ForCachingHiveMetastore.class)
.to(GlueHiveMetastore.class)
.in(Scopes.SINGLETON);
newExporter(binder).export(HiveMetastore.class)
.as(generator -> generator.generatedNameOf(GlueHiveMetastore.class));
}
binder.install(new CachingHiveMetastoreModule());
}
@Override
protected void setup(Binder binder)
{
OptionalBinder.newOptionalBinder(binder, ThriftMetastoreClientFactory.class)
.setDefault().to(DefaultThriftMetastoreClientFactory.class).in(Scopes.SINGLETON);
binder.bind(MetastoreLocator.class).to(StaticMetastoreLocator.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(StaticMetastoreConfig.class);
configBinder(binder).bindConfig(ThriftMetastoreConfig.class);
binder.bind(ThriftMetastore.class).to(ThriftHiveMetastore.class).in(Scopes.SINGLETON);
newExporter(binder).export(ThriftMetastore.class)
.as(generator -> generator.generatedNameOf(ThriftHiveMetastore.class));
if (buildConfigObject(HiveConfig.class).getRecordingPath() != null) {
binder.bind(HiveMetastore.class)
.annotatedWith(ForRecordingHiveMetastore.class)
.to(BridgingHiveMetastore.class)
.in(Scopes.SINGLETON);
binder.bind(HiveMetastore.class)
.annotatedWith(ForCachingHiveMetastore.class)
.to(RecordingHiveMetastore.class)
.in(Scopes.SINGLETON);
binder.bind(RecordingHiveMetastore.class).in(Scopes.SINGLETON);
newExporter(binder).export(RecordingHiveMetastore.class).withGeneratedName();
Multibinder<Procedure> procedures = newSetBinder(binder, Procedure.class);
procedures.addBinding().toProvider(WriteHiveMetastoreRecordingProcedure.class).in(Scopes.SINGLETON);
}
else {
binder.bind(HiveMetastore.class)
.annotatedWith(ForCachingHiveMetastore.class)
.to(BridgingHiveMetastore.class)
.in(Scopes.SINGLETON);
}
binder.install(new CachingHiveMetastoreModule());
install(new ThriftMetastoreAuthenticationModule());
}
@Override
public void configure(Binder binder)
{
configBinder(binder).bindConfig(FileHiveMetastoreConfig.class);
binder.bind(HiveMetastore.class).annotatedWith(ForCachingHiveMetastore.class).to(FileHiveMetastore.class).in(Scopes.SINGLETON);
binder.install(new CachingHiveMetastoreModule());
}
@Override
public void configure(Binder binder)
{
binder.bind(KinesisDecoderRegistry.class).in(Scopes.SINGLETON);
binder.install(new DummyKinesisDecoderModule());
binder.install(new CsvKinesisDecoderModule());
binder.install(new JsonKinesisDecoderModule());
binder.install(new RawKinesisDecoderModule());
}
/**
* @since 2.8
*/
public void configureResourceDescriptionsProvider(Binder binder) {
if (Activator.isJavaEnabled()) {
binder.install(new ResourceDescriptionsProviderModule());
} else {
binder.bind(ResourceDescriptionsProvider.class).in(Scopes.SINGLETON);
}
binder.bind(IResourceDescriptions.class).annotatedWith(Names.named(ResourceDescriptionsProvider.LIVE_SCOPE))
.to(LiveShadowedResourceDescriptions.class);
binder.bind(IResourceDescriptions.class).annotatedWith(Names.named(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE))
.to(CurrentDescriptions.ResourceSetAware.class);
binder.bind(org.eclipse.xtext.resource.IResourceDescriptions.class).annotatedWith(Names.named(ResourceDescriptionsProvider.PERSISTED_DESCRIPTIONS)).to(IBuilderState.class);
}
protected Module getWrappedModule(final Module childModule) {
return new Module() {
@Override
public void configure(Binder binder) {
binder.bind(SharedStateContribution.class);
binder.install(childModule);
}
};
}
@Override
public void configure(Binder binder) {
binder.install(new BaragonDataModule());
binder.install(new BaragonResourcesModule());
// Healthcheck
binder.bind(ZooKeeperHealthcheck.class).in(Scopes.SINGLETON);
binder.bind(BaragonExceptionNotifier.class).in(Scopes.SINGLETON);
// Managed
binder.bind(BaragonExceptionNotifierManaged.class).asEagerSingleton();
binder.bind(BaragonGraphiteReporterManaged.class).asEagerSingleton();
binder.bind(BaragonManaged.class).asEagerSingleton();
// Managers
binder.bind(AgentManager.class).in(Scopes.SINGLETON);
binder.bind(ElbManager.class).in(Scopes.SINGLETON);
binder.bind(RequestManager.class).in(Scopes.SINGLETON);
binder.bind(ServiceManager.class).in(Scopes.SINGLETON);
binder.bind(StatusManager.class).in(Scopes.SINGLETON);
binder.bind(GoogleCloudManager.class).in(Scopes.SINGLETON);
// Edge Cache
binder.bind(CloudflareEdgeCache.class);
binder.bind(CloudflareClient.class);
binder.bind(EdgeCache.class).to(getConfiguration().getEdgeCacheConfiguration().getEdgeCache().getEdgeCacheClass());
// Workers
binder.bind(BaragonElbSyncWorker.class).in(Scopes.SINGLETON);
binder.bind(BaragonRequestWorker.class).in(Scopes.SINGLETON);
binder.bind(RequestPurgingWorker.class).in(Scopes.SINGLETON);
binder.bind(ClassicLoadBalancer.class);
binder.bind(ApplicationLoadBalancer.class);
Multibinder<AbstractLatchListener> latchBinder = Multibinder.newSetBinder(binder, AbstractLatchListener.class);
latchBinder.addBinding().to(RequestWorkerListener.class).in(Scopes.SINGLETON);
latchBinder.addBinding().to(ElbSyncWorkerListener.class).in(Scopes.SINGLETON);
latchBinder.addBinding().to(RequestPurgingListener.class).in(Scopes.SINGLETON);
}
@Override
public void configure(Binder binder)
{
binder.install(new HiveHdfsModule());
binder.bind(TypeTranslator.class).toInstance(new HiveTypeTranslator());
binder.bind(CoercionPolicy.class).to(HiveCoercionPolicy.class).in(Scopes.SINGLETON);
binder.bind(DirectoryLister.class).to(CachingDirectoryLister.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(HiveConfig.class);
binder.bind(HiveSessionProperties.class).in(Scopes.SINGLETON);
binder.bind(HiveTableProperties.class).in(Scopes.SINGLETON);
binder.bind(HiveAnalyzeProperties.class).in(Scopes.SINGLETON);
binder.bind(PrestoS3ClientFactory.class).in(Scopes.SINGLETON);
binder.bind(CachingDirectoryLister.class).in(Scopes.SINGLETON);
newExporter(binder).export(CachingDirectoryLister.class).withGeneratedName();
binder.bind(HiveWriterStats.class).in(Scopes.SINGLETON);
newExporter(binder).export(HiveWriterStats.class).withGeneratedName();
newSetBinder(binder, EventClient.class).addBinding().to(HiveEventClient.class).in(Scopes.SINGLETON);
binder.bind(HivePartitionManager.class).in(Scopes.SINGLETON);
binder.bind(LocationService.class).to(HiveLocationService.class).in(Scopes.SINGLETON);
binder.bind(HiveMetadataFactory.class).in(Scopes.SINGLETON);
binder.bind(TransactionalMetadataFactory.class).to(HiveMetadataFactory.class).in(Scopes.SINGLETON);
binder.bind(HiveTransactionManager.class).in(Scopes.SINGLETON);
binder.bind(ConnectorSplitManager.class).to(HiveSplitManager.class).in(Scopes.SINGLETON);
newExporter(binder).export(ConnectorSplitManager.class).as(generator -> generator.generatedNameOf(HiveSplitManager.class));
binder.bind(ConnectorPageSourceProvider.class).to(HivePageSourceProvider.class).in(Scopes.SINGLETON);
binder.bind(ConnectorPageSinkProvider.class).to(HivePageSinkProvider.class).in(Scopes.SINGLETON);
binder.bind(ConnectorNodePartitioningProvider.class).to(HiveNodePartitioningProvider.class).in(Scopes.SINGLETON);
jsonCodecBinder(binder).bindJsonCodec(PartitionUpdate.class);
binder.bind(FileFormatDataSourceStats.class).in(Scopes.SINGLETON);
newExporter(binder).export(FileFormatDataSourceStats.class).withGeneratedName();
Multibinder<HivePageSourceFactory> pageSourceFactoryBinder = newSetBinder(binder, HivePageSourceFactory.class);
pageSourceFactoryBinder.addBinding().to(OrcPageSourceFactory.class).in(Scopes.SINGLETON);
pageSourceFactoryBinder.addBinding().to(ParquetPageSourceFactory.class).in(Scopes.SINGLETON);
pageSourceFactoryBinder.addBinding().to(RcFilePageSourceFactory.class).in(Scopes.SINGLETON);
Multibinder<HiveRecordCursorProvider> recordCursorProviderBinder = newSetBinder(binder, HiveRecordCursorProvider.class);
recordCursorProviderBinder.addBinding().to(S3SelectRecordCursorProvider.class).in(Scopes.SINGLETON);
binder.bind(GenericHiveRecordCursorProvider.class).in(Scopes.SINGLETON);
Multibinder<HiveFileWriterFactory> fileWriterFactoryBinder = newSetBinder(binder, HiveFileWriterFactory.class);
binder.bind(OrcFileWriterFactory.class).in(Scopes.SINGLETON);
newExporter(binder).export(OrcFileWriterFactory.class).withGeneratedName();
configBinder(binder).bindConfig(OrcReaderConfig.class);
configBinder(binder).bindConfig(OrcWriterConfig.class);
fileWriterFactoryBinder.addBinding().to(OrcFileWriterFactory.class).in(Scopes.SINGLETON);
fileWriterFactoryBinder.addBinding().to(RcFileFileWriterFactory.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(ParquetReaderConfig.class);
configBinder(binder).bindConfig(ParquetWriterConfig.class);
fileWriterFactoryBinder.addBinding().to(ParquetFileWriterFactory.class).in(Scopes.SINGLETON);
jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
newSetBinder(binder, SystemTable.class);
}
public void configureAdditionalBindings(Binder binder) {
binder.install(language.getGuiceModule());
}
private DriftClientBinder(Binder binder)
{
this.binder = requireNonNull(binder, "binder is null").skipSources(this.getClass());
binder.install(new ThriftCodecModule());
binder.install(new DriftClientBinderModule());
}