saintstack 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_r291811395
##########
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:
Does this need more comments saying that its for CPs only? Or maybe there
are comments to this effect elsewhere, just not down here at this level?
----------------------------------------------------------------
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