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

Commit 93c1869

Browse files
feat: configure retry for Diaglogflow v2.Environments.ListEnvironments and v2beta1.Environments.ListEnvironments (#172)
PiperOrigin-RevId: 308749074 Source-Author: Google APIs <noreply@google.com> Source-Date: Mon Apr 27 20:01:53 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: c284e4f849e4b085a297d336cef8721ab69ba013 Source-Link: googleapis/googleapis@c284e4f
1 parent 17fd213 commit 93c1869

File tree

9 files changed

+509
-31
lines changed

9 files changed

+509
-31
lines changed

google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/EnvironmentsClient.java

Lines changed: 196 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@
1515
*/
1616
package com.google.cloud.dialogflow.v2beta1;
1717

18+
import com.google.api.core.ApiFunction;
19+
import com.google.api.core.ApiFuture;
20+
import com.google.api.core.ApiFutures;
1821
import com.google.api.core.BetaApi;
1922
import com.google.api.gax.core.BackgroundResource;
23+
import com.google.api.gax.paging.AbstractFixedSizeCollection;
24+
import com.google.api.gax.paging.AbstractPage;
25+
import com.google.api.gax.paging.AbstractPagedListResponse;
26+
import com.google.api.gax.rpc.PageContext;
2027
import com.google.api.gax.rpc.UnaryCallable;
2128
import com.google.cloud.dialogflow.v2beta1.stub.EnvironmentsStub;
2229
import com.google.cloud.dialogflow.v2beta1.stub.EnvironmentsStubSettings;
30+
import com.google.common.util.concurrent.MoreExecutors;
2331
import java.io.IOException;
32+
import java.util.List;
2433
import java.util.concurrent.TimeUnit;
2534
import javax.annotation.Generated;
2635

@@ -34,8 +43,10 @@
3443
* <pre>
3544
* <code>
3645
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
37-
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder().build();
38-
* ListEnvironmentsResponse response = environmentsClient.listEnvironments(request);
46+
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
47+
* for (Environment element : environmentsClient.listEnvironments(parent).iterateAll()) {
48+
* // doThingsWith(element);
49+
* }
3950
* }
4051
* </code>
4152
* </pre>
@@ -151,16 +162,73 @@ public EnvironmentsStub getStub() {
151162
*
152163
* <pre><code>
153164
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
154-
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder().build();
155-
* ListEnvironmentsResponse response = environmentsClient.listEnvironments(request);
165+
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
166+
* for (Environment element : environmentsClient.listEnvironments(parent).iterateAll()) {
167+
* // doThingsWith(element);
168+
* }
169+
* }
170+
* </code></pre>
171+
*
172+
* @param parent Required. The agent to list all environments from. Format: `projects/&lt;Project
173+
* ID&gt;/agent`.
174+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
175+
*/
176+
public final ListEnvironmentsPagedResponse listEnvironments(ProjectAgentName parent) {
177+
ListEnvironmentsRequest request =
178+
ListEnvironmentsRequest.newBuilder()
179+
.setParent(parent == null ? null : parent.toString())
180+
.build();
181+
return listEnvironments(request);
182+
}
183+
184+
// AUTO-GENERATED DOCUMENTATION AND METHOD
185+
/**
186+
* Returns the list of all non-draft environments of the specified agent.
187+
*
188+
* <p>Sample code:
189+
*
190+
* <pre><code>
191+
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
192+
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
193+
* for (Environment element : environmentsClient.listEnvironments(parent.toString()).iterateAll()) {
194+
* // doThingsWith(element);
195+
* }
196+
* }
197+
* </code></pre>
198+
*
199+
* @param parent Required. The agent to list all environments from. Format: `projects/&lt;Project
200+
* ID&gt;/agent`.
201+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
202+
*/
203+
public final ListEnvironmentsPagedResponse listEnvironments(String parent) {
204+
ListEnvironmentsRequest request =
205+
ListEnvironmentsRequest.newBuilder().setParent(parent).build();
206+
return listEnvironments(request);
207+
}
208+
209+
// AUTO-GENERATED DOCUMENTATION AND METHOD
210+
/**
211+
* Returns the list of all non-draft environments of the specified agent.
212+
*
213+
* <p>Sample code:
214+
*
215+
* <pre><code>
216+
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
217+
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
218+
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder()
219+
* .setParent(parent.toString())
220+
* .build();
221+
* for (Environment element : environmentsClient.listEnvironments(request).iterateAll()) {
222+
* // doThingsWith(element);
223+
* }
156224
* }
157225
* </code></pre>
158226
*
159227
* @param request The request object containing all of the parameters for the API call.
160228
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
161229
*/
162-
public final ListEnvironmentsResponse listEnvironments(ListEnvironmentsRequest request) {
163-
return listEnvironmentsCallable().call(request);
230+
public final ListEnvironmentsPagedResponse listEnvironments(ListEnvironmentsRequest request) {
231+
return listEnvironmentsPagedCallable().call(request);
164232
}
165233

166234
// AUTO-GENERATED DOCUMENTATION AND METHOD
@@ -171,10 +239,47 @@ public final ListEnvironmentsResponse listEnvironments(ListEnvironmentsRequest r
171239
*
172240
* <pre><code>
173241
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
174-
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder().build();
175-
* ApiFuture&lt;ListEnvironmentsResponse&gt; future = environmentsClient.listEnvironmentsCallable().futureCall(request);
242+
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
243+
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder()
244+
* .setParent(parent.toString())
245+
* .build();
246+
* ApiFuture&lt;ListEnvironmentsPagedResponse&gt; future = environmentsClient.listEnvironmentsPagedCallable().futureCall(request);
176247
* // Do something
177-
* ListEnvironmentsResponse response = future.get();
248+
* for (Environment element : future.get().iterateAll()) {
249+
* // doThingsWith(element);
250+
* }
251+
* }
252+
* </code></pre>
253+
*/
254+
public final UnaryCallable<ListEnvironmentsRequest, ListEnvironmentsPagedResponse>
255+
listEnvironmentsPagedCallable() {
256+
return stub.listEnvironmentsPagedCallable();
257+
}
258+
259+
// AUTO-GENERATED DOCUMENTATION AND METHOD
260+
/**
261+
* Returns the list of all non-draft environments of the specified agent.
262+
*
263+
* <p>Sample code:
264+
*
265+
* <pre><code>
266+
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
267+
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
268+
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder()
269+
* .setParent(parent.toString())
270+
* .build();
271+
* while (true) {
272+
* ListEnvironmentsResponse response = environmentsClient.listEnvironmentsCallable().call(request);
273+
* for (Environment element : response.getEnvironmentsList()) {
274+
* // doThingsWith(element);
275+
* }
276+
* String nextPageToken = response.getNextPageToken();
277+
* if (!Strings.isNullOrEmpty(nextPageToken)) {
278+
* request = request.toBuilder().setPageToken(nextPageToken).build();
279+
* } else {
280+
* break;
281+
* }
282+
* }
178283
* }
179284
* </code></pre>
180285
*/
@@ -212,4 +317,86 @@ public void shutdownNow() {
212317
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
213318
return stub.awaitTermination(duration, unit);
214319
}
320+
321+
public static class ListEnvironmentsPagedResponse
322+
extends AbstractPagedListResponse<
323+
ListEnvironmentsRequest,
324+
ListEnvironmentsResponse,
325+
Environment,
326+
ListEnvironmentsPage,
327+
ListEnvironmentsFixedSizeCollection> {
328+
329+
public static ApiFuture<ListEnvironmentsPagedResponse> createAsync(
330+
PageContext<ListEnvironmentsRequest, ListEnvironmentsResponse, Environment> context,
331+
ApiFuture<ListEnvironmentsResponse> futureResponse) {
332+
ApiFuture<ListEnvironmentsPage> futurePage =
333+
ListEnvironmentsPage.createEmptyPage().createPageAsync(context, futureResponse);
334+
return ApiFutures.transform(
335+
futurePage,
336+
new ApiFunction<ListEnvironmentsPage, ListEnvironmentsPagedResponse>() {
337+
@Override
338+
public ListEnvironmentsPagedResponse apply(ListEnvironmentsPage input) {
339+
return new ListEnvironmentsPagedResponse(input);
340+
}
341+
},
342+
MoreExecutors.directExecutor());
343+
}
344+
345+
private ListEnvironmentsPagedResponse(ListEnvironmentsPage page) {
346+
super(page, ListEnvironmentsFixedSizeCollection.createEmptyCollection());
347+
}
348+
}
349+
350+
public static class ListEnvironmentsPage
351+
extends AbstractPage<
352+
ListEnvironmentsRequest, ListEnvironmentsResponse, Environment, ListEnvironmentsPage> {
353+
354+
private ListEnvironmentsPage(
355+
PageContext<ListEnvironmentsRequest, ListEnvironmentsResponse, Environment> context,
356+
ListEnvironmentsResponse response) {
357+
super(context, response);
358+
}
359+
360+
private static ListEnvironmentsPage createEmptyPage() {
361+
return new ListEnvironmentsPage(null, null);
362+
}
363+
364+
@Override
365+
protected ListEnvironmentsPage createPage(
366+
PageContext<ListEnvironmentsRequest, ListEnvironmentsResponse, Environment> context,
367+
ListEnvironmentsResponse response) {
368+
return new ListEnvironmentsPage(context, response);
369+
}
370+
371+
@Override
372+
public ApiFuture<ListEnvironmentsPage> createPageAsync(
373+
PageContext<ListEnvironmentsRequest, ListEnvironmentsResponse, Environment> context,
374+
ApiFuture<ListEnvironmentsResponse> futureResponse) {
375+
return super.createPageAsync(context, futureResponse);
376+
}
377+
}
378+
379+
public static class ListEnvironmentsFixedSizeCollection
380+
extends AbstractFixedSizeCollection<
381+
ListEnvironmentsRequest,
382+
ListEnvironmentsResponse,
383+
Environment,
384+
ListEnvironmentsPage,
385+
ListEnvironmentsFixedSizeCollection> {
386+
387+
private ListEnvironmentsFixedSizeCollection(
388+
List<ListEnvironmentsPage> pages, int collectionSize) {
389+
super(pages, collectionSize);
390+
}
391+
392+
private static ListEnvironmentsFixedSizeCollection createEmptyCollection() {
393+
return new ListEnvironmentsFixedSizeCollection(null, 0);
394+
}
395+
396+
@Override
397+
protected ListEnvironmentsFixedSizeCollection createCollection(
398+
List<ListEnvironmentsPage> pages, int collectionSize) {
399+
return new ListEnvironmentsFixedSizeCollection(pages, collectionSize);
400+
}
401+
}
215402
}

google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/EnvironmentsSettings.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.google.cloud.dialogflow.v2beta1;
1717

18+
import static com.google.cloud.dialogflow.v2beta1.EnvironmentsClient.ListEnvironmentsPagedResponse;
19+
1820
import com.google.api.core.ApiFunction;
1921
import com.google.api.core.BetaApi;
2022
import com.google.api.gax.core.GoogleCredentialsProvider;
@@ -23,6 +25,7 @@
2325
import com.google.api.gax.rpc.ApiClientHeaderProvider;
2426
import com.google.api.gax.rpc.ClientContext;
2527
import com.google.api.gax.rpc.ClientSettings;
28+
import com.google.api.gax.rpc.PagedCallSettings;
2629
import com.google.api.gax.rpc.TransportChannelProvider;
2730
import com.google.api.gax.rpc.UnaryCallSettings;
2831
import com.google.cloud.dialogflow.v2beta1.stub.EnvironmentsStubSettings;
@@ -65,7 +68,8 @@
6568
@BetaApi
6669
public class EnvironmentsSettings extends ClientSettings<EnvironmentsSettings> {
6770
/** Returns the object with the settings used for calls to listEnvironments. */
68-
public UnaryCallSettings<ListEnvironmentsRequest, ListEnvironmentsResponse>
71+
public PagedCallSettings<
72+
ListEnvironmentsRequest, ListEnvironmentsResponse, ListEnvironmentsPagedResponse>
6973
listEnvironmentsSettings() {
7074
return ((EnvironmentsStubSettings) getStubSettings()).listEnvironmentsSettings();
7175
}
@@ -168,7 +172,8 @@ public Builder applyToAllUnaryMethods(
168172
}
169173

170174
/** Returns the builder for the settings used for calls to listEnvironments. */
171-
public UnaryCallSettings.Builder<ListEnvironmentsRequest, ListEnvironmentsResponse>
175+
public PagedCallSettings.Builder<
176+
ListEnvironmentsRequest, ListEnvironmentsResponse, ListEnvironmentsPagedResponse>
172177
listEnvironmentsSettings() {
173178
return getStubSettingsBuilder().listEnvironmentsSettings();
174179
}

google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@
149149
* <pre>
150150
* <code>
151151
* try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
152-
* ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder().build();
153-
* ListEnvironmentsResponse response = environmentsClient.listEnvironments(request);
152+
* ProjectAgentName parent = ProjectAgentName.of("[PROJECT]");
153+
* ListEnvironmentsPagedResponse response = environmentsClient.listEnvironments(parent);
154154
* }
155155
* </code>
156156
* </pre>

google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/EnvironmentsStub.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.google.cloud.dialogflow.v2beta1.stub;
1717

18+
import static com.google.cloud.dialogflow.v2beta1.EnvironmentsClient.ListEnvironmentsPagedResponse;
19+
1820
import com.google.api.core.BetaApi;
1921
import com.google.api.gax.core.BackgroundResource;
2022
import com.google.api.gax.rpc.UnaryCallable;
@@ -32,6 +34,11 @@
3234
@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
3335
public abstract class EnvironmentsStub implements BackgroundResource {
3436

37+
public UnaryCallable<ListEnvironmentsRequest, ListEnvironmentsPagedResponse>
38+
listEnvironmentsPagedCallable() {
39+
throw new UnsupportedOperationException("Not implemented: listEnvironmentsPagedCallable()");
40+
}
41+
3542
public UnaryCallable<ListEnvironmentsRequest, ListEnvironmentsResponse>
3643
listEnvironmentsCallable() {
3744
throw new UnsupportedOperationException("Not implemented: listEnvironmentsCallable()");

0 commit comments

Comments
 (0)