ElementT - The type of each individual element to be batchedElementResultT - The type of the result for each individual elementRequestT - The type of the request that will contain the accumulated elementsResponseT - The type of the response that will be unpacked into individual element results@BetaApi(value="The surface for batching is not stable yet and may change in the future.")
@InternalApi(value="For google-cloud-java client use only.")
public interface BatchingDescriptor<ElementT,ElementResultT,RequestT,ResponseT>
This interface should be implemented by either a service specific client or autogenerated by gapic-generator.
Example implementation:
class ListDescriptor implements BatchingDescriptor<String, String, List<String>, List<String>> {
RequestBuilder<String, List<String>> newRequestBuilder(List<String> prototype) {
return new RequestBuilder<String, List<String>>() {
void add(String element) {
list.add(element);
}
List<String> build() {
return list.clone();
}
};
}
void splitResponse(List<String> callableResponse, List<SettableApiFuture<String>> batch) {
for (int i = 0; i < batchResponse.size(); i++) {
batch.get(i).set(batchResponse.get(i);
}
}
void splitException(Throwable throwable, List<SettableApiFuture<String>> batch) {
for (SettableApiFuture<String> result : batch) {
result.setException(throwable);
}
}
long countBytes(String element) {
return element.length();
}
}
| Modifier and Type | Method and Description |
|---|---|
long |
countBytes(ElementT element)
Returns the size of the passed element object in bytes.
|
BatchingRequestBuilder<ElementT,RequestT> |
newRequestBuilder(RequestT prototype)
Creates a new wrapper for the underlying request builder.
|
void |
splitException(Throwable throwable,
List<BatchEntry<ElementT,ElementResultT>> batch)
Unpacks the batch response error into individual element errors.
|
void |
splitResponse(ResponseT batchResponse,
List<BatchEntry<ElementT,ElementResultT>> batch)
Unpacks the batch response into individual elements results.
|
BatchingRequestBuilder<ElementT,RequestT> newRequestBuilder(RequestT prototype)
void splitResponse(ResponseT batchResponse, List<BatchEntry<ElementT,ElementResultT>> batch)
void splitException(Throwable throwable, List<BatchEntry<ElementT,ElementResultT>> batch)
long countBytes(ElementT element)