superhx commented on code in PR #6646:
URL: https://github.com/apache/rocketmq/pull/6646#discussion_r1176380128


##########
remoting/src/main/java/org/apache/rocketmq/remoting/RemotingClient.java:
##########
@@ -45,6 +47,30 @@ void invokeOneway(final String addr, final RemotingCommand 
request, final long t
         throws InterruptedException, RemotingConnectException, 
RemotingTooMuchRequestException,
         RemotingTimeoutException, RemotingSendRequestException;
 
+    default CompletableFuture<RemotingCommand> invoke(final String addr, final 
RemotingCommand request,
+        final long timeoutMillis) {
+        CompletableFuture<RemotingCommand> future = new CompletableFuture<>();
+        try {
+            invokeAsync(addr, request, timeoutMillis, responseFuture -> {
+                RemotingCommand response = responseFuture.getResponseCommand();
+                if (response != null) {
+                    future.complete(response);
+                } else {
+                    if (!responseFuture.isSendRequestOK()) {
+                        future.completeExceptionally(new 
RemotingSendRequestException(addr, responseFuture.getCause()));
+                    } else if (responseFuture.isTimeout()) {
+                        future.completeExceptionally(new 
RemotingTimeoutException(addr, timeoutMillis, responseFuture.getCause()));
+                    } else {
+                        future.completeExceptionally(new 
RemotingException(request.toString(), responseFuture.getCause()));
+                    }
+                }
+            });
+        } catch (Exception e) {

Review Comment:
   Suggest catch Throwable instead of Exception.



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