happyer opened a new issue #1640: How to understand this snippet 
URL: https://github.com/apache/rocketmq/issues/1640
 
 
   
   
   ``` 
   public RemotingCommand invokeSyncImpl(final Channel channel, final 
RemotingCommand request,
           final long timeoutMillis)
           throws InterruptedException, RemotingSendRequestException, 
RemotingTimeoutException {
           final int opaque = request.getOpaque();
   
           try {
               final ResponseFuture responseFuture = new ResponseFuture(opaque, 
timeoutMillis, null, null);
               this.responseTable.put(opaque, responseFuture);
               final SocketAddress addr = channel.remoteAddress();
               channel.writeAndFlush(request).addListener(new 
ChannelFutureListener() {
                   @Override
                   public void operationComplete(ChannelFuture f) throws 
Exception {
                       if (f.isSuccess()) {
                           responseFuture.setSendRequestOK(true);
                           return;
                       } else {
                           responseFuture.setSendRequestOK(false);
                       }
   
                       responseTable.remove(opaque);
                       responseFuture.setCause(f.cause());
                       responseFuture.putResponse(null);
                       log.warn("send a request command to channel <" + addr + 
"> failed.");
                   }
               });
   
               RemotingCommand responseCommand = 
responseFuture.waitResponse(timeoutMillis);
               if (null == responseCommand) {
                   if (responseFuture.isSendRequestOK()) {
                       throw new 
RemotingTimeoutException(RemotingHelper.parseSocketAddressAddr(addr), 
timeoutMillis,
                           responseFuture.getCause());
                   } else {
                       throw new 
RemotingSendRequestException(RemotingHelper.parseSocketAddressAddr(addr), 
responseFuture.getCause());
                   }
               }
   
               return responseCommand;
           } finally {
               this.responseTable.remove(opaque);
           }
       }
   ``` 
   
   
   
   
   [code in the here 
](https://github.com/apache/rocketmq/blob/master/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java)
   
   
   when execution  channel.writeAndFlush(request) is complete then will invoke 
operationComplete function ,  response future will putResponse for notify 
waitResponse ,but client not recv server response ,so will throw 
RemotingTimeoutException .
   ChannelFutureListener's operationComplete will trigger when data send to NIC 
not guarantee server send response to client  
   
   
   
   this is my understanding , how to correct explain this snippet ?
   
   
   
   
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to