@InterfaceAudience.Public public static interface RawAsyncTable.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(HRegionInfo, Object)
or onRegionError(HRegionInfo, Throwable)
calls), i.e, there will be no
onRegionComplete(HRegionInfo, Object)
or
onRegionError(HRegionInfo, 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 RawAsyncTable.CoprocessorCallback
will be called. The
callback
in the pseudo code is our RawAsyncTable.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(HRegionInfo, Object) or
onRegionError(HRegionInfo, Throwable) . |
void |
onError(Throwable error)
Indicate that we got an error which does not belong to any regions.
|
void |
onRegionComplete(HRegionInfo region,
R resp) |
void |
onRegionError(HRegionInfo region,
Throwable error) |
void onRegionComplete(HRegionInfo region, R resp)
region
- the region that the response belongs toresp
- the response of the coprocessor callvoid onRegionError(HRegionInfo region, Throwable error)
region
- the region that the error belongs toerror
- the response error of the coprocessor callvoid onComplete()
onRegionComplete(HRegionInfo, Object)
or
onRegionError(HRegionInfo, Throwable)
.void onError(Throwable error)
Copyright © 2007–2017 The Apache Software Foundation. All rights reserved.