Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Introducing interfaces for new Batching API #692

Merged
merged 10 commits into from
May 29, 2019
Prev Previous commit
Next Next commit
Reverting type names and RequestBuilder#build
removed return statement
  • Loading branch information
rahulKQL committed May 29, 2019
commit e2bbd350a8d0461166d31cb2840a4af97cffb157
8 changes: 4 additions & 4 deletions gax/src/main/java/com/google/api/gax/batching/v2/Batcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
* when triggered by an internal threshold. This is intended to be used for high throughput
* scenarios at the cost of latency.
*
* @param <RequestElementT> The request type for which this class performs batching.
* @param <ResponseElementT> The response type of an entry object.
* @param <ElementT> The request type for which this class performs batching.
* @param <ElementResultT> The response type of an entry object.
*/
public interface Batcher<RequestElementT, ResponseElementT> extends AutoCloseable {
public interface Batcher<ElementT, ElementResultT> extends AutoCloseable {

/**
* Queues the passed in element to be sent at some point in the future.
Expand All @@ -52,7 +52,7 @@ public interface Batcher<RequestElementT, ResponseElementT> extends AutoCloseabl
* <p>Note: Cancelling returned result simply marks the future cancelled, It would not stop the
* batch request.
*/
ApiFuture<ResponseElementT> add(RequestElementT entry);
ApiFuture<ElementResultT> add(ElementT entry);

/**
* Synchronously sends any pending elements as a batch and waits for all outstanding batches to be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@
* <p>Example implementation:
*
* <pre>{@code
* class ListDescriptor implements BatchingDescriptor<String, List<String>, String, List<String>> {
* class ListDescriptor implements BatchingDescriptor<String, String, List<String>, List<String>> {
*
* RequestBuilder<String, List<String>> newRequestBuilder(List<String> prototype) {
* return new RequestBuilder<String, List<String>>() {
*
* RequestBuilder<String, List<String>> add(String element) {
* void add(String element) {
* list.add(element);
* return this;
* }
*
* List<String> build() {
Expand All @@ -58,11 +57,8 @@
* }
*
* void splitResponse(List<String> callableResponse, List<SettableApiFuture<String>> batch) {
* Iterator<String> respIt = callableResponse.iterator();
* Iterator<SettableApiFuture<String>> it = batch.iterator();
*
* while (respIt.hasNext()) {
* it.next().set(respIt.next());
* for (int i = 0; i < batchResponse.size(); i++) {
* batch.get(i).set(batchResponse.get(i);
* }
* }
*
Expand All @@ -78,25 +74,25 @@
* }
* }</pre>
*
* @param <RequestElementT> The request type to perform batching.
* @param <RequestT> The request wrapper type which bundles {@link RequestElementT}.
* @param <ResponseElementT> The response type of an entry object.
* @param <ResponseT> The response wrapper type which bundles {@link ResponseElementT}.
* @param <ElementT> The request type to perform batching.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param <ElementT> the type of each individual element to be batched
@param <ElementResultT> the type of the result for each individual element
@param <RequestT> the type of the request that will contain the accumulated elements
@param <ResponseT> the type of the response will be unpacked into the individual element results

* @param <ElementResultT> The response type of an entry object.
* @param <RequestT> The request wrapper type which bundles {@link ElementT}.
* @param <ResponseT> The response wrapper type which bundles {@link ElementResultT}.
*/
public interface BatchingDescriptor<RequestElementT, RequestT, ResponseElementT, ResponseT> {
public interface BatchingDescriptor<ElementT, ElementResultT, RequestT, ResponseT> {

/**
* Creates a new wrapper for the underlying request builder. It's used to pack the current batch
* request with elements.
*/
RequestBuilder<RequestElementT, RequestT> newRequestBuilder(RequestT prototype);
RequestBuilder<ElementT, RequestT> newRequestBuilder(RequestT prototype);

/** Unpacks the batch response into individual elements results. */
void splitResponse(ResponseT batchResponse, List<SettableApiFuture<ResponseElementT>> batch);
void splitResponse(ResponseT batchResponse, List<SettableApiFuture<ElementResultT>> batch);

/** Unpacks the batch response error into individual element errors. */
void splitException(Throwable throwable, List<SettableApiFuture<ResponseElementT>> batch);
void splitException(Throwable throwable, List<SettableApiFuture<ElementResultT>> batch);

/** Returns the size of the passed element object in bytes. */
long countBytes(RequestElementT element);
long countBytes(ElementT element);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
* <p>The implementation for this interface will be implemented by service specific client or auto
* generated by the gapic-generator.
*
* @param <RequestElementT> The request type to perform batching.
* @param <RequestT> The request wrapper type which bundles {@link RequestElementT}.
* @param <ElementT> The request type to perform batching.
* @param <RequestT> The request wrapper type which bundles {@link ElementT}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the javadoc suggestion from above

*/
public interface RequestBuilder<RequestElementT, RequestT> {
public interface RequestBuilder<ElementT, RequestT> {

/** Adds element object into client specific batch request. */
RequestBuilder<RequestElementT, RequestT> add(RequestElementT element);
void add(ElementT element);

/** Returns the collected elements as a single client specific batch request. */
RequestT build();
Expand Down