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

feat: configure retry for Diaglogflow v2.Environments.ListEnvironments and v2beta1.Environments.ListEnvironments #172

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@
*/
package com.google.cloud.dialogflow.v2beta1;

import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.paging.AbstractFixedSizeCollection;
import com.google.api.gax.paging.AbstractPage;
import com.google.api.gax.paging.AbstractPagedListResponse;
import com.google.api.gax.rpc.PageContext;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.dialogflow.v2beta1.stub.EnvironmentsStub;
import com.google.cloud.dialogflow.v2beta1.stub.EnvironmentsStubSettings;
import com.google.common.util.concurrent.MoreExecutors;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;

Expand All @@ -34,8 +43,10 @@
* <pre>
* <code>
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder().build();
* ListEnvironmentsResponse response = environmentsClient.listEnvironments(request);
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
* for (Environment element : environmentsClient.listEnvironments(parent).iterateAll()) {
* // doThingsWith(element);
* }
* }
* </code>
* </pre>
Expand Down Expand Up @@ -151,16 +162,73 @@ public EnvironmentsStub getStub() {
*
* <pre><code>
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder().build();
* ListEnvironmentsResponse response = environmentsClient.listEnvironments(request);
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
* for (Environment element : environmentsClient.listEnvironments(parent).iterateAll()) {
* // doThingsWith(element);
* }
* }
* </code></pre>
*
* @param parent Required. The agent to list all environments from. Format: `projects/&lt;Project
* ID&gt;/agent`.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListEnvironmentsPagedResponse listEnvironments(ProjectAgentName parent) {
ListEnvironmentsRequest request =
ListEnvironmentsRequest.newBuilder()
.setParent(parent == null ? null : parent.toString())
.build();
return listEnvironments(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns the list of all non-draft environments of the specified agent.
*
* <p>Sample code:
*
* <pre><code>
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
* for (Environment element : environmentsClient.listEnvironments(parent.toString()).iterateAll()) {
* // doThingsWith(element);
* }
* }
* </code></pre>
*
* @param parent Required. The agent to list all environments from. Format: `projects/&lt;Project
* ID&gt;/agent`.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListEnvironmentsPagedResponse listEnvironments(String parent) {
ListEnvironmentsRequest request =
ListEnvironmentsRequest.newBuilder().setParent(parent).build();
return listEnvironments(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns the list of all non-draft environments of the specified agent.
*
* <p>Sample code:
*
* <pre><code>
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder()
* .setParent(parent.toString())
* .build();
* for (Environment element : environmentsClient.listEnvironments(request).iterateAll()) {
* // doThingsWith(element);
* }
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListEnvironmentsResponse listEnvironments(ListEnvironmentsRequest request) {
return listEnvironmentsCallable().call(request);
public final ListEnvironmentsPagedResponse listEnvironments(ListEnvironmentsRequest request) {
return listEnvironmentsPagedCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
Expand All @@ -171,10 +239,47 @@ public final ListEnvironmentsResponse listEnvironments(ListEnvironmentsRequest r
*
* <pre><code>
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder().build();
* ApiFuture&lt;ListEnvironmentsResponse&gt; future = environmentsClient.listEnvironmentsCallable().futureCall(request);
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder()
* .setParent(parent.toString())
* .build();
* ApiFuture&lt;ListEnvironmentsPagedResponse&gt; future = environmentsClient.listEnvironmentsPagedCallable().futureCall(request);
* // Do something
* ListEnvironmentsResponse response = future.get();
* for (Environment element : future.get().iterateAll()) {
* // doThingsWith(element);
* }
* }
* </code></pre>
*/
public final UnaryCallable<ListEnvironmentsRequest, ListEnvironmentsPagedResponse>
listEnvironmentsPagedCallable() {
return stub.listEnvironmentsPagedCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns the list of all non-draft environments of the specified agent.
*
* <p>Sample code:
*
* <pre><code>
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder()
* .setParent(parent.toString())
* .build();
* while (true) {
* ListEnvironmentsResponse response = environmentsClient.listEnvironmentsCallable().call(request);
* for (Environment element : response.getEnvironmentsList()) {
* // doThingsWith(element);
* }
* String nextPageToken = response.getNextPageToken();
* if (!Strings.isNullOrEmpty(nextPageToken)) {
* request = request.toBuilder().setPageToken(nextPageToken).build();
* } else {
* break;
* }
* }
* }
* </code></pre>
*/
Expand Down Expand Up @@ -212,4 +317,86 @@ public void shutdownNow() {
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
return stub.awaitTermination(duration, unit);
}

public static class ListEnvironmentsPagedResponse
extends AbstractPagedListResponse<
ListEnvironmentsRequest,
ListEnvironmentsResponse,
Environment,
ListEnvironmentsPage,
ListEnvironmentsFixedSizeCollection> {

public static ApiFuture<ListEnvironmentsPagedResponse> createAsync(
PageContext<ListEnvironmentsRequest, ListEnvironmentsResponse, Environment> context,
ApiFuture<ListEnvironmentsResponse> futureResponse) {
ApiFuture<ListEnvironmentsPage> futurePage =
ListEnvironmentsPage.createEmptyPage().createPageAsync(context, futureResponse);
return ApiFutures.transform(
futurePage,
new ApiFunction<ListEnvironmentsPage, ListEnvironmentsPagedResponse>() {
@Override
public ListEnvironmentsPagedResponse apply(ListEnvironmentsPage input) {
return new ListEnvironmentsPagedResponse(input);
}
},
MoreExecutors.directExecutor());
}

private ListEnvironmentsPagedResponse(ListEnvironmentsPage page) {
super(page, ListEnvironmentsFixedSizeCollection.createEmptyCollection());
}
}

public static class ListEnvironmentsPage
extends AbstractPage<
ListEnvironmentsRequest, ListEnvironmentsResponse, Environment, ListEnvironmentsPage> {

private ListEnvironmentsPage(
PageContext<ListEnvironmentsRequest, ListEnvironmentsResponse, Environment> context,
ListEnvironmentsResponse response) {
super(context, response);
}

private static ListEnvironmentsPage createEmptyPage() {
return new ListEnvironmentsPage(null, null);
}

@Override
protected ListEnvironmentsPage createPage(
PageContext<ListEnvironmentsRequest, ListEnvironmentsResponse, Environment> context,
ListEnvironmentsResponse response) {
return new ListEnvironmentsPage(context, response);
}

@Override
public ApiFuture<ListEnvironmentsPage> createPageAsync(
PageContext<ListEnvironmentsRequest, ListEnvironmentsResponse, Environment> context,
ApiFuture<ListEnvironmentsResponse> futureResponse) {
return super.createPageAsync(context, futureResponse);
}
}

public static class ListEnvironmentsFixedSizeCollection
extends AbstractFixedSizeCollection<
ListEnvironmentsRequest,
ListEnvironmentsResponse,
Environment,
ListEnvironmentsPage,
ListEnvironmentsFixedSizeCollection> {

private ListEnvironmentsFixedSizeCollection(
List<ListEnvironmentsPage> pages, int collectionSize) {
super(pages, collectionSize);
}

private static ListEnvironmentsFixedSizeCollection createEmptyCollection() {
return new ListEnvironmentsFixedSizeCollection(null, 0);
}

@Override
protected ListEnvironmentsFixedSizeCollection createCollection(
List<ListEnvironmentsPage> pages, int collectionSize) {
return new ListEnvironmentsFixedSizeCollection(pages, collectionSize);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.google.cloud.dialogflow.v2beta1;

import static com.google.cloud.dialogflow.v2beta1.EnvironmentsClient.ListEnvironmentsPagedResponse;

import com.google.api.core.ApiFunction;
import com.google.api.core.BetaApi;
import com.google.api.gax.core.GoogleCredentialsProvider;
Expand All @@ -23,6 +25,7 @@
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientSettings;
import com.google.api.gax.rpc.PagedCallSettings;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.cloud.dialogflow.v2beta1.stub.EnvironmentsStubSettings;
Expand Down Expand Up @@ -65,7 +68,8 @@
@BetaApi
public class EnvironmentsSettings extends ClientSettings<EnvironmentsSettings> {
/** Returns the object with the settings used for calls to listEnvironments. */
public UnaryCallSettings<ListEnvironmentsRequest, ListEnvironmentsResponse>
public PagedCallSettings<
ListEnvironmentsRequest, ListEnvironmentsResponse, ListEnvironmentsPagedResponse>
listEnvironmentsSettings() {
return ((EnvironmentsStubSettings) getStubSettings()).listEnvironmentsSettings();
}
Expand Down Expand Up @@ -168,7 +172,8 @@ public Builder applyToAllUnaryMethods(
}

/** Returns the builder for the settings used for calls to listEnvironments. */
public UnaryCallSettings.Builder<ListEnvironmentsRequest, ListEnvironmentsResponse>
public PagedCallSettings.Builder<
ListEnvironmentsRequest, ListEnvironmentsResponse, ListEnvironmentsPagedResponse>
listEnvironmentsSettings() {
return getStubSettingsBuilder().listEnvironmentsSettings();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@
* <pre>
* <code>
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder().build();
* ListEnvironmentsResponse response = environmentsClient.listEnvironments(request);
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
* ListEnvironmentsPagedResponse response = environmentsClient.listEnvironments(parent);
* }
* </code>
* </pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.google.cloud.dialogflow.v2beta1.stub;

import static com.google.cloud.dialogflow.v2beta1.EnvironmentsClient.ListEnvironmentsPagedResponse;

import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.rpc.UnaryCallable;
Expand All @@ -32,6 +34,11 @@
@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public abstract class EnvironmentsStub implements BackgroundResource {

public UnaryCallable<ListEnvironmentsRequest, ListEnvironmentsPagedResponse>
listEnvironmentsPagedCallable() {
throw new UnsupportedOperationException("Not implemented: listEnvironmentsPagedCallable()");
}

public UnaryCallable<ListEnvironmentsRequest, ListEnvironmentsResponse>
listEnvironmentsCallable() {
throw new UnsupportedOperationException("Not implemented: listEnvironmentsCallable()");
Expand Down
Loading