rdblue commented on code in PR #6698:
URL: https://github.com/apache/iceberg/pull/6698#discussion_r1092397423


##########
core/src/main/java/org/apache/iceberg/CatalogUtil.java:
##########
@@ -439,4 +439,44 @@ public static MetricsReporter loadMetricsReporter(String 
impl) {
 
     return reporter;
   }
+
+  /**
+   * Load a custom ClientPool implementation.
+   *
+   * <p>The ClientPool must have a no-arg constructor. If the class implements 
Configurable, a
+   * Hadoop config will be passed using Configurable.setConf. {@link 
ClientPool#initialize(Map)} is
+   * called to complete the initialization.
+   *
+   * @param impl ClientPool implementation full class name
+   * @param properties catalog properties
+   * @param conf hadoop configuration if needed
+   * @return initialized ClientPool object
+   * @throws IllegalArgumentException if no-arg constructor not found or error 
during initialization
+   */
+  public static <C, E extends Exception> ClientPool<C, E> loadClientPool(
+      String impl, Map<String, String> properties, Object conf) {
+    LOG.info("Loading custom client pool implementation: {}", impl);
+    Preconditions.checkNotNull(
+        impl,
+        "Cannot initialize custom ClientPool, impl class name is null. Please 
check the value of %s.",
+        CatalogProperties.CLIENT_POOL_IMPL);
+    DynConstructors.Ctor<ClientPool<C, E>> ctor;
+    try {
+      ctor = 
DynConstructors.builder(ClientPool.class).impl(impl).buildChecked();
+    } catch (NoSuchMethodException e) {
+      throw new IllegalArgumentException(
+          String.format("Cannot initialize ClientPool implementation %s", 
impl), e);
+    }
+    ClientPool<C, E> clientPool;
+    try {
+      clientPool = ctor.newInstance();
+    } catch (ClassCastException e) {
+      throw new IllegalArgumentException(
+          String.format("Cannot initialize ClientPool, %s does not implement 
ClientPool.", impl),
+          e);
+    }
+    configureHadoopConf(clientPool, conf);
+    clientPool.initialize(properties);
+    return clientPool;

Review Comment:
   Style: This code needs more whitespace between code blocks and statements.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to