Package com.google.api.gax.batching
Interface BatchingDescriptor<ElementT,ElementResultT,RequestT,ResponseT>
- Type Parameters:
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
@InternalApi("For google-cloud-java client use only.")
public interface BatchingDescriptor<ElementT,ElementResultT,RequestT,ResponseT>
An adapter that packs and unpacks the elements in and out of batch requests and responses.
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();
}
}
-
Method Summary
Modifier and TypeMethodDescriptionlong
countBytes
(ElementT element) Returns the size of the passed element object in bytes.default BatchResource
Create an emptyBatchResource
.default BatchResource
createResource
(ElementT element) Creates a newBatchResource
with ElementT.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.
-
Method Details
-
newRequestBuilder
Creates a new wrapper for the underlying request builder. It's used to pack the current batch request with elements. -
splitResponse
Unpacks the batch response into individual elements results. -
splitException
Unpacks the batch response error into individual element errors. -
countBytes
Returns the size of the passed element object in bytes. -
createResource
Creates a newBatchResource
with ElementT. -
createEmptyResource
Create an emptyBatchResource
.
-