private CompletableFuture<Message> rpcCall(MethodDescriptor method, Message request,
    Message responsePrototype, HBaseRpcController controller, HRegionLocation loc,
    ClientService.Interface stub) {
    final Context context = Context.current();
    CompletableFuture<Message> future = new CompletableFuture<>();
    if (region != null && !Bytes.equals(loc.getRegion().getRegionName(), region.getRegionName())) {
      future.completeExceptionally(new DoNotRetryIOException("Region name is changed, expected "
        + region.getRegionNameAsString() + ", actual " + loc.getRegion().getRegionNameAsString()));
      return future;
    }
    CoprocessorServiceRequest csr = CoprocessorRpcUtils.getCoprocessorServiceRequest(method,
      request, row, loc.getRegion().getRegionName());
    stub.execService(controller, csr, resp -> {
      try (Scope ignored = context.makeCurrent()) {
        if (controller.failed()) {
          future.completeExceptionally(controller.getFailed());
        } else {
          lastRegion = resp.getRegion().getValue().toByteArray();
          try {
            future.complete(CoprocessorRpcUtils.getResponse(resp, responsePrototype));
          } catch (IOException e) {
            future.completeExceptionally(e);
          }
        }
      }
    });
    return future;
  }
The implementation of a region based coprocessor rpc channel.
hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionCoprocessorRpcChannelImpl.java