lhotari commented on code in PR #19327:
URL: https://github.com/apache/pulsar/pull/19327#discussion_r1088063810


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarChannelInitializer.java:
##########
@@ -209,5 +209,33 @@ CompletableFuture<Channel> initSocks5IfConfig(Channel ch) {
 
         return initSocks5Future;
     }
+
+    CompletableFuture<Channel> initializeClientCnx(Channel ch,
+                                                   InetSocketAddress 
logicalAddress,
+                                                   InetSocketAddress 
resolvedPhysicalAddress) {
+        CompletableFuture<Channel> initFuture = new CompletableFuture<>();
+        ch.eventLoop().execute(() -> {
+            final ClientCnx cnx = (ClientCnx) ch.pipeline().get("handler");
+
+            if (cnx == null) {
+                initFuture
+                        .completeExceptionally(new 
IllegalStateException("Missing ClientCnx. This should not happen."));
+            }
+
+            // Need to do our own equality because the physical address is 
resolved already
+            if 
(!(logicalAddress.getHostString().equalsIgnoreCase(resolvedPhysicalAddress.getHostString())
+                    && logicalAddress.getPort() == 
resolvedPhysicalAddress.getPort())) {
+                // We are connecting through a proxy. We need to set the 
target broker in the ClientCnx object so that
+                // it can be specified when sending the CommandConnect.
+                cnx.setTargetBroker(logicalAddress);
+            }
+
+            cnx.setRemoteHostName(resolvedPhysicalAddress.getHostString());
+
+            initFuture.complete(ch);
+        });

Review Comment:
   instead of handling the CompletableFuture logic manually, it might be good 
to use `NettyFutureUtil.toCompletableFuture(ch.eventLoop().submit(() -> {...}, 
ch))`.
   
   The benefit of this is that all exceptions would be caught. 



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