Apache9 commented on a change in pull request #287: HBASE-21512 Reimplement
sync client based on async client
URL: https://github.com/apache/hbase/pull/287#discussion_r291827519
##########
File path:
hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java
##########
@@ -695,4 +606,94 @@ static void updateStats(Optional<ServerStatisticTracker>
optStats,
metrics -> ResultStatsUtil.updateStats(metrics, serverName,
regionName, regionLoadStats));
});
}
+
+ @FunctionalInterface
+ interface Converter<D, I, S> {
+ D convert(I info, S src) throws IOException;
+ }
+
+ @FunctionalInterface
+ interface RpcCall<RESP, REQ> {
+ void call(ClientService.Interface stub, HBaseRpcController controller, REQ
req,
+ RpcCallback<RESP> done);
+ }
+
+ static <REQ, PREQ, PRESP, RESP> CompletableFuture<RESP>
call(HBaseRpcController controller,
+ HRegionLocation loc, ClientService.Interface stub, REQ req,
+ Converter<PREQ, byte[], REQ> reqConvert, RpcCall<PRESP, PREQ> rpcCall,
+ Converter<RESP, HBaseRpcController, PRESP> respConverter) {
+ CompletableFuture<RESP> future = new CompletableFuture<>();
+ try {
+ rpcCall.call(stub, controller,
reqConvert.convert(loc.getRegion().getRegionName(), req),
+ new RpcCallback<PRESP>() {
+
+ @Override
+ public void run(PRESP resp) {
+ if (controller.failed()) {
+ future.completeExceptionally(controller.getFailed());
+ } else {
+ try {
+ future.complete(respConverter.convert(controller, resp));
+ } catch (IOException e) {
+ future.completeExceptionally(e);
+ }
+ }
+ }
+ });
+ } catch (IOException e) {
+ future.completeExceptionally(e);
+ }
+ return future;
+ }
+
+ static ThreadPoolExecutor getThreadPool(Configuration conf, int maxThreads,
int coreThreads,
Review comment:
I moved this method to ConnectionOverAsyncConnection in HBASE-22550. But
anyway, we could add comments here. Let me do some hack here to amend the
comments in the commit for HBASE-22550 since we are on a feature branch.
----------------------------------------------------------------
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