@InterfaceAudience.Public public static interface AsyncTable.CoprocessorCallback<R>
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(); } }); }); }
Modifier and Type | Method and Description |
---|---|
void |
onComplete()
Indicate that all responses of the regions have been notified by calling
onRegionComplete(RegionInfo, Object) or
onRegionError(RegionInfo, Throwable) . |
void |
onError(Throwable error)
Indicate that we got an error which does not belong to any regions.
|
void |
onRegionComplete(RegionInfo region,
R resp) |
void |
onRegionError(RegionInfo region,
Throwable error) |
void onRegionComplete(RegionInfo region, R resp)
region
- the region that the response belongs toresp
- the response of the coprocessor callvoid onRegionError(RegionInfo region, Throwable error)
region
- the region that the error belongs toerror
- the response error of the coprocessor callvoid onComplete()
onRegionComplete(RegionInfo, Object)
or
onRegionError(RegionInfo, Throwable)
.Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.