Copilot commented on code in PR #24790:
URL: https://github.com/apache/pulsar/pull/24790#discussion_r2384254457


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java:
##########
@@ -1415,4 +1417,36 @@ InstrumentProvider instrumentProvider() {
     public TransactionBuilder newTransaction() {
         return new TransactionBuilderImpl(this, tcClient);
     }
+
+    NameResolver<InetAddress> getNameResolver() {
+        return DnsResolverUtil.adaptToNameResolver(addressResolver);
+    }
+
+    /**
+     * Use reflection to extract Netty NameResolver from addressResolver 
instance.
+     * @param addressResolver Netty AddressResolver instance
+     * @return Netty NameResolver instance
+     */
+    @SuppressWarnings("unchecked")
+    private NameResolver<InetAddress> 
extractNameResolver(AddressResolver<InetSocketAddress> addressResolver) {
+        if (InetSocketAddressResolver.class.isInstance(addressResolver)) {
+            try {
+                Field nameResolverField =
+                        
FieldUtils.getDeclaredField(InetSocketAddressResolver.class, "nameResolver", 
true);
+                if (nameResolverField != null) {
+                    return (NameResolver<InetAddress>) 
FieldUtils.readField(nameResolverField, addressResolver);
+                } else {
+                    log.warn("Could not find nameResolver Field in 
InetSocketAddressResolver");
+                }
+            } catch (Throwable t) {
+                log.warn("Failed to extract NameResolver from addressResolver. 
DNS resolver won't be shared for HTTP "
+                        + "client.", t);
+            }
+        } else {
+            log.warn("Cannot extract NameResolver from addressResolver 
instance. DNS resolver won't be shared for HTTP "
+                    + "client.");
+        }
+        // fallback to JDK default resolver
+        return new DefaultNameResolver(ImmediateEventExecutor.INSTANCE);
+    }

Review Comment:
   This method is defined but never used. The functionality has been moved to 
`DnsResolverUtil.adaptToNameResolver()`. This unused method should be removed 
to avoid code duplication and confusion.
   ```suggestion
   
   ```



##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientSharedResourcesBuilderImpl.java:
##########
@@ -0,0 +1,283 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl;
+
+import com.google.common.collect.Lists;
+import java.net.InetSocketAddress;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import org.apache.pulsar.client.api.DnsResolverConfig;
+import org.apache.pulsar.client.api.EventLoopGroupConfig;
+import org.apache.pulsar.client.api.PulsarClientSharedResources;
+import org.apache.pulsar.client.api.PulsarClientSharedResourcesBuilder;
+import org.apache.pulsar.client.api.ThreadPoolConfig;
+import org.apache.pulsar.client.api.TimerConfig;
+import org.apache.pulsar.common.util.netty.DnsResolverUtil;
+
+public class PulsarClientSharedResourcesBuilderImpl implements 
PulsarClientSharedResourcesBuilder {
+    Set<PulsarClientSharedResources.SharedResource> sharedResources = new 
HashSet<>();
+    Map<PulsarClientSharedResources.SharedResource, ResourceConfig> 
resourceConfigs = new HashMap<>();
+    private boolean shareConfigured;
+
+    interface ResourceConfig {
+
+    }
+
+    abstract static class NamedResourceConfig<T> implements ResourceConfig {
+        String name;
+
+        public T name(String name) {
+            this.name = name;
+            return self();
+        }
+
+        @SuppressWarnings("unchecked")
+        T self() {
+            return (T) this;
+        }
+    }
+
+    static class ThreadPoolResourceConfig extends 
NamedResourceConfig<ThreadPoolConfig> implements ThreadPoolConfig {
+        int numberOfThreads = Runtime.getRuntime().availableProcessors();
+        boolean daemon = Thread.currentThread().isDaemon();
+
+        @Override
+        public ThreadPoolConfig numberOfThreads(int numberOfThreads) {
+            this.numberOfThreads = numberOfThreads;
+            return this;
+        }
+
+        @Override
+        public ThreadPoolConfig daemon(boolean daemon) {

Review Comment:
   The generic type parameter should match the implementing class. This should 
be `ThreadPoolResourceConfig` instead of `ThreadPoolConfig` to maintain proper 
type safety in the fluent interface.
   ```suggestion
       static class ThreadPoolResourceConfig extends 
NamedResourceConfig<ThreadPoolResourceConfig> implements ThreadPoolConfig {
           int numberOfThreads = Runtime.getRuntime().availableProcessors();
           boolean daemon = Thread.currentThread().isDaemon();
   
           @Override
           public ThreadPoolResourceConfig numberOfThreads(int numberOfThreads) 
{
               this.numberOfThreads = numberOfThreads;
               return this;
           }
   
           @Override
           public ThreadPoolResourceConfig daemon(boolean daemon) {
   ```



-- 
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]

Reply via email to