@Override public void configure(Binder binder) { binder.bind(JsonMapper.class); configBinder(binder).bindConfig(FeaturesConfig.class); binder.bind(TypeRegistry.class).in(Scopes.SINGLETON); binder.bind(TypeManager.class).to(TypeRegistry.class).in(Scopes.SINGLETON); jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class); newSetBinder(binder, Type.class); jsonCodecBinder(binder).bindJsonCodec(TaskStatus.class); jsonCodecBinder(binder).bindJsonCodec(TaskInfo.class); jsonCodecBinder(binder).bindJsonCodec(TaskUpdateRequest.class); }
@Override public void configure(Binder binder) { binder.bind(CassandraConnectorId.class).toInstance(new CassandraConnectorId(connectorId)); binder.bind(CassandraConnector.class).in(Scopes.SINGLETON); binder.bind(CassandraMetadata.class).in(Scopes.SINGLETON); binder.bind(CassandraSplitManager.class).in(Scopes.SINGLETON); binder.bind(CassandraTokenSplitManager.class).in(Scopes.SINGLETON); binder.bind(CassandraRecordSetProvider.class).in(Scopes.SINGLETON); binder.bind(CassandraPageSinkProvider.class).in(Scopes.SINGLETON); binder.bind(CassandraPartitionManager.class).in(Scopes.SINGLETON); binder.bind(CassandraSessionProperties.class).in(Scopes.SINGLETON); configBinder(binder).bindConfig(CassandraClientConfig.class); jsonCodecBinder(binder).bindListJsonCodec(ExtraColumnMetadata.class); }
@Override public void configure(Binder binder) { binder.bind(TypeManager.class).toInstance(typeManager); binder.bind(ExampleConnector.class).in(Scopes.SINGLETON); binder.bind(ExampleConnectorId.class).toInstance(new ExampleConnectorId(connectorId)); binder.bind(ExampleMetadata.class).in(Scopes.SINGLETON); binder.bind(ExampleClient.class).in(Scopes.SINGLETON); binder.bind(ExampleSplitManager.class).in(Scopes.SINGLETON); binder.bind(ExampleRecordSetProvider.class).in(Scopes.SINGLETON); configBinder(binder).bindConfig(ExampleConfig.class); jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class); jsonCodecBinder(binder).bindMapJsonCodec(String.class, listJsonCodec(ExampleTable.class)); }
@Override public void configure(Binder binder) { binder.bind(ElasticsearchConnector.class).in(Scopes.SINGLETON); binder.bind(ElasticsearchMetadata.class).in(Scopes.SINGLETON); binder.bind(ElasticsearchSplitManager.class).in(Scopes.SINGLETON); binder.bind(ElasticsearchRecordSetProvider.class).in(Scopes.SINGLETON); configBinder(binder).bindConfig(ElasticsearchConnectorConfig.class); jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class); jsonCodecBinder(binder).bindJsonCodec(ElasticsearchTableDescription.class); binder.install(new DecoderModule()); }
binder.bind(ServiceInventory.class).in(Scopes.SINGLETON); configBinder(binder).bindConfig(ServiceInventoryConfig.class); configBinder(binder).bindConfig(DiscoveryClientConfig.class); binder.bind(DiscoveryLookupClient.class).to(HttpDiscoveryLookupClient.class).in(Scopes.SINGLETON); binder.bind(DiscoveryAnnouncementClient.class).to(HttpDiscoveryAnnouncementClient.class).in(Scopes.SINGLETON); jsonCodecBinder(binder).bindJsonCodec(ServiceDescriptorsRepresentation.class); jsonCodecBinder(binder).bindJsonCodec(Announcement.class); binder.bind(CachingServiceSelectorFactory.class).in(Scopes.SINGLETON); binder.bind(ServiceSelectorFactory.class).to(MergingServiceSelectorFactory.class).in(Scopes.SINGLETON); binder.bind(ScheduledExecutorService.class) .annotatedWith(ForDiscoveryClient.class) .toProvider(DiscoveryExecutorProvider.class) .in(Scopes.SINGLETON);
public void configure(Binder binder) binder.disableCircularProxies(); binder.requireExplicitBindings(); binder.bind(AdminResource.class).in(Scopes.SINGLETON); binder.bind(VersionConflictExceptionMapper.class).in(Scopes.SINGLETON); binder.bind(RemoteCoordinatorFactory.class).to(HttpRemoteCoordinatorFactory.class).in(Scopes.SINGLETON); binder.bind(RemoteAgentFactory.class).to(HttpRemoteAgentFactory.class).in(Scopes.SINGLETON); binder.bind(Repository.class).to(RepositorySet.class).in(Scopes.SINGLETON); Multibinder.newSetBinder(binder, Repository.class).addBinding().to(MavenRepository.class).in(Scopes.SINGLETON); Multibinder.newSetBinder(binder, Repository.class).addBinding().to(HttpRepository.class).in(Scopes.SINGLETON); binder.bind(BinaryResource.class).in(Scopes.SINGLETON); binder.bind(SignatureVerifier.class).in(Scopes.SINGLETON); Multibinder.newSetBinder(binder, Filter.class, TheServlet.class).addBinding().to(AuthFilter.class).in(Scopes.SINGLETON); bindConfig(binder).to(AuthConfig.class); JsonCodecBinder.jsonCodecBinder(binder).bindJsonCodec(InstallationRepresentation.class); JsonCodecBinder.jsonCodecBinder(binder).bindJsonCodec(CoordinatorStatusRepresentation.class); JsonCodecBinder.jsonCodecBinder(binder).bindJsonCodec(AgentStatusRepresentation.class); JsonCodecBinder.jsonCodecBinder(binder).bindJsonCodec(SlotStatusRepresentation.class); JsonCodecBinder.jsonCodecBinder(binder).bindJsonCodec(ServiceDescriptorsRepresentation.class); JsonCodecBinder.jsonCodecBinder(binder).bindJsonCodec(ExpectedSlotStatus.class); JsonCodecBinder.jsonCodecBinder(binder).bindListJsonCodec(ServiceDescriptor.class);
@Override protected void setup(Binder binder) { configBinder(binder).bindConfig(DiscoveryConfig.class); jaxrsBinder(binder).bind(ServiceResource.class); discoveryBinder(binder).bindHttpAnnouncement("discovery"); jsonCodecBinder(binder).bindJsonCodec(Service.class); jsonCodecBinder(binder).bindListJsonCodec(Service.class); binder.bind(ServiceSelector.class).to(DiscoveryServiceSelector.class); binder.bind(StaticStore.class).to(EmptyStaticStore.class); jaxrsBinder(binder).bind(DynamicAnnouncementResource.class); binder.bind(DynamicStore.class).to(ReplicatedDynamicStore.class).in(Scopes.SINGLETON); binder.install(new ReplicatedStoreModule("dynamic", ForDynamicStore.class, InMemoryStore.class)); }
@Override public void configure(Binder binder) { // bind service inventory binder.bind(ServiceInventory.class).in(Scopes.SINGLETON); bindConfig(binder).to(ServiceInventoryConfig.class); // for legacy configurations bindConfig(binder).to(DiscoveryClientConfig.class); // bind discovery client and dependencies binder.bind(DiscoveryLookupClient.class).to(HttpDiscoveryLookupClient.class).in(Scopes.SINGLETON); binder.bind(DiscoveryAnnouncementClient.class).to(HttpDiscoveryAnnouncementClient.class).in(Scopes.SINGLETON); jsonCodecBinder(binder).bindJsonCodec(ServiceDescriptorsRepresentation.class); jsonCodecBinder(binder).bindJsonCodec(Announcement.class); // bind the http client httpClientBinder(binder).bindAsyncHttpClient("discovery", ForDiscoveryClient.class); // bind announcer binder.bind(Announcer.class).in(Scopes.SINGLETON); // Must create a multibinder for service announcements or construction will fail if no // service announcements are bound, which is legal for processes that don't have public services Multibinder.newSetBinder(binder, ServiceAnnouncement.class); binder.bind(ServiceSelectorFactory.class).to(CachingServiceSelectorFactory.class).in(Scopes.SINGLETON); MBeanModule.newExporter(binder).export(ServiceInventory.class).withGeneratedName(); }
@Override public void configure(Binder binder) { jsonCodecBinder(binder).bindJsonCodec(Integer.class); jsonCodecBinder(binder).bindJsonCodec(Integer.class); binder.bind(Dummy.class).in(Scopes.SINGLETON); } });
public void configure(Binder binder) { JsonCodecBinder codecBinder = jsonCodecBinder(binder); codecBinder.bindJsonCodec(Person.class); codecBinder.bindListJsonCodec(Person.class); codecBinder.bindMapJsonCodec(String.class, Person.class); } });
binder.bind(ServiceInventory.class).in(Scopes.SINGLETON); configBinder(binder).bindConfig(ServiceInventoryConfig.class); configBinder(binder).bindConfig(DiscoveryClientConfig.class); binder.bind(DiscoveryLookupClient.class).to(HttpDiscoveryLookupClient.class).in(Scopes.SINGLETON); binder.bind(DiscoveryAnnouncementClient.class).to(HttpDiscoveryAnnouncementClient.class).in(Scopes.SINGLETON); jsonCodecBinder(binder).bindJsonCodec(ServiceDescriptorsRepresentation.class); jsonCodecBinder(binder).bindJsonCodec(Announcement.class); binder.bind(CachingServiceSelectorFactory.class).in(Scopes.SINGLETON); binder.bind(ServiceSelectorFactory.class).to(MergingServiceSelectorFactory.class).in(Scopes.SINGLETON); binder.bind(ScheduledExecutorService.class) .annotatedWith(ForDiscoveryClient.class) .toProvider(DiscoveryExecutorProvider.class) .in(Scopes.SINGLETON);
@Override protected void setup(Binder binder) { if (!buildConfigObject(EmbeddedDiscoveryConfig.class).isEnabled()) { return; } configBinder(binder).bindConfig(DiscoveryConfig.class); jaxrsBinder(binder).bind(ServiceResource.class); discoveryBinder(binder).bindHttpAnnouncement("discovery"); jsonCodecBinder(binder).bindJsonCodec(Service.class); jsonCodecBinder(binder).bindListJsonCodec(Service.class); binder.bind(ServiceSelector.class).to(DiscoveryServiceSelector.class); binder.bind(StaticStore.class).to(EmptyStaticStore.class); jaxrsBinder(binder).bind(DynamicAnnouncementResource.class); binder.bind(DynamicStore.class).to(ReplicatedDynamicStore.class).in(Scopes.SINGLETON); binder.install(new ReplicatedStoreModule("dynamic", ForDynamicStore.class, InMemoryStore.class)); }
@Override public void configure(Binder binder) { binder.bind(KafkaConnector.class).in(Scopes.SINGLETON); binder.bind(KafkaMetadata.class).in(Scopes.SINGLETON); binder.bind(KafkaSplitManager.class).in(Scopes.SINGLETON); binder.bind(KafkaRecordSetProvider.class).in(Scopes.SINGLETON); binder.bind(KafkaSimpleConsumerManager.class).in(Scopes.SINGLETON); configBinder(binder).bindConfig(KafkaConnectorConfig.class); jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class); jsonCodecBinder(binder).bindJsonCodec(KafkaTopicDescription.class); binder.install(new DecoderModule()); }
@Test public void ignoresRepeatedBinding() { Injector injector = Guice.createInjector((Module) binder -> { jsonCodecBinder(binder).bindJsonCodec(Integer.class); jsonCodecBinder(binder).bindJsonCodec(Integer.class); binder.bind(Dummy.class).in(Scopes.SINGLETON); }); assertNotNull(injector.getInstance(Dummy.class).getCodec()); }
@Test public void test() throws Exception { Injector injector = Guice.createInjector(new JsonModule(), binder -> { JsonCodecBinder codecBinder = jsonCodecBinder(binder); codecBinder.bindJsonCodec(Person.class); codecBinder.bindListJsonCodec(Person.class); codecBinder.bindMapJsonCodec(String.class, Person.class); }); injector.injectMembers(this); assertNotNull(personJsonCodec); assertNotNull(personListJsonCodec); assertNotNull(personMapJsonCodec); Person.validatePersonJsonCodec(personJsonCodec); Person.validatePersonListJsonCodec(personListJsonCodec); Person.validatePersonMapJsonCodec(personMapJsonCodec); } }
@Override public void configure(Binder binder) binder.bind(HiveConnectorId.class).toInstance(new HiveConnectorId(connectorId)); binder.bind(TypeTranslator.class).toInstance(new HiveTypeTranslator()); binder.bind(CoercionPolicy.class).to(HiveCoercionPolicy.class).in(Scopes.SINGLETON); binder.bind(HiveSessionProperties.class).in(Scopes.SINGLETON); recordCursorProviderBinder.addBinding().to(S3SelectRecordCursorProvider.class).in(Scopes.SINGLETON); recordCursorProviderBinder.addBinding().to(GenericHiveRecordCursorProvider.class).in(Scopes.SINGLETON); binder.bind(HiveWriterStats.class).in(Scopes.SINGLETON); newExporter(binder).export(HiveWriterStats.class).as(generatedNameOf(HiveWriterStats.class, connectorId)); 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(ConnectorNodePartitioningProvider.class).to(HiveNodePartitioningProvider.class).in(Scopes.SINGLETON); jsonCodecBinder(binder).bindJsonCodec(PartitionUpdate.class); binder.bind(FileFormatDataSourceStats.class).in(Scopes.SINGLETON);
@Override public void configure(Binder binder) { // Add appender to Log4J root logger JulAppender appender = new JulAppender(); //create appender appender.setLayout(new PatternLayout("%d %-5p %c - %m%n")); appender.setThreshold(Level.INFO); appender.activateOptions(); org.apache.log4j.Logger.getRootLogger().addAppender(appender); binder.bind(TypeManager.class).toInstance(typeManager); binder.bind(AccumuloConnector.class).in(Scopes.SINGLETON); binder.bind(AccumuloConnectorId.class).toInstance(new AccumuloConnectorId(connectorId)); binder.bind(AccumuloMetadata.class).in(Scopes.SINGLETON); binder.bind(AccumuloMetadataFactory.class).in(Scopes.SINGLETON); binder.bind(AccumuloClient.class).in(Scopes.SINGLETON); binder.bind(AccumuloSplitManager.class).in(Scopes.SINGLETON); binder.bind(AccumuloRecordSetProvider.class).in(Scopes.SINGLETON); binder.bind(AccumuloPageSinkProvider.class).in(Scopes.SINGLETON); binder.bind(AccumuloHandleResolver.class).in(Scopes.SINGLETON); binder.bind(AccumuloSessionProperties.class).in(Scopes.SINGLETON); binder.bind(AccumuloTableProperties.class).in(Scopes.SINGLETON); binder.bind(ZooKeeperMetadataManager.class).in(Scopes.SINGLETON); binder.bind(AccumuloTableManager.class).in(Scopes.SINGLETON); binder.bind(IndexLookup.class).in(Scopes.SINGLETON); binder.bind(ColumnCardinalityCache.class).in(Scopes.SINGLETON); binder.bind(Connector.class).toProvider(ConnectorProvider.class); configBinder(binder).bindConfig(AccumuloConfig.class); jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class); jsonCodecBinder(binder).bindMapJsonCodec(String.class, JsonCodec.listJsonCodec(AccumuloTable.class)); }
@Override public void configure(Binder binder) { configBinder(binder).bindConfig(DiscoveryConfig.class); jaxrsBinder(binder).bind(ServiceResource.class); discoveryBinder(binder).bindHttpAnnouncement("discovery"); jsonCodecBinder(binder).bindJsonCodec(Service.class); jsonCodecBinder(binder).bindListJsonCodec(Service.class); binder.bind(ServiceSelector.class).to(DiscoveryServiceSelector.class); // dynamic announcements jaxrsBinder(binder).bind(DynamicAnnouncementResource.class); binder.bind(DynamicStore.class).to(ReplicatedDynamicStore.class).in(Scopes.SINGLETON); binder.install(new ReplicatedStoreModule("dynamic", ForDynamicStore.class, InMemoryStore.class)); // static announcements jaxrsBinder(binder).bind(StaticAnnouncementResource.class); binder.bind(StaticStore.class).to(ReplicatedStaticStore.class).in(Scopes.SINGLETON); binder.install(new ReplicatedStoreModule("static", ForStaticStore.class, PersistentStore.class)); configBinder(binder).bindConfig(PersistentStoreConfig.class, "static"); } }
@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.bind(CassandraConnectorId.class).toInstance(new CassandraConnectorId(connectorId)); binder.bind(CassandraConnector.class).in(Scopes.SINGLETON); binder.bind(CassandraMetadata.class).in(Scopes.SINGLETON); binder.bind(CassandraSplitManager.class).in(Scopes.SINGLETON); binder.bind(CassandraTokenSplitManager.class).in(Scopes.SINGLETON); binder.bind(CassandraRecordSetProvider.class).in(Scopes.SINGLETON); binder.bind(CassandraPageSinkProvider.class).in(Scopes.SINGLETON); binder.bind(CassandraPartitionManager.class).in(Scopes.SINGLETON); binder.bind(CassandraSessionProperties.class).in(Scopes.SINGLETON); configBinder(binder).bindConfig(CassandraClientConfig.class); jsonCodecBinder(binder).bindListJsonCodec(ExtraColumnMetadata.class); }