• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.cloud.dialogflow.v2;
18 
19 import com.google.api.core.ApiFuture;
20 import com.google.api.core.ApiFutures;
21 import com.google.api.gax.core.BackgroundResource;
22 import com.google.api.gax.paging.AbstractFixedSizeCollection;
23 import com.google.api.gax.paging.AbstractPage;
24 import com.google.api.gax.paging.AbstractPagedListResponse;
25 import com.google.api.gax.rpc.PageContext;
26 import com.google.api.gax.rpc.UnaryCallable;
27 import com.google.cloud.dialogflow.v2.stub.ContextsStub;
28 import com.google.cloud.dialogflow.v2.stub.ContextsStubSettings;
29 import com.google.cloud.location.GetLocationRequest;
30 import com.google.cloud.location.ListLocationsRequest;
31 import com.google.cloud.location.ListLocationsResponse;
32 import com.google.cloud.location.Location;
33 import com.google.common.util.concurrent.MoreExecutors;
34 import com.google.protobuf.Empty;
35 import com.google.protobuf.FieldMask;
36 import java.io.IOException;
37 import java.util.List;
38 import java.util.concurrent.TimeUnit;
39 import javax.annotation.Generated;
40 
41 // AUTO-GENERATED DOCUMENTATION AND CLASS.
42 /**
43  * Service Description: Service for managing [Contexts][google.cloud.dialogflow.v2.Context].
44  *
45  * <p>This class provides the ability to make remote calls to the backing service through method
46  * calls that map to API methods. Sample code to get started:
47  *
48  * <pre>{@code
49  * // This snippet has been automatically generated and should be regarded as a code template only.
50  * // It will require modifications to work:
51  * // - It may require correct/in-range values for request initialization.
52  * // - It may require specifying regional endpoints when creating the service client as shown in
53  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
54  * try (ContextsClient contextsClient = ContextsClient.create()) {
55  *   ContextName name =
56  *       ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]");
57  *   Context response = contextsClient.getContext(name);
58  * }
59  * }</pre>
60  *
61  * <p>Note: close() needs to be called on the ContextsClient object to clean up resources such as
62  * threads. In the example above, try-with-resources is used, which automatically calls close().
63  *
64  * <p>The surface of this class includes several types of Java methods for each of the API's
65  * methods:
66  *
67  * <ol>
68  *   <li>A "flattened" method. With this type of method, the fields of the request type have been
69  *       converted into function parameters. It may be the case that not all fields are available as
70  *       parameters, and not every API method will have a flattened method entry point.
71  *   <li>A "request object" method. This type of method only takes one parameter, a request object,
72  *       which must be constructed before the call. Not every API method will have a request object
73  *       method.
74  *   <li>A "callable" method. This type of method takes no parameters and returns an immutable API
75  *       callable object, which can be used to initiate calls to the service.
76  * </ol>
77  *
78  * <p>See the individual methods for example code.
79  *
80  * <p>Many parameters require resource names to be formatted in a particular way. To assist with
81  * these names, this class includes a format method for each type of name, and additionally a parse
82  * method to extract the individual identifiers contained within names that are returned.
83  *
84  * <p>This class can be customized by passing in a custom instance of ContextsSettings to create().
85  * For example:
86  *
87  * <p>To customize credentials:
88  *
89  * <pre>{@code
90  * // This snippet has been automatically generated and should be regarded as a code template only.
91  * // It will require modifications to work:
92  * // - It may require correct/in-range values for request initialization.
93  * // - It may require specifying regional endpoints when creating the service client as shown in
94  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
95  * ContextsSettings contextsSettings =
96  *     ContextsSettings.newBuilder()
97  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
98  *         .build();
99  * ContextsClient contextsClient = ContextsClient.create(contextsSettings);
100  * }</pre>
101  *
102  * <p>To customize the endpoint:
103  *
104  * <pre>{@code
105  * // This snippet has been automatically generated and should be regarded as a code template only.
106  * // It will require modifications to work:
107  * // - It may require correct/in-range values for request initialization.
108  * // - It may require specifying regional endpoints when creating the service client as shown in
109  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
110  * ContextsSettings contextsSettings =
111  *     ContextsSettings.newBuilder().setEndpoint(myEndpoint).build();
112  * ContextsClient contextsClient = ContextsClient.create(contextsSettings);
113  * }</pre>
114  *
115  * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
116  * the wire:
117  *
118  * <pre>{@code
119  * // This snippet has been automatically generated and should be regarded as a code template only.
120  * // It will require modifications to work:
121  * // - It may require correct/in-range values for request initialization.
122  * // - It may require specifying regional endpoints when creating the service client as shown in
123  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
124  * ContextsSettings contextsSettings = ContextsSettings.newHttpJsonBuilder().build();
125  * ContextsClient contextsClient = ContextsClient.create(contextsSettings);
126  * }</pre>
127  *
128  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
129  */
130 @Generated("by gapic-generator-java")
131 public class ContextsClient implements BackgroundResource {
132   private final ContextsSettings settings;
133   private final ContextsStub stub;
134 
135   /** Constructs an instance of ContextsClient with default settings. */
create()136   public static final ContextsClient create() throws IOException {
137     return create(ContextsSettings.newBuilder().build());
138   }
139 
140   /**
141    * Constructs an instance of ContextsClient, using the given settings. The channels are created
142    * based on the settings passed in, or defaults for any settings that are not set.
143    */
create(ContextsSettings settings)144   public static final ContextsClient create(ContextsSettings settings) throws IOException {
145     return new ContextsClient(settings);
146   }
147 
148   /**
149    * Constructs an instance of ContextsClient, using the given stub for making calls. This is for
150    * advanced usage - prefer using create(ContextsSettings).
151    */
create(ContextsStub stub)152   public static final ContextsClient create(ContextsStub stub) {
153     return new ContextsClient(stub);
154   }
155 
156   /**
157    * Constructs an instance of ContextsClient, using the given settings. This is protected so that
158    * it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
159    */
ContextsClient(ContextsSettings settings)160   protected ContextsClient(ContextsSettings settings) throws IOException {
161     this.settings = settings;
162     this.stub = ((ContextsStubSettings) settings.getStubSettings()).createStub();
163   }
164 
ContextsClient(ContextsStub stub)165   protected ContextsClient(ContextsStub stub) {
166     this.settings = null;
167     this.stub = stub;
168   }
169 
getSettings()170   public final ContextsSettings getSettings() {
171     return settings;
172   }
173 
getStub()174   public ContextsStub getStub() {
175     return stub;
176   }
177 
178   // AUTO-GENERATED DOCUMENTATION AND METHOD.
179   /**
180    * Returns the list of all contexts in the specified session.
181    *
182    * <p>Sample code:
183    *
184    * <pre>{@code
185    * // This snippet has been automatically generated and should be regarded as a code template only.
186    * // It will require modifications to work:
187    * // - It may require correct/in-range values for request initialization.
188    * // - It may require specifying regional endpoints when creating the service client as shown in
189    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
190    * try (ContextsClient contextsClient = ContextsClient.create()) {
191    *   SessionName parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]");
192    *   for (Context element : contextsClient.listContexts(parent).iterateAll()) {
193    *     // doThingsWith(element);
194    *   }
195    * }
196    * }</pre>
197    *
198    * @param parent Required. The session to list all contexts from. Format: `projects/&lt;Project
199    *     ID&gt;/agent/sessions/&lt;Session ID&gt;` or `projects/&lt;Project
200    *     ID&gt;/agent/environments/&lt;Environment ID&gt;/users/&lt;User ID&gt;/sessions/&lt;Session
201    *     ID&gt;`. If `Environment ID` is not specified, we assume default 'draft' environment. If
202    *     `User ID` is not specified, we assume default '-' user.
203    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
204    */
listContexts(SessionName parent)205   public final ListContextsPagedResponse listContexts(SessionName parent) {
206     ListContextsRequest request =
207         ListContextsRequest.newBuilder()
208             .setParent(parent == null ? null : parent.toString())
209             .build();
210     return listContexts(request);
211   }
212 
213   // AUTO-GENERATED DOCUMENTATION AND METHOD.
214   /**
215    * Returns the list of all contexts in the specified session.
216    *
217    * <p>Sample code:
218    *
219    * <pre>{@code
220    * // This snippet has been automatically generated and should be regarded as a code template only.
221    * // It will require modifications to work:
222    * // - It may require correct/in-range values for request initialization.
223    * // - It may require specifying regional endpoints when creating the service client as shown in
224    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
225    * try (ContextsClient contextsClient = ContextsClient.create()) {
226    *   String parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString();
227    *   for (Context element : contextsClient.listContexts(parent).iterateAll()) {
228    *     // doThingsWith(element);
229    *   }
230    * }
231    * }</pre>
232    *
233    * @param parent Required. The session to list all contexts from. Format: `projects/&lt;Project
234    *     ID&gt;/agent/sessions/&lt;Session ID&gt;` or `projects/&lt;Project
235    *     ID&gt;/agent/environments/&lt;Environment ID&gt;/users/&lt;User ID&gt;/sessions/&lt;Session
236    *     ID&gt;`. If `Environment ID` is not specified, we assume default 'draft' environment. If
237    *     `User ID` is not specified, we assume default '-' user.
238    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
239    */
listContexts(String parent)240   public final ListContextsPagedResponse listContexts(String parent) {
241     ListContextsRequest request = ListContextsRequest.newBuilder().setParent(parent).build();
242     return listContexts(request);
243   }
244 
245   // AUTO-GENERATED DOCUMENTATION AND METHOD.
246   /**
247    * Returns the list of all contexts in the specified session.
248    *
249    * <p>Sample code:
250    *
251    * <pre>{@code
252    * // This snippet has been automatically generated and should be regarded as a code template only.
253    * // It will require modifications to work:
254    * // - It may require correct/in-range values for request initialization.
255    * // - It may require specifying regional endpoints when creating the service client as shown in
256    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
257    * try (ContextsClient contextsClient = ContextsClient.create()) {
258    *   ListContextsRequest request =
259    *       ListContextsRequest.newBuilder()
260    *           .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString())
261    *           .setPageSize(883849137)
262    *           .setPageToken("pageToken873572522")
263    *           .build();
264    *   for (Context element : contextsClient.listContexts(request).iterateAll()) {
265    *     // doThingsWith(element);
266    *   }
267    * }
268    * }</pre>
269    *
270    * @param request The request object containing all of the parameters for the API call.
271    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
272    */
listContexts(ListContextsRequest request)273   public final ListContextsPagedResponse listContexts(ListContextsRequest request) {
274     return listContextsPagedCallable().call(request);
275   }
276 
277   // AUTO-GENERATED DOCUMENTATION AND METHOD.
278   /**
279    * Returns the list of all contexts in the specified session.
280    *
281    * <p>Sample code:
282    *
283    * <pre>{@code
284    * // This snippet has been automatically generated and should be regarded as a code template only.
285    * // It will require modifications to work:
286    * // - It may require correct/in-range values for request initialization.
287    * // - It may require specifying regional endpoints when creating the service client as shown in
288    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
289    * try (ContextsClient contextsClient = ContextsClient.create()) {
290    *   ListContextsRequest request =
291    *       ListContextsRequest.newBuilder()
292    *           .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString())
293    *           .setPageSize(883849137)
294    *           .setPageToken("pageToken873572522")
295    *           .build();
296    *   ApiFuture<Context> future = contextsClient.listContextsPagedCallable().futureCall(request);
297    *   // Do something.
298    *   for (Context element : future.get().iterateAll()) {
299    *     // doThingsWith(element);
300    *   }
301    * }
302    * }</pre>
303    */
304   public final UnaryCallable<ListContextsRequest, ListContextsPagedResponse>
listContextsPagedCallable()305       listContextsPagedCallable() {
306     return stub.listContextsPagedCallable();
307   }
308 
309   // AUTO-GENERATED DOCUMENTATION AND METHOD.
310   /**
311    * Returns the list of all contexts in the specified session.
312    *
313    * <p>Sample code:
314    *
315    * <pre>{@code
316    * // This snippet has been automatically generated and should be regarded as a code template only.
317    * // It will require modifications to work:
318    * // - It may require correct/in-range values for request initialization.
319    * // - It may require specifying regional endpoints when creating the service client as shown in
320    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
321    * try (ContextsClient contextsClient = ContextsClient.create()) {
322    *   ListContextsRequest request =
323    *       ListContextsRequest.newBuilder()
324    *           .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString())
325    *           .setPageSize(883849137)
326    *           .setPageToken("pageToken873572522")
327    *           .build();
328    *   while (true) {
329    *     ListContextsResponse response = contextsClient.listContextsCallable().call(request);
330    *     for (Context element : response.getContextsList()) {
331    *       // doThingsWith(element);
332    *     }
333    *     String nextPageToken = response.getNextPageToken();
334    *     if (!Strings.isNullOrEmpty(nextPageToken)) {
335    *       request = request.toBuilder().setPageToken(nextPageToken).build();
336    *     } else {
337    *       break;
338    *     }
339    *   }
340    * }
341    * }</pre>
342    */
listContextsCallable()343   public final UnaryCallable<ListContextsRequest, ListContextsResponse> listContextsCallable() {
344     return stub.listContextsCallable();
345   }
346 
347   // AUTO-GENERATED DOCUMENTATION AND METHOD.
348   /**
349    * Retrieves the specified context.
350    *
351    * <p>Sample code:
352    *
353    * <pre>{@code
354    * // This snippet has been automatically generated and should be regarded as a code template only.
355    * // It will require modifications to work:
356    * // - It may require correct/in-range values for request initialization.
357    * // - It may require specifying regional endpoints when creating the service client as shown in
358    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
359    * try (ContextsClient contextsClient = ContextsClient.create()) {
360    *   ContextName name =
361    *       ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]");
362    *   Context response = contextsClient.getContext(name);
363    * }
364    * }</pre>
365    *
366    * @param name Required. The name of the context. Format: `projects/&lt;Project
367    *     ID&gt;/agent/sessions/&lt;Session ID&gt;/contexts/&lt;Context ID&gt;` or
368    *     `projects/&lt;Project ID&gt;/agent/environments/&lt;Environment ID&gt;/users/&lt;User
369    *     ID&gt;/sessions/&lt;Session ID&gt;/contexts/&lt;Context ID&gt;`. If `Environment ID` is not
370    *     specified, we assume default 'draft' environment. If `User ID` is not specified, we assume
371    *     default '-' user.
372    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
373    */
getContext(ContextName name)374   public final Context getContext(ContextName name) {
375     GetContextRequest request =
376         GetContextRequest.newBuilder().setName(name == null ? null : name.toString()).build();
377     return getContext(request);
378   }
379 
380   // AUTO-GENERATED DOCUMENTATION AND METHOD.
381   /**
382    * Retrieves the specified context.
383    *
384    * <p>Sample code:
385    *
386    * <pre>{@code
387    * // This snippet has been automatically generated and should be regarded as a code template only.
388    * // It will require modifications to work:
389    * // - It may require correct/in-range values for request initialization.
390    * // - It may require specifying regional endpoints when creating the service client as shown in
391    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
392    * try (ContextsClient contextsClient = ContextsClient.create()) {
393    *   String name =
394    *       ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]").toString();
395    *   Context response = contextsClient.getContext(name);
396    * }
397    * }</pre>
398    *
399    * @param name Required. The name of the context. Format: `projects/&lt;Project
400    *     ID&gt;/agent/sessions/&lt;Session ID&gt;/contexts/&lt;Context ID&gt;` or
401    *     `projects/&lt;Project ID&gt;/agent/environments/&lt;Environment ID&gt;/users/&lt;User
402    *     ID&gt;/sessions/&lt;Session ID&gt;/contexts/&lt;Context ID&gt;`. If `Environment ID` is not
403    *     specified, we assume default 'draft' environment. If `User ID` is not specified, we assume
404    *     default '-' user.
405    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
406    */
getContext(String name)407   public final Context getContext(String name) {
408     GetContextRequest request = GetContextRequest.newBuilder().setName(name).build();
409     return getContext(request);
410   }
411 
412   // AUTO-GENERATED DOCUMENTATION AND METHOD.
413   /**
414    * Retrieves the specified context.
415    *
416    * <p>Sample code:
417    *
418    * <pre>{@code
419    * // This snippet has been automatically generated and should be regarded as a code template only.
420    * // It will require modifications to work:
421    * // - It may require correct/in-range values for request initialization.
422    * // - It may require specifying regional endpoints when creating the service client as shown in
423    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
424    * try (ContextsClient contextsClient = ContextsClient.create()) {
425    *   GetContextRequest request =
426    *       GetContextRequest.newBuilder()
427    *           .setName(
428    *               ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]")
429    *                   .toString())
430    *           .build();
431    *   Context response = contextsClient.getContext(request);
432    * }
433    * }</pre>
434    *
435    * @param request The request object containing all of the parameters for the API call.
436    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
437    */
getContext(GetContextRequest request)438   public final Context getContext(GetContextRequest request) {
439     return getContextCallable().call(request);
440   }
441 
442   // AUTO-GENERATED DOCUMENTATION AND METHOD.
443   /**
444    * Retrieves the specified context.
445    *
446    * <p>Sample code:
447    *
448    * <pre>{@code
449    * // This snippet has been automatically generated and should be regarded as a code template only.
450    * // It will require modifications to work:
451    * // - It may require correct/in-range values for request initialization.
452    * // - It may require specifying regional endpoints when creating the service client as shown in
453    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
454    * try (ContextsClient contextsClient = ContextsClient.create()) {
455    *   GetContextRequest request =
456    *       GetContextRequest.newBuilder()
457    *           .setName(
458    *               ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]")
459    *                   .toString())
460    *           .build();
461    *   ApiFuture<Context> future = contextsClient.getContextCallable().futureCall(request);
462    *   // Do something.
463    *   Context response = future.get();
464    * }
465    * }</pre>
466    */
getContextCallable()467   public final UnaryCallable<GetContextRequest, Context> getContextCallable() {
468     return stub.getContextCallable();
469   }
470 
471   // AUTO-GENERATED DOCUMENTATION AND METHOD.
472   /**
473    * Creates a context.
474    *
475    * <p>If the specified context already exists, overrides the context.
476    *
477    * <p>Sample code:
478    *
479    * <pre>{@code
480    * // This snippet has been automatically generated and should be regarded as a code template only.
481    * // It will require modifications to work:
482    * // - It may require correct/in-range values for request initialization.
483    * // - It may require specifying regional endpoints when creating the service client as shown in
484    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
485    * try (ContextsClient contextsClient = ContextsClient.create()) {
486    *   SessionName parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]");
487    *   Context context = Context.newBuilder().build();
488    *   Context response = contextsClient.createContext(parent, context);
489    * }
490    * }</pre>
491    *
492    * @param parent Required. The session to create a context for. Format: `projects/&lt;Project
493    *     ID&gt;/agent/sessions/&lt;Session ID&gt;` or `projects/&lt;Project
494    *     ID&gt;/agent/environments/&lt;Environment ID&gt;/users/&lt;User ID&gt;/sessions/&lt;Session
495    *     ID&gt;`. If `Environment ID` is not specified, we assume default 'draft' environment. If
496    *     `User ID` is not specified, we assume default '-' user.
497    * @param context Required. The context to create.
498    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
499    */
createContext(SessionName parent, Context context)500   public final Context createContext(SessionName parent, Context context) {
501     CreateContextRequest request =
502         CreateContextRequest.newBuilder()
503             .setParent(parent == null ? null : parent.toString())
504             .setContext(context)
505             .build();
506     return createContext(request);
507   }
508 
509   // AUTO-GENERATED DOCUMENTATION AND METHOD.
510   /**
511    * Creates a context.
512    *
513    * <p>If the specified context already exists, overrides the context.
514    *
515    * <p>Sample code:
516    *
517    * <pre>{@code
518    * // This snippet has been automatically generated and should be regarded as a code template only.
519    * // It will require modifications to work:
520    * // - It may require correct/in-range values for request initialization.
521    * // - It may require specifying regional endpoints when creating the service client as shown in
522    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
523    * try (ContextsClient contextsClient = ContextsClient.create()) {
524    *   String parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString();
525    *   Context context = Context.newBuilder().build();
526    *   Context response = contextsClient.createContext(parent, context);
527    * }
528    * }</pre>
529    *
530    * @param parent Required. The session to create a context for. Format: `projects/&lt;Project
531    *     ID&gt;/agent/sessions/&lt;Session ID&gt;` or `projects/&lt;Project
532    *     ID&gt;/agent/environments/&lt;Environment ID&gt;/users/&lt;User ID&gt;/sessions/&lt;Session
533    *     ID&gt;`. If `Environment ID` is not specified, we assume default 'draft' environment. If
534    *     `User ID` is not specified, we assume default '-' user.
535    * @param context Required. The context to create.
536    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
537    */
createContext(String parent, Context context)538   public final Context createContext(String parent, Context context) {
539     CreateContextRequest request =
540         CreateContextRequest.newBuilder().setParent(parent).setContext(context).build();
541     return createContext(request);
542   }
543 
544   // AUTO-GENERATED DOCUMENTATION AND METHOD.
545   /**
546    * Creates a context.
547    *
548    * <p>If the specified context already exists, overrides the context.
549    *
550    * <p>Sample code:
551    *
552    * <pre>{@code
553    * // This snippet has been automatically generated and should be regarded as a code template only.
554    * // It will require modifications to work:
555    * // - It may require correct/in-range values for request initialization.
556    * // - It may require specifying regional endpoints when creating the service client as shown in
557    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
558    * try (ContextsClient contextsClient = ContextsClient.create()) {
559    *   CreateContextRequest request =
560    *       CreateContextRequest.newBuilder()
561    *           .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString())
562    *           .setContext(Context.newBuilder().build())
563    *           .build();
564    *   Context response = contextsClient.createContext(request);
565    * }
566    * }</pre>
567    *
568    * @param request The request object containing all of the parameters for the API call.
569    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
570    */
createContext(CreateContextRequest request)571   public final Context createContext(CreateContextRequest request) {
572     return createContextCallable().call(request);
573   }
574 
575   // AUTO-GENERATED DOCUMENTATION AND METHOD.
576   /**
577    * Creates a context.
578    *
579    * <p>If the specified context already exists, overrides the context.
580    *
581    * <p>Sample code:
582    *
583    * <pre>{@code
584    * // This snippet has been automatically generated and should be regarded as a code template only.
585    * // It will require modifications to work:
586    * // - It may require correct/in-range values for request initialization.
587    * // - It may require specifying regional endpoints when creating the service client as shown in
588    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
589    * try (ContextsClient contextsClient = ContextsClient.create()) {
590    *   CreateContextRequest request =
591    *       CreateContextRequest.newBuilder()
592    *           .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString())
593    *           .setContext(Context.newBuilder().build())
594    *           .build();
595    *   ApiFuture<Context> future = contextsClient.createContextCallable().futureCall(request);
596    *   // Do something.
597    *   Context response = future.get();
598    * }
599    * }</pre>
600    */
createContextCallable()601   public final UnaryCallable<CreateContextRequest, Context> createContextCallable() {
602     return stub.createContextCallable();
603   }
604 
605   // AUTO-GENERATED DOCUMENTATION AND METHOD.
606   /**
607    * Updates the specified context.
608    *
609    * <p>Sample code:
610    *
611    * <pre>{@code
612    * // This snippet has been automatically generated and should be regarded as a code template only.
613    * // It will require modifications to work:
614    * // - It may require correct/in-range values for request initialization.
615    * // - It may require specifying regional endpoints when creating the service client as shown in
616    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
617    * try (ContextsClient contextsClient = ContextsClient.create()) {
618    *   Context context = Context.newBuilder().build();
619    *   FieldMask updateMask = FieldMask.newBuilder().build();
620    *   Context response = contextsClient.updateContext(context, updateMask);
621    * }
622    * }</pre>
623    *
624    * @param context Required. The context to update.
625    * @param updateMask Optional. The mask to control which fields get updated.
626    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
627    */
updateContext(Context context, FieldMask updateMask)628   public final Context updateContext(Context context, FieldMask updateMask) {
629     UpdateContextRequest request =
630         UpdateContextRequest.newBuilder().setContext(context).setUpdateMask(updateMask).build();
631     return updateContext(request);
632   }
633 
634   // AUTO-GENERATED DOCUMENTATION AND METHOD.
635   /**
636    * Updates the specified context.
637    *
638    * <p>Sample code:
639    *
640    * <pre>{@code
641    * // This snippet has been automatically generated and should be regarded as a code template only.
642    * // It will require modifications to work:
643    * // - It may require correct/in-range values for request initialization.
644    * // - It may require specifying regional endpoints when creating the service client as shown in
645    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
646    * try (ContextsClient contextsClient = ContextsClient.create()) {
647    *   UpdateContextRequest request =
648    *       UpdateContextRequest.newBuilder()
649    *           .setContext(Context.newBuilder().build())
650    *           .setUpdateMask(FieldMask.newBuilder().build())
651    *           .build();
652    *   Context response = contextsClient.updateContext(request);
653    * }
654    * }</pre>
655    *
656    * @param request The request object containing all of the parameters for the API call.
657    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
658    */
updateContext(UpdateContextRequest request)659   public final Context updateContext(UpdateContextRequest request) {
660     return updateContextCallable().call(request);
661   }
662 
663   // AUTO-GENERATED DOCUMENTATION AND METHOD.
664   /**
665    * Updates the specified context.
666    *
667    * <p>Sample code:
668    *
669    * <pre>{@code
670    * // This snippet has been automatically generated and should be regarded as a code template only.
671    * // It will require modifications to work:
672    * // - It may require correct/in-range values for request initialization.
673    * // - It may require specifying regional endpoints when creating the service client as shown in
674    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
675    * try (ContextsClient contextsClient = ContextsClient.create()) {
676    *   UpdateContextRequest request =
677    *       UpdateContextRequest.newBuilder()
678    *           .setContext(Context.newBuilder().build())
679    *           .setUpdateMask(FieldMask.newBuilder().build())
680    *           .build();
681    *   ApiFuture<Context> future = contextsClient.updateContextCallable().futureCall(request);
682    *   // Do something.
683    *   Context response = future.get();
684    * }
685    * }</pre>
686    */
updateContextCallable()687   public final UnaryCallable<UpdateContextRequest, Context> updateContextCallable() {
688     return stub.updateContextCallable();
689   }
690 
691   // AUTO-GENERATED DOCUMENTATION AND METHOD.
692   /**
693    * Deletes the specified context.
694    *
695    * <p>Sample code:
696    *
697    * <pre>{@code
698    * // This snippet has been automatically generated and should be regarded as a code template only.
699    * // It will require modifications to work:
700    * // - It may require correct/in-range values for request initialization.
701    * // - It may require specifying regional endpoints when creating the service client as shown in
702    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
703    * try (ContextsClient contextsClient = ContextsClient.create()) {
704    *   ContextName name =
705    *       ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]");
706    *   contextsClient.deleteContext(name);
707    * }
708    * }</pre>
709    *
710    * @param name Required. The name of the context to delete. Format: `projects/&lt;Project
711    *     ID&gt;/agent/sessions/&lt;Session ID&gt;/contexts/&lt;Context ID&gt;` or
712    *     `projects/&lt;Project ID&gt;/agent/environments/&lt;Environment ID&gt;/users/&lt;User
713    *     ID&gt;/sessions/&lt;Session ID&gt;/contexts/&lt;Context ID&gt;`. If `Environment ID` is not
714    *     specified, we assume default 'draft' environment. If `User ID` is not specified, we assume
715    *     default '-' user.
716    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
717    */
deleteContext(ContextName name)718   public final void deleteContext(ContextName name) {
719     DeleteContextRequest request =
720         DeleteContextRequest.newBuilder().setName(name == null ? null : name.toString()).build();
721     deleteContext(request);
722   }
723 
724   // AUTO-GENERATED DOCUMENTATION AND METHOD.
725   /**
726    * Deletes the specified context.
727    *
728    * <p>Sample code:
729    *
730    * <pre>{@code
731    * // This snippet has been automatically generated and should be regarded as a code template only.
732    * // It will require modifications to work:
733    * // - It may require correct/in-range values for request initialization.
734    * // - It may require specifying regional endpoints when creating the service client as shown in
735    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
736    * try (ContextsClient contextsClient = ContextsClient.create()) {
737    *   String name =
738    *       ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]").toString();
739    *   contextsClient.deleteContext(name);
740    * }
741    * }</pre>
742    *
743    * @param name Required. The name of the context to delete. Format: `projects/&lt;Project
744    *     ID&gt;/agent/sessions/&lt;Session ID&gt;/contexts/&lt;Context ID&gt;` or
745    *     `projects/&lt;Project ID&gt;/agent/environments/&lt;Environment ID&gt;/users/&lt;User
746    *     ID&gt;/sessions/&lt;Session ID&gt;/contexts/&lt;Context ID&gt;`. If `Environment ID` is not
747    *     specified, we assume default 'draft' environment. If `User ID` is not specified, we assume
748    *     default '-' user.
749    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
750    */
deleteContext(String name)751   public final void deleteContext(String name) {
752     DeleteContextRequest request = DeleteContextRequest.newBuilder().setName(name).build();
753     deleteContext(request);
754   }
755 
756   // AUTO-GENERATED DOCUMENTATION AND METHOD.
757   /**
758    * Deletes the specified context.
759    *
760    * <p>Sample code:
761    *
762    * <pre>{@code
763    * // This snippet has been automatically generated and should be regarded as a code template only.
764    * // It will require modifications to work:
765    * // - It may require correct/in-range values for request initialization.
766    * // - It may require specifying regional endpoints when creating the service client as shown in
767    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
768    * try (ContextsClient contextsClient = ContextsClient.create()) {
769    *   DeleteContextRequest request =
770    *       DeleteContextRequest.newBuilder()
771    *           .setName(
772    *               ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]")
773    *                   .toString())
774    *           .build();
775    *   contextsClient.deleteContext(request);
776    * }
777    * }</pre>
778    *
779    * @param request The request object containing all of the parameters for the API call.
780    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
781    */
deleteContext(DeleteContextRequest request)782   public final void deleteContext(DeleteContextRequest request) {
783     deleteContextCallable().call(request);
784   }
785 
786   // AUTO-GENERATED DOCUMENTATION AND METHOD.
787   /**
788    * Deletes the specified context.
789    *
790    * <p>Sample code:
791    *
792    * <pre>{@code
793    * // This snippet has been automatically generated and should be regarded as a code template only.
794    * // It will require modifications to work:
795    * // - It may require correct/in-range values for request initialization.
796    * // - It may require specifying regional endpoints when creating the service client as shown in
797    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
798    * try (ContextsClient contextsClient = ContextsClient.create()) {
799    *   DeleteContextRequest request =
800    *       DeleteContextRequest.newBuilder()
801    *           .setName(
802    *               ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]")
803    *                   .toString())
804    *           .build();
805    *   ApiFuture<Empty> future = contextsClient.deleteContextCallable().futureCall(request);
806    *   // Do something.
807    *   future.get();
808    * }
809    * }</pre>
810    */
deleteContextCallable()811   public final UnaryCallable<DeleteContextRequest, Empty> deleteContextCallable() {
812     return stub.deleteContextCallable();
813   }
814 
815   // AUTO-GENERATED DOCUMENTATION AND METHOD.
816   /**
817    * Deletes all active contexts in the specified session.
818    *
819    * <p>Sample code:
820    *
821    * <pre>{@code
822    * // This snippet has been automatically generated and should be regarded as a code template only.
823    * // It will require modifications to work:
824    * // - It may require correct/in-range values for request initialization.
825    * // - It may require specifying regional endpoints when creating the service client as shown in
826    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
827    * try (ContextsClient contextsClient = ContextsClient.create()) {
828    *   SessionName parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]");
829    *   contextsClient.deleteAllContexts(parent);
830    * }
831    * }</pre>
832    *
833    * @param parent Required. The name of the session to delete all contexts from. Format:
834    *     `projects/&lt;Project ID&gt;/agent/sessions/&lt;Session ID&gt;` or `projects/&lt;Project
835    *     ID&gt;/agent/environments/&lt;Environment ID&gt;/users/&lt;User ID&gt;/sessions/&lt;Session
836    *     ID&gt;`. If `Environment ID` is not specified we assume default 'draft' environment. If
837    *     `User ID` is not specified, we assume default '-' user.
838    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
839    */
deleteAllContexts(SessionName parent)840   public final void deleteAllContexts(SessionName parent) {
841     DeleteAllContextsRequest request =
842         DeleteAllContextsRequest.newBuilder()
843             .setParent(parent == null ? null : parent.toString())
844             .build();
845     deleteAllContexts(request);
846   }
847 
848   // AUTO-GENERATED DOCUMENTATION AND METHOD.
849   /**
850    * Deletes all active contexts in the specified session.
851    *
852    * <p>Sample code:
853    *
854    * <pre>{@code
855    * // This snippet has been automatically generated and should be regarded as a code template only.
856    * // It will require modifications to work:
857    * // - It may require correct/in-range values for request initialization.
858    * // - It may require specifying regional endpoints when creating the service client as shown in
859    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
860    * try (ContextsClient contextsClient = ContextsClient.create()) {
861    *   String parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString();
862    *   contextsClient.deleteAllContexts(parent);
863    * }
864    * }</pre>
865    *
866    * @param parent Required. The name of the session to delete all contexts from. Format:
867    *     `projects/&lt;Project ID&gt;/agent/sessions/&lt;Session ID&gt;` or `projects/&lt;Project
868    *     ID&gt;/agent/environments/&lt;Environment ID&gt;/users/&lt;User ID&gt;/sessions/&lt;Session
869    *     ID&gt;`. If `Environment ID` is not specified we assume default 'draft' environment. If
870    *     `User ID` is not specified, we assume default '-' user.
871    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
872    */
deleteAllContexts(String parent)873   public final void deleteAllContexts(String parent) {
874     DeleteAllContextsRequest request =
875         DeleteAllContextsRequest.newBuilder().setParent(parent).build();
876     deleteAllContexts(request);
877   }
878 
879   // AUTO-GENERATED DOCUMENTATION AND METHOD.
880   /**
881    * Deletes all active contexts in the specified session.
882    *
883    * <p>Sample code:
884    *
885    * <pre>{@code
886    * // This snippet has been automatically generated and should be regarded as a code template only.
887    * // It will require modifications to work:
888    * // - It may require correct/in-range values for request initialization.
889    * // - It may require specifying regional endpoints when creating the service client as shown in
890    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
891    * try (ContextsClient contextsClient = ContextsClient.create()) {
892    *   DeleteAllContextsRequest request =
893    *       DeleteAllContextsRequest.newBuilder()
894    *           .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString())
895    *           .build();
896    *   contextsClient.deleteAllContexts(request);
897    * }
898    * }</pre>
899    *
900    * @param request The request object containing all of the parameters for the API call.
901    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
902    */
deleteAllContexts(DeleteAllContextsRequest request)903   public final void deleteAllContexts(DeleteAllContextsRequest request) {
904     deleteAllContextsCallable().call(request);
905   }
906 
907   // AUTO-GENERATED DOCUMENTATION AND METHOD.
908   /**
909    * Deletes all active contexts in the specified session.
910    *
911    * <p>Sample code:
912    *
913    * <pre>{@code
914    * // This snippet has been automatically generated and should be regarded as a code template only.
915    * // It will require modifications to work:
916    * // - It may require correct/in-range values for request initialization.
917    * // - It may require specifying regional endpoints when creating the service client as shown in
918    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
919    * try (ContextsClient contextsClient = ContextsClient.create()) {
920    *   DeleteAllContextsRequest request =
921    *       DeleteAllContextsRequest.newBuilder()
922    *           .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString())
923    *           .build();
924    *   ApiFuture<Empty> future = contextsClient.deleteAllContextsCallable().futureCall(request);
925    *   // Do something.
926    *   future.get();
927    * }
928    * }</pre>
929    */
deleteAllContextsCallable()930   public final UnaryCallable<DeleteAllContextsRequest, Empty> deleteAllContextsCallable() {
931     return stub.deleteAllContextsCallable();
932   }
933 
934   // AUTO-GENERATED DOCUMENTATION AND METHOD.
935   /**
936    * Lists information about the supported locations for this service.
937    *
938    * <p>Sample code:
939    *
940    * <pre>{@code
941    * // This snippet has been automatically generated and should be regarded as a code template only.
942    * // It will require modifications to work:
943    * // - It may require correct/in-range values for request initialization.
944    * // - It may require specifying regional endpoints when creating the service client as shown in
945    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
946    * try (ContextsClient contextsClient = ContextsClient.create()) {
947    *   ListLocationsRequest request =
948    *       ListLocationsRequest.newBuilder()
949    *           .setName("name3373707")
950    *           .setFilter("filter-1274492040")
951    *           .setPageSize(883849137)
952    *           .setPageToken("pageToken873572522")
953    *           .build();
954    *   for (Location element : contextsClient.listLocations(request).iterateAll()) {
955    *     // doThingsWith(element);
956    *   }
957    * }
958    * }</pre>
959    *
960    * @param request The request object containing all of the parameters for the API call.
961    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
962    */
listLocations(ListLocationsRequest request)963   public final ListLocationsPagedResponse listLocations(ListLocationsRequest request) {
964     return listLocationsPagedCallable().call(request);
965   }
966 
967   // AUTO-GENERATED DOCUMENTATION AND METHOD.
968   /**
969    * Lists information about the supported locations for this service.
970    *
971    * <p>Sample code:
972    *
973    * <pre>{@code
974    * // This snippet has been automatically generated and should be regarded as a code template only.
975    * // It will require modifications to work:
976    * // - It may require correct/in-range values for request initialization.
977    * // - It may require specifying regional endpoints when creating the service client as shown in
978    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
979    * try (ContextsClient contextsClient = ContextsClient.create()) {
980    *   ListLocationsRequest request =
981    *       ListLocationsRequest.newBuilder()
982    *           .setName("name3373707")
983    *           .setFilter("filter-1274492040")
984    *           .setPageSize(883849137)
985    *           .setPageToken("pageToken873572522")
986    *           .build();
987    *   ApiFuture<Location> future = contextsClient.listLocationsPagedCallable().futureCall(request);
988    *   // Do something.
989    *   for (Location element : future.get().iterateAll()) {
990    *     // doThingsWith(element);
991    *   }
992    * }
993    * }</pre>
994    */
995   public final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
listLocationsPagedCallable()996       listLocationsPagedCallable() {
997     return stub.listLocationsPagedCallable();
998   }
999 
1000   // AUTO-GENERATED DOCUMENTATION AND METHOD.
1001   /**
1002    * Lists information about the supported locations for this service.
1003    *
1004    * <p>Sample code:
1005    *
1006    * <pre>{@code
1007    * // This snippet has been automatically generated and should be regarded as a code template only.
1008    * // It will require modifications to work:
1009    * // - It may require correct/in-range values for request initialization.
1010    * // - It may require specifying regional endpoints when creating the service client as shown in
1011    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
1012    * try (ContextsClient contextsClient = ContextsClient.create()) {
1013    *   ListLocationsRequest request =
1014    *       ListLocationsRequest.newBuilder()
1015    *           .setName("name3373707")
1016    *           .setFilter("filter-1274492040")
1017    *           .setPageSize(883849137)
1018    *           .setPageToken("pageToken873572522")
1019    *           .build();
1020    *   while (true) {
1021    *     ListLocationsResponse response = contextsClient.listLocationsCallable().call(request);
1022    *     for (Location element : response.getLocationsList()) {
1023    *       // doThingsWith(element);
1024    *     }
1025    *     String nextPageToken = response.getNextPageToken();
1026    *     if (!Strings.isNullOrEmpty(nextPageToken)) {
1027    *       request = request.toBuilder().setPageToken(nextPageToken).build();
1028    *     } else {
1029    *       break;
1030    *     }
1031    *   }
1032    * }
1033    * }</pre>
1034    */
listLocationsCallable()1035   public final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() {
1036     return stub.listLocationsCallable();
1037   }
1038 
1039   // AUTO-GENERATED DOCUMENTATION AND METHOD.
1040   /**
1041    * Gets information about a location.
1042    *
1043    * <p>Sample code:
1044    *
1045    * <pre>{@code
1046    * // This snippet has been automatically generated and should be regarded as a code template only.
1047    * // It will require modifications to work:
1048    * // - It may require correct/in-range values for request initialization.
1049    * // - It may require specifying regional endpoints when creating the service client as shown in
1050    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
1051    * try (ContextsClient contextsClient = ContextsClient.create()) {
1052    *   GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
1053    *   Location response = contextsClient.getLocation(request);
1054    * }
1055    * }</pre>
1056    *
1057    * @param request The request object containing all of the parameters for the API call.
1058    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
1059    */
getLocation(GetLocationRequest request)1060   public final Location getLocation(GetLocationRequest request) {
1061     return getLocationCallable().call(request);
1062   }
1063 
1064   // AUTO-GENERATED DOCUMENTATION AND METHOD.
1065   /**
1066    * Gets information about a location.
1067    *
1068    * <p>Sample code:
1069    *
1070    * <pre>{@code
1071    * // This snippet has been automatically generated and should be regarded as a code template only.
1072    * // It will require modifications to work:
1073    * // - It may require correct/in-range values for request initialization.
1074    * // - It may require specifying regional endpoints when creating the service client as shown in
1075    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
1076    * try (ContextsClient contextsClient = ContextsClient.create()) {
1077    *   GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
1078    *   ApiFuture<Location> future = contextsClient.getLocationCallable().futureCall(request);
1079    *   // Do something.
1080    *   Location response = future.get();
1081    * }
1082    * }</pre>
1083    */
getLocationCallable()1084   public final UnaryCallable<GetLocationRequest, Location> getLocationCallable() {
1085     return stub.getLocationCallable();
1086   }
1087 
1088   @Override
close()1089   public final void close() {
1090     stub.close();
1091   }
1092 
1093   @Override
shutdown()1094   public void shutdown() {
1095     stub.shutdown();
1096   }
1097 
1098   @Override
isShutdown()1099   public boolean isShutdown() {
1100     return stub.isShutdown();
1101   }
1102 
1103   @Override
isTerminated()1104   public boolean isTerminated() {
1105     return stub.isTerminated();
1106   }
1107 
1108   @Override
shutdownNow()1109   public void shutdownNow() {
1110     stub.shutdownNow();
1111   }
1112 
1113   @Override
awaitTermination(long duration, TimeUnit unit)1114   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
1115     return stub.awaitTermination(duration, unit);
1116   }
1117 
1118   public static class ListContextsPagedResponse
1119       extends AbstractPagedListResponse<
1120           ListContextsRequest,
1121           ListContextsResponse,
1122           Context,
1123           ListContextsPage,
1124           ListContextsFixedSizeCollection> {
1125 
createAsync( PageContext<ListContextsRequest, ListContextsResponse, Context> context, ApiFuture<ListContextsResponse> futureResponse)1126     public static ApiFuture<ListContextsPagedResponse> createAsync(
1127         PageContext<ListContextsRequest, ListContextsResponse, Context> context,
1128         ApiFuture<ListContextsResponse> futureResponse) {
1129       ApiFuture<ListContextsPage> futurePage =
1130           ListContextsPage.createEmptyPage().createPageAsync(context, futureResponse);
1131       return ApiFutures.transform(
1132           futurePage,
1133           input -> new ListContextsPagedResponse(input),
1134           MoreExecutors.directExecutor());
1135     }
1136 
ListContextsPagedResponse(ListContextsPage page)1137     private ListContextsPagedResponse(ListContextsPage page) {
1138       super(page, ListContextsFixedSizeCollection.createEmptyCollection());
1139     }
1140   }
1141 
1142   public static class ListContextsPage
1143       extends AbstractPage<ListContextsRequest, ListContextsResponse, Context, ListContextsPage> {
1144 
ListContextsPage( PageContext<ListContextsRequest, ListContextsResponse, Context> context, ListContextsResponse response)1145     private ListContextsPage(
1146         PageContext<ListContextsRequest, ListContextsResponse, Context> context,
1147         ListContextsResponse response) {
1148       super(context, response);
1149     }
1150 
createEmptyPage()1151     private static ListContextsPage createEmptyPage() {
1152       return new ListContextsPage(null, null);
1153     }
1154 
1155     @Override
createPage( PageContext<ListContextsRequest, ListContextsResponse, Context> context, ListContextsResponse response)1156     protected ListContextsPage createPage(
1157         PageContext<ListContextsRequest, ListContextsResponse, Context> context,
1158         ListContextsResponse response) {
1159       return new ListContextsPage(context, response);
1160     }
1161 
1162     @Override
createPageAsync( PageContext<ListContextsRequest, ListContextsResponse, Context> context, ApiFuture<ListContextsResponse> futureResponse)1163     public ApiFuture<ListContextsPage> createPageAsync(
1164         PageContext<ListContextsRequest, ListContextsResponse, Context> context,
1165         ApiFuture<ListContextsResponse> futureResponse) {
1166       return super.createPageAsync(context, futureResponse);
1167     }
1168   }
1169 
1170   public static class ListContextsFixedSizeCollection
1171       extends AbstractFixedSizeCollection<
1172           ListContextsRequest,
1173           ListContextsResponse,
1174           Context,
1175           ListContextsPage,
1176           ListContextsFixedSizeCollection> {
1177 
ListContextsFixedSizeCollection(List<ListContextsPage> pages, int collectionSize)1178     private ListContextsFixedSizeCollection(List<ListContextsPage> pages, int collectionSize) {
1179       super(pages, collectionSize);
1180     }
1181 
createEmptyCollection()1182     private static ListContextsFixedSizeCollection createEmptyCollection() {
1183       return new ListContextsFixedSizeCollection(null, 0);
1184     }
1185 
1186     @Override
createCollection( List<ListContextsPage> pages, int collectionSize)1187     protected ListContextsFixedSizeCollection createCollection(
1188         List<ListContextsPage> pages, int collectionSize) {
1189       return new ListContextsFixedSizeCollection(pages, collectionSize);
1190     }
1191   }
1192 
1193   public static class ListLocationsPagedResponse
1194       extends AbstractPagedListResponse<
1195           ListLocationsRequest,
1196           ListLocationsResponse,
1197           Location,
1198           ListLocationsPage,
1199           ListLocationsFixedSizeCollection> {
1200 
createAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)1201     public static ApiFuture<ListLocationsPagedResponse> createAsync(
1202         PageContext<ListLocationsRequest, ListLocationsResponse, Location> context,
1203         ApiFuture<ListLocationsResponse> futureResponse) {
1204       ApiFuture<ListLocationsPage> futurePage =
1205           ListLocationsPage.createEmptyPage().createPageAsync(context, futureResponse);
1206       return ApiFutures.transform(
1207           futurePage,
1208           input -> new ListLocationsPagedResponse(input),
1209           MoreExecutors.directExecutor());
1210     }
1211 
ListLocationsPagedResponse(ListLocationsPage page)1212     private ListLocationsPagedResponse(ListLocationsPage page) {
1213       super(page, ListLocationsFixedSizeCollection.createEmptyCollection());
1214     }
1215   }
1216 
1217   public static class ListLocationsPage
1218       extends AbstractPage<
1219           ListLocationsRequest, ListLocationsResponse, Location, ListLocationsPage> {
1220 
ListLocationsPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)1221     private ListLocationsPage(
1222         PageContext<ListLocationsRequest, ListLocationsResponse, Location> context,
1223         ListLocationsResponse response) {
1224       super(context, response);
1225     }
1226 
createEmptyPage()1227     private static ListLocationsPage createEmptyPage() {
1228       return new ListLocationsPage(null, null);
1229     }
1230 
1231     @Override
createPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)1232     protected ListLocationsPage createPage(
1233         PageContext<ListLocationsRequest, ListLocationsResponse, Location> context,
1234         ListLocationsResponse response) {
1235       return new ListLocationsPage(context, response);
1236     }
1237 
1238     @Override
createPageAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)1239     public ApiFuture<ListLocationsPage> createPageAsync(
1240         PageContext<ListLocationsRequest, ListLocationsResponse, Location> context,
1241         ApiFuture<ListLocationsResponse> futureResponse) {
1242       return super.createPageAsync(context, futureResponse);
1243     }
1244   }
1245 
1246   public static class ListLocationsFixedSizeCollection
1247       extends AbstractFixedSizeCollection<
1248           ListLocationsRequest,
1249           ListLocationsResponse,
1250           Location,
1251           ListLocationsPage,
1252           ListLocationsFixedSizeCollection> {
1253 
ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize)1254     private ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize) {
1255       super(pages, collectionSize);
1256     }
1257 
createEmptyCollection()1258     private static ListLocationsFixedSizeCollection createEmptyCollection() {
1259       return new ListLocationsFixedSizeCollection(null, 0);
1260     }
1261 
1262     @Override
createCollection( List<ListLocationsPage> pages, int collectionSize)1263     protected ListLocationsFixedSizeCollection createCollection(
1264         List<ListLocationsPage> pages, int collectionSize) {
1265       return new ListLocationsFixedSizeCollection(pages, collectionSize);
1266     }
1267   }
1268 }
1269