Interface AsyncTable.CoprocessorCallback<R>

All Known Subinterfaces:
AsyncTable.PartialResultCoprocessorCallback<S,R>
All Known Implementing Classes:
NoopPartialResultCoprocessorCallback
Enclosing interface:
AsyncTable<C extends ScanResultConsumerBase>

@Public public static interface AsyncTable.CoprocessorCallback<R>
The callback when we want to execute a coprocessor call on a range of regions.

As the locating itself also takes some time, the implementation may want to send rpc calls on the fly, which means we do not know how many regions we have when we get the return value of the rpc calls, so we need an onComplete() which is used to tell you that we have passed all the return values to you(through the onRegionComplete(RegionInfo, Object) or onRegionError(RegionInfo, Throwable) calls), i.e, there will be no onRegionComplete(RegionInfo, Object) or onRegionError(RegionInfo, Throwable) calls in the future.

Here is a pseudo code to describe a typical implementation of a range coprocessor service method to help you better understand how the AsyncTable.CoprocessorCallback will be called. The callback in the pseudo code is our AsyncTable.CoprocessorCallback. And notice that the whenComplete is CompletableFuture.whenComplete.

 locateThenCall(byte[] row) {
   locate(row).whenComplete((location, locateError) -> {
     if (locateError != null) {
       callback.onError(locateError);
       return;
     }
     incPendingCall();
     region = location.getRegion();
     if (region.getEndKey() > endKey) {
       locateEnd = true;
     } else {
       locateThenCall(region.getEndKey());
     }
     sendCall().whenComplete((resp, error) -> {
       if (error != null) {
         callback.onRegionError(region, error);
       } else {
         callback.onRegionComplete(region, resp);
       }
       if (locateEnd && decPendingCallAndGet() == 0) {
         callback.onComplete();
       }
     });
   });
 }
 
  • Method Details