collado-mike commented on code in PR #493:
URL: https://github.com/apache/polaris/pull/493#discussion_r1870024498
##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -63,69 +88,206 @@ public class PolarisApplicationConfig extends
Configuration {
private String awsSecretKey;
private FileIOFactory fileIOFactory;
private RateLimiter rateLimiter;
+ private TokenBrokerFactory tokenBrokerFactory;
private AccessToken gcpAccessToken;
public static final long REQUEST_BODY_BYTES_NO_LIMIT = -1;
private long maxRequestBodyBytes = REQUEST_BODY_BYTES_NO_LIMIT;
+ @Inject ServiceLocator serviceLocator;
+
+ @PostConstruct
+ public void bindToServiceLocator() {
+ ServiceLocatorUtilities.bind(serviceLocator, binder());
+ }
+
+ @NotNull
+ public AbstractBinder binder() {
+ PolarisApplicationConfig config = this;
+ return new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bindFactory(SupplierFactory.create(serviceLocator,
config::getStorageIntegrationProvider))
+ .to(PolarisStorageIntegrationProvider.class)
+ .ranked(OVERRIDE_BINDING_RANK);
+ bindFactory(SupplierFactory.create(serviceLocator,
config::getMetaStoreManagerFactory))
+ .to(MetaStoreManagerFactory.class)
+ .ranked(OVERRIDE_BINDING_RANK);
+ bindFactory(SupplierFactory.create(serviceLocator,
config::createConfigurationStore))
+ .to(PolarisConfigurationStore.class)
+ .ranked(OVERRIDE_BINDING_RANK);
+ bindFactory(SupplierFactory.create(serviceLocator,
config::getFileIOFactory))
+ .to(FileIOFactory.class)
+ .ranked(OVERRIDE_BINDING_RANK);
+ bindFactory(SupplierFactory.create(serviceLocator,
config::getPolarisAuthenticator))
+ .to(Authenticator.class)
+ .ranked(OVERRIDE_BINDING_RANK);
+ bindFactory(SupplierFactory.create(serviceLocator,
config::getTokenBrokerFactory))
+ .to(TokenBrokerFactory.class)
+ .ranked(OVERRIDE_BINDING_RANK);
+ bindFactory(SupplierFactory.create(serviceLocator,
config::getOauth2Service))
+ .to(IcebergRestOAuth2ApiService.class)
+ .ranked(OVERRIDE_BINDING_RANK);
+ bindFactory(SupplierFactory.create(serviceLocator,
config::getCallContextResolver))
+ .to(CallContextResolver.class)
+ .ranked(OVERRIDE_BINDING_RANK);
+ bindFactory(SupplierFactory.create(serviceLocator,
config::getRealmContextResolver))
+ .to(RealmContextResolver.class)
+ .ranked(OVERRIDE_BINDING_RANK);
+ bindFactory(SupplierFactory.create(serviceLocator,
config::getRateLimiter))
+ .to(RateLimiter.class)
+ .ranked(OVERRIDE_BINDING_RANK);
+ }
+ };
+ }
+
+ /**
+ * Factory implementation that uses the provided supplier method to retrieve
the instance and then
+ * uses the {@link #serviceLocator} to inject dependencies into the
instance. This is necessary
+ * since the DI framework doesn't automatically inject dependencies into the
instances created.
+ *
+ * @param <T>
+ */
+ private static final class SupplierFactory<T> implements Factory<T> {
+ private final ServiceLocator serviceLocator;
+ private final Supplier<T> supplier;
+
+ private static <T> SupplierFactory<T> create(
+ ServiceLocator serviceLocator, Supplier<T> supplier) {
+ return new SupplierFactory<>(serviceLocator, supplier);
+ }
+
+ private SupplierFactory(ServiceLocator serviceLocator, Supplier<T>
supplier) {
+ this.serviceLocator = serviceLocator;
+ this.supplier = supplier;
+ }
+
+ @Override
+ public T provide() {
+ T obj = supplier.get();
+ serviceLocator.inject(obj);
+ return obj;
+ }
+
+ @Override
+ public void dispose(T instance) {}
+ }
+
+ public <T> T findService(Class<T> serviceClass) {
Review Comment:
It doesn't, but the servlet filters don't use DI, so the PolarisApplication
has to find them somehow
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]