Interface BatchingDescriptor<ElementT,​ElementResultT,​RequestT,​ResponseT>

  • Type Parameters:
    ElementT - The type of each individual element to be batched
    ElementResultT - The type of the result for each individual element
    RequestT - The type of the request that will contain the accumulated elements
    ResponseT - 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();
       }
     }