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


##########
pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java:
##########
@@ -313,6 +334,43 @@ private synchronized void completeConnect(AuthData 
clientData) throws PulsarClie
         }
     }
 
+    private void handleBrokerConnected(DirectProxyHandler directProxyHandler, 
CommandConnected connected) {
+        checkState(ctx.executor().inEventLoop(), "This method should be called 
in the event loop");
+        if (state == State.ProxyConnectingToBroker && ctx.channel().isOpen() 
&& this.directProxyHandler == null) {
+            this.directProxyHandler = directProxyHandler;
+            state = State.ProxyConnectionToBroker;
+            int maxMessageSize =
+                    connected.hasMaxMessageSize() ? 
connected.getMaxMessageSize() : Commands.INVALID_MAX_MESSAGE_SIZE;
+            
ctx.writeAndFlush(Commands.newConnected(connected.getProtocolVersion(), 
maxMessageSize))
+                    
.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
+        } else {
+            LOG.warn("[{}] Channel is {}. ProxyConnection is in {}. "
+                            + "Closing connection to broker '{}'.",
+                    remoteAddress, ctx.channel().isOpen() ? "open" : "already 
closed",
+                    state != State.ProxyConnectingToBroker ? "invalid state " 
+ state : "state " + state,
+                    proxyToBrokerUrl);
+            directProxyHandler.close();

Review Comment:
   `directProxyHandler` is the method parameter in this case. it's not set to 
any field at this point. The instance will only be set to the field if the 
state is what is expected (`state == State.ProxyConnectingToBroker && 
ctx.channel().isOpen() && this.directProxyHandler == null`). 



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