• 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.stub;
18 
19 import static com.google.cloud.dialogflow.v2.AgentsClient.ListLocationsPagedResponse;
20 import static com.google.cloud.dialogflow.v2.AgentsClient.SearchAgentsPagedResponse;
21 
22 import com.google.api.core.ApiFunction;
23 import com.google.api.core.ApiFuture;
24 import com.google.api.core.BetaApi;
25 import com.google.api.gax.core.GaxProperties;
26 import com.google.api.gax.core.GoogleCredentialsProvider;
27 import com.google.api.gax.core.InstantiatingExecutorProvider;
28 import com.google.api.gax.grpc.GaxGrpcProperties;
29 import com.google.api.gax.grpc.GrpcTransportChannel;
30 import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
31 import com.google.api.gax.grpc.ProtoOperationTransformers;
32 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
33 import com.google.api.gax.httpjson.HttpJsonTransportChannel;
34 import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
35 import com.google.api.gax.longrunning.OperationSnapshot;
36 import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
37 import com.google.api.gax.retrying.RetrySettings;
38 import com.google.api.gax.rpc.ApiCallContext;
39 import com.google.api.gax.rpc.ApiClientHeaderProvider;
40 import com.google.api.gax.rpc.ClientContext;
41 import com.google.api.gax.rpc.OperationCallSettings;
42 import com.google.api.gax.rpc.PageContext;
43 import com.google.api.gax.rpc.PagedCallSettings;
44 import com.google.api.gax.rpc.PagedListDescriptor;
45 import com.google.api.gax.rpc.PagedListResponseFactory;
46 import com.google.api.gax.rpc.StatusCode;
47 import com.google.api.gax.rpc.StubSettings;
48 import com.google.api.gax.rpc.TransportChannelProvider;
49 import com.google.api.gax.rpc.UnaryCallSettings;
50 import com.google.api.gax.rpc.UnaryCallable;
51 import com.google.cloud.dialogflow.v2.Agent;
52 import com.google.cloud.dialogflow.v2.DeleteAgentRequest;
53 import com.google.cloud.dialogflow.v2.ExportAgentRequest;
54 import com.google.cloud.dialogflow.v2.ExportAgentResponse;
55 import com.google.cloud.dialogflow.v2.GetAgentRequest;
56 import com.google.cloud.dialogflow.v2.GetValidationResultRequest;
57 import com.google.cloud.dialogflow.v2.ImportAgentRequest;
58 import com.google.cloud.dialogflow.v2.RestoreAgentRequest;
59 import com.google.cloud.dialogflow.v2.SearchAgentsRequest;
60 import com.google.cloud.dialogflow.v2.SearchAgentsResponse;
61 import com.google.cloud.dialogflow.v2.SetAgentRequest;
62 import com.google.cloud.dialogflow.v2.TrainAgentRequest;
63 import com.google.cloud.dialogflow.v2.ValidationResult;
64 import com.google.cloud.location.GetLocationRequest;
65 import com.google.cloud.location.ListLocationsRequest;
66 import com.google.cloud.location.ListLocationsResponse;
67 import com.google.cloud.location.Location;
68 import com.google.common.collect.ImmutableList;
69 import com.google.common.collect.ImmutableMap;
70 import com.google.common.collect.ImmutableSet;
71 import com.google.common.collect.Lists;
72 import com.google.longrunning.Operation;
73 import com.google.protobuf.Empty;
74 import com.google.protobuf.Struct;
75 import java.io.IOException;
76 import java.util.List;
77 import javax.annotation.Generated;
78 import org.threeten.bp.Duration;
79 
80 // AUTO-GENERATED DOCUMENTATION AND CLASS.
81 /**
82  * Settings class to configure an instance of {@link AgentsStub}.
83  *
84  * <p>The default instance has everything set to sensible defaults:
85  *
86  * <ul>
87  *   <li>The default service address (dialogflow.googleapis.com) and default port (443) are used.
88  *   <li>Credentials are acquired automatically through Application Default Credentials.
89  *   <li>Retries are configured for idempotent methods but not for non-idempotent methods.
90  * </ul>
91  *
92  * <p>The builder of this class is recursive, so contained classes are themselves builders. When
93  * build() is called, the tree of builders is called to create the complete settings object.
94  *
95  * <p>For example, to set the total timeout of getAgent to 30 seconds:
96  *
97  * <pre>{@code
98  * // This snippet has been automatically generated and should be regarded as a code template only.
99  * // It will require modifications to work:
100  * // - It may require correct/in-range values for request initialization.
101  * // - It may require specifying regional endpoints when creating the service client as shown in
102  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
103  * AgentsStubSettings.Builder agentsSettingsBuilder = AgentsStubSettings.newBuilder();
104  * agentsSettingsBuilder
105  *     .getAgentSettings()
106  *     .setRetrySettings(
107  *         agentsSettingsBuilder
108  *             .getAgentSettings()
109  *             .getRetrySettings()
110  *             .toBuilder()
111  *             .setTotalTimeout(Duration.ofSeconds(30))
112  *             .build());
113  * AgentsStubSettings agentsSettings = agentsSettingsBuilder.build();
114  * }</pre>
115  */
116 @Generated("by gapic-generator-java")
117 public class AgentsStubSettings extends StubSettings<AgentsStubSettings> {
118   /** The default scopes of the service. */
119   private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
120       ImmutableList.<String>builder()
121           .add("https://www.googleapis.com/auth/cloud-platform")
122           .add("https://www.googleapis.com/auth/dialogflow")
123           .build();
124 
125   private final UnaryCallSettings<GetAgentRequest, Agent> getAgentSettings;
126   private final UnaryCallSettings<SetAgentRequest, Agent> setAgentSettings;
127   private final UnaryCallSettings<DeleteAgentRequest, Empty> deleteAgentSettings;
128   private final PagedCallSettings<
129           SearchAgentsRequest, SearchAgentsResponse, SearchAgentsPagedResponse>
130       searchAgentsSettings;
131   private final UnaryCallSettings<TrainAgentRequest, Operation> trainAgentSettings;
132   private final OperationCallSettings<TrainAgentRequest, Empty, Struct> trainAgentOperationSettings;
133   private final UnaryCallSettings<ExportAgentRequest, Operation> exportAgentSettings;
134   private final OperationCallSettings<ExportAgentRequest, ExportAgentResponse, Struct>
135       exportAgentOperationSettings;
136   private final UnaryCallSettings<ImportAgentRequest, Operation> importAgentSettings;
137   private final OperationCallSettings<ImportAgentRequest, Empty, Struct>
138       importAgentOperationSettings;
139   private final UnaryCallSettings<RestoreAgentRequest, Operation> restoreAgentSettings;
140   private final OperationCallSettings<RestoreAgentRequest, Empty, Struct>
141       restoreAgentOperationSettings;
142   private final UnaryCallSettings<GetValidationResultRequest, ValidationResult>
143       getValidationResultSettings;
144   private final PagedCallSettings<
145           ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
146       listLocationsSettings;
147   private final UnaryCallSettings<GetLocationRequest, Location> getLocationSettings;
148 
149   private static final PagedListDescriptor<SearchAgentsRequest, SearchAgentsResponse, Agent>
150       SEARCH_AGENTS_PAGE_STR_DESC =
151           new PagedListDescriptor<SearchAgentsRequest, SearchAgentsResponse, Agent>() {
152             @Override
153             public String emptyToken() {
154               return "";
155             }
156 
157             @Override
158             public SearchAgentsRequest injectToken(SearchAgentsRequest payload, String token) {
159               return SearchAgentsRequest.newBuilder(payload).setPageToken(token).build();
160             }
161 
162             @Override
163             public SearchAgentsRequest injectPageSize(SearchAgentsRequest payload, int pageSize) {
164               return SearchAgentsRequest.newBuilder(payload).setPageSize(pageSize).build();
165             }
166 
167             @Override
168             public Integer extractPageSize(SearchAgentsRequest payload) {
169               return payload.getPageSize();
170             }
171 
172             @Override
173             public String extractNextToken(SearchAgentsResponse payload) {
174               return payload.getNextPageToken();
175             }
176 
177             @Override
178             public Iterable<Agent> extractResources(SearchAgentsResponse payload) {
179               return payload.getAgentsList() == null
180                   ? ImmutableList.<Agent>of()
181                   : payload.getAgentsList();
182             }
183           };
184 
185   private static final PagedListDescriptor<ListLocationsRequest, ListLocationsResponse, Location>
186       LIST_LOCATIONS_PAGE_STR_DESC =
187           new PagedListDescriptor<ListLocationsRequest, ListLocationsResponse, Location>() {
188             @Override
189             public String emptyToken() {
190               return "";
191             }
192 
193             @Override
194             public ListLocationsRequest injectToken(ListLocationsRequest payload, String token) {
195               return ListLocationsRequest.newBuilder(payload).setPageToken(token).build();
196             }
197 
198             @Override
199             public ListLocationsRequest injectPageSize(ListLocationsRequest payload, int pageSize) {
200               return ListLocationsRequest.newBuilder(payload).setPageSize(pageSize).build();
201             }
202 
203             @Override
204             public Integer extractPageSize(ListLocationsRequest payload) {
205               return payload.getPageSize();
206             }
207 
208             @Override
209             public String extractNextToken(ListLocationsResponse payload) {
210               return payload.getNextPageToken();
211             }
212 
213             @Override
214             public Iterable<Location> extractResources(ListLocationsResponse payload) {
215               return payload.getLocationsList() == null
216                   ? ImmutableList.<Location>of()
217                   : payload.getLocationsList();
218             }
219           };
220 
221   private static final PagedListResponseFactory<
222           SearchAgentsRequest, SearchAgentsResponse, SearchAgentsPagedResponse>
223       SEARCH_AGENTS_PAGE_STR_FACT =
224           new PagedListResponseFactory<
225               SearchAgentsRequest, SearchAgentsResponse, SearchAgentsPagedResponse>() {
226             @Override
227             public ApiFuture<SearchAgentsPagedResponse> getFuturePagedResponse(
228                 UnaryCallable<SearchAgentsRequest, SearchAgentsResponse> callable,
229                 SearchAgentsRequest request,
230                 ApiCallContext context,
231                 ApiFuture<SearchAgentsResponse> futureResponse) {
232               PageContext<SearchAgentsRequest, SearchAgentsResponse, Agent> pageContext =
233                   PageContext.create(callable, SEARCH_AGENTS_PAGE_STR_DESC, request, context);
234               return SearchAgentsPagedResponse.createAsync(pageContext, futureResponse);
235             }
236           };
237 
238   private static final PagedListResponseFactory<
239           ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
240       LIST_LOCATIONS_PAGE_STR_FACT =
241           new PagedListResponseFactory<
242               ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>() {
243             @Override
244             public ApiFuture<ListLocationsPagedResponse> getFuturePagedResponse(
245                 UnaryCallable<ListLocationsRequest, ListLocationsResponse> callable,
246                 ListLocationsRequest request,
247                 ApiCallContext context,
248                 ApiFuture<ListLocationsResponse> futureResponse) {
249               PageContext<ListLocationsRequest, ListLocationsResponse, Location> pageContext =
250                   PageContext.create(callable, LIST_LOCATIONS_PAGE_STR_DESC, request, context);
251               return ListLocationsPagedResponse.createAsync(pageContext, futureResponse);
252             }
253           };
254 
255   /** Returns the object with the settings used for calls to getAgent. */
getAgentSettings()256   public UnaryCallSettings<GetAgentRequest, Agent> getAgentSettings() {
257     return getAgentSettings;
258   }
259 
260   /** Returns the object with the settings used for calls to setAgent. */
setAgentSettings()261   public UnaryCallSettings<SetAgentRequest, Agent> setAgentSettings() {
262     return setAgentSettings;
263   }
264 
265   /** Returns the object with the settings used for calls to deleteAgent. */
deleteAgentSettings()266   public UnaryCallSettings<DeleteAgentRequest, Empty> deleteAgentSettings() {
267     return deleteAgentSettings;
268   }
269 
270   /** Returns the object with the settings used for calls to searchAgents. */
271   public PagedCallSettings<SearchAgentsRequest, SearchAgentsResponse, SearchAgentsPagedResponse>
searchAgentsSettings()272       searchAgentsSettings() {
273     return searchAgentsSettings;
274   }
275 
276   /** Returns the object with the settings used for calls to trainAgent. */
trainAgentSettings()277   public UnaryCallSettings<TrainAgentRequest, Operation> trainAgentSettings() {
278     return trainAgentSettings;
279   }
280 
281   /** Returns the object with the settings used for calls to trainAgent. */
trainAgentOperationSettings()282   public OperationCallSettings<TrainAgentRequest, Empty, Struct> trainAgentOperationSettings() {
283     return trainAgentOperationSettings;
284   }
285 
286   /** Returns the object with the settings used for calls to exportAgent. */
exportAgentSettings()287   public UnaryCallSettings<ExportAgentRequest, Operation> exportAgentSettings() {
288     return exportAgentSettings;
289   }
290 
291   /** Returns the object with the settings used for calls to exportAgent. */
292   public OperationCallSettings<ExportAgentRequest, ExportAgentResponse, Struct>
exportAgentOperationSettings()293       exportAgentOperationSettings() {
294     return exportAgentOperationSettings;
295   }
296 
297   /** Returns the object with the settings used for calls to importAgent. */
importAgentSettings()298   public UnaryCallSettings<ImportAgentRequest, Operation> importAgentSettings() {
299     return importAgentSettings;
300   }
301 
302   /** Returns the object with the settings used for calls to importAgent. */
importAgentOperationSettings()303   public OperationCallSettings<ImportAgentRequest, Empty, Struct> importAgentOperationSettings() {
304     return importAgentOperationSettings;
305   }
306 
307   /** Returns the object with the settings used for calls to restoreAgent. */
restoreAgentSettings()308   public UnaryCallSettings<RestoreAgentRequest, Operation> restoreAgentSettings() {
309     return restoreAgentSettings;
310   }
311 
312   /** Returns the object with the settings used for calls to restoreAgent. */
restoreAgentOperationSettings()313   public OperationCallSettings<RestoreAgentRequest, Empty, Struct> restoreAgentOperationSettings() {
314     return restoreAgentOperationSettings;
315   }
316 
317   /** Returns the object with the settings used for calls to getValidationResult. */
318   public UnaryCallSettings<GetValidationResultRequest, ValidationResult>
getValidationResultSettings()319       getValidationResultSettings() {
320     return getValidationResultSettings;
321   }
322 
323   /** Returns the object with the settings used for calls to listLocations. */
324   public PagedCallSettings<ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings()325       listLocationsSettings() {
326     return listLocationsSettings;
327   }
328 
329   /** Returns the object with the settings used for calls to getLocation. */
getLocationSettings()330   public UnaryCallSettings<GetLocationRequest, Location> getLocationSettings() {
331     return getLocationSettings;
332   }
333 
createStub()334   public AgentsStub createStub() throws IOException {
335     if (getTransportChannelProvider()
336         .getTransportName()
337         .equals(GrpcTransportChannel.getGrpcTransportName())) {
338       return GrpcAgentsStub.create(this);
339     }
340     if (getTransportChannelProvider()
341         .getTransportName()
342         .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
343       return HttpJsonAgentsStub.create(this);
344     }
345     throw new UnsupportedOperationException(
346         String.format(
347             "Transport not supported: %s", getTransportChannelProvider().getTransportName()));
348   }
349 
350   /** Returns a builder for the default ExecutorProvider for this service. */
defaultExecutorProviderBuilder()351   public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
352     return InstantiatingExecutorProvider.newBuilder();
353   }
354 
355   /** Returns the default service endpoint. */
getDefaultEndpoint()356   public static String getDefaultEndpoint() {
357     return "dialogflow.googleapis.com:443";
358   }
359 
360   /** Returns the default mTLS service endpoint. */
getDefaultMtlsEndpoint()361   public static String getDefaultMtlsEndpoint() {
362     return "dialogflow.mtls.googleapis.com:443";
363   }
364 
365   /** Returns the default service scopes. */
getDefaultServiceScopes()366   public static List<String> getDefaultServiceScopes() {
367     return DEFAULT_SERVICE_SCOPES;
368   }
369 
370   /** Returns a builder for the default credentials for this service. */
defaultCredentialsProviderBuilder()371   public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
372     return GoogleCredentialsProvider.newBuilder()
373         .setScopesToApply(DEFAULT_SERVICE_SCOPES)
374         .setUseJwtAccessWithScope(true);
375   }
376 
377   /** Returns a builder for the default gRPC ChannelProvider for this service. */
defaultGrpcTransportProviderBuilder()378   public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
379     return InstantiatingGrpcChannelProvider.newBuilder()
380         .setMaxInboundMessageSize(Integer.MAX_VALUE);
381   }
382 
383   /** Returns a builder for the default REST ChannelProvider for this service. */
384   @BetaApi
385   public static InstantiatingHttpJsonChannelProvider.Builder
defaultHttpJsonTransportProviderBuilder()386       defaultHttpJsonTransportProviderBuilder() {
387     return InstantiatingHttpJsonChannelProvider.newBuilder();
388   }
389 
defaultTransportChannelProvider()390   public static TransportChannelProvider defaultTransportChannelProvider() {
391     return defaultGrpcTransportProviderBuilder().build();
392   }
393 
394   @BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
defaultGrpcApiClientHeaderProviderBuilder()395   public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() {
396     return ApiClientHeaderProvider.newBuilder()
397         .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(AgentsStubSettings.class))
398         .setTransportToken(
399             GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
400   }
401 
402   @BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
defaultHttpJsonApiClientHeaderProviderBuilder()403   public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() {
404     return ApiClientHeaderProvider.newBuilder()
405         .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(AgentsStubSettings.class))
406         .setTransportToken(
407             GaxHttpJsonProperties.getHttpJsonTokenName(),
408             GaxHttpJsonProperties.getHttpJsonVersion());
409   }
410 
defaultApiClientHeaderProviderBuilder()411   public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
412     return AgentsStubSettings.defaultGrpcApiClientHeaderProviderBuilder();
413   }
414 
415   /** Returns a new gRPC builder for this class. */
newBuilder()416   public static Builder newBuilder() {
417     return Builder.createDefault();
418   }
419 
420   /** Returns a new REST builder for this class. */
newHttpJsonBuilder()421   public static Builder newHttpJsonBuilder() {
422     return Builder.createHttpJsonDefault();
423   }
424 
425   /** Returns a new builder for this class. */
newBuilder(ClientContext clientContext)426   public static Builder newBuilder(ClientContext clientContext) {
427     return new Builder(clientContext);
428   }
429 
430   /** Returns a builder containing all the values of this settings class. */
toBuilder()431   public Builder toBuilder() {
432     return new Builder(this);
433   }
434 
AgentsStubSettings(Builder settingsBuilder)435   protected AgentsStubSettings(Builder settingsBuilder) throws IOException {
436     super(settingsBuilder);
437 
438     getAgentSettings = settingsBuilder.getAgentSettings().build();
439     setAgentSettings = settingsBuilder.setAgentSettings().build();
440     deleteAgentSettings = settingsBuilder.deleteAgentSettings().build();
441     searchAgentsSettings = settingsBuilder.searchAgentsSettings().build();
442     trainAgentSettings = settingsBuilder.trainAgentSettings().build();
443     trainAgentOperationSettings = settingsBuilder.trainAgentOperationSettings().build();
444     exportAgentSettings = settingsBuilder.exportAgentSettings().build();
445     exportAgentOperationSettings = settingsBuilder.exportAgentOperationSettings().build();
446     importAgentSettings = settingsBuilder.importAgentSettings().build();
447     importAgentOperationSettings = settingsBuilder.importAgentOperationSettings().build();
448     restoreAgentSettings = settingsBuilder.restoreAgentSettings().build();
449     restoreAgentOperationSettings = settingsBuilder.restoreAgentOperationSettings().build();
450     getValidationResultSettings = settingsBuilder.getValidationResultSettings().build();
451     listLocationsSettings = settingsBuilder.listLocationsSettings().build();
452     getLocationSettings = settingsBuilder.getLocationSettings().build();
453   }
454 
455   /** Builder for AgentsStubSettings. */
456   public static class Builder extends StubSettings.Builder<AgentsStubSettings, Builder> {
457     private final ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders;
458     private final UnaryCallSettings.Builder<GetAgentRequest, Agent> getAgentSettings;
459     private final UnaryCallSettings.Builder<SetAgentRequest, Agent> setAgentSettings;
460     private final UnaryCallSettings.Builder<DeleteAgentRequest, Empty> deleteAgentSettings;
461     private final PagedCallSettings.Builder<
462             SearchAgentsRequest, SearchAgentsResponse, SearchAgentsPagedResponse>
463         searchAgentsSettings;
464     private final UnaryCallSettings.Builder<TrainAgentRequest, Operation> trainAgentSettings;
465     private final OperationCallSettings.Builder<TrainAgentRequest, Empty, Struct>
466         trainAgentOperationSettings;
467     private final UnaryCallSettings.Builder<ExportAgentRequest, Operation> exportAgentSettings;
468     private final OperationCallSettings.Builder<ExportAgentRequest, ExportAgentResponse, Struct>
469         exportAgentOperationSettings;
470     private final UnaryCallSettings.Builder<ImportAgentRequest, Operation> importAgentSettings;
471     private final OperationCallSettings.Builder<ImportAgentRequest, Empty, Struct>
472         importAgentOperationSettings;
473     private final UnaryCallSettings.Builder<RestoreAgentRequest, Operation> restoreAgentSettings;
474     private final OperationCallSettings.Builder<RestoreAgentRequest, Empty, Struct>
475         restoreAgentOperationSettings;
476     private final UnaryCallSettings.Builder<GetValidationResultRequest, ValidationResult>
477         getValidationResultSettings;
478     private final PagedCallSettings.Builder<
479             ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
480         listLocationsSettings;
481     private final UnaryCallSettings.Builder<GetLocationRequest, Location> getLocationSettings;
482     private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>>
483         RETRYABLE_CODE_DEFINITIONS;
484 
485     static {
486       ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions =
487           ImmutableMap.builder();
488       definitions.put(
489           "retry_policy_0_codes",
490           ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList(StatusCode.Code.UNAVAILABLE)));
491       RETRYABLE_CODE_DEFINITIONS = definitions.build();
492     }
493 
494     private static final ImmutableMap<String, RetrySettings> RETRY_PARAM_DEFINITIONS;
495 
496     static {
497       ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder();
498       RetrySettings settings = null;
499       settings =
500           RetrySettings.newBuilder()
501               .setInitialRetryDelay(Duration.ofMillis(100L))
502               .setRetryDelayMultiplier(1.3)
503               .setMaxRetryDelay(Duration.ofMillis(60000L))
504               .setInitialRpcTimeout(Duration.ofMillis(60000L))
505               .setRpcTimeoutMultiplier(1.0)
506               .setMaxRpcTimeout(Duration.ofMillis(60000L))
507               .setTotalTimeout(Duration.ofMillis(60000L))
508               .build();
509       definitions.put("retry_policy_0_params", settings);
510       RETRY_PARAM_DEFINITIONS = definitions.build();
511     }
512 
Builder()513     protected Builder() {
514       this(((ClientContext) null));
515     }
516 
Builder(ClientContext clientContext)517     protected Builder(ClientContext clientContext) {
518       super(clientContext);
519 
520       getAgentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
521       setAgentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
522       deleteAgentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
523       searchAgentsSettings = PagedCallSettings.newBuilder(SEARCH_AGENTS_PAGE_STR_FACT);
524       trainAgentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
525       trainAgentOperationSettings = OperationCallSettings.newBuilder();
526       exportAgentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
527       exportAgentOperationSettings = OperationCallSettings.newBuilder();
528       importAgentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
529       importAgentOperationSettings = OperationCallSettings.newBuilder();
530       restoreAgentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
531       restoreAgentOperationSettings = OperationCallSettings.newBuilder();
532       getValidationResultSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
533       listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT);
534       getLocationSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
535 
536       unaryMethodSettingsBuilders =
537           ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
538               getAgentSettings,
539               setAgentSettings,
540               deleteAgentSettings,
541               searchAgentsSettings,
542               trainAgentSettings,
543               exportAgentSettings,
544               importAgentSettings,
545               restoreAgentSettings,
546               getValidationResultSettings,
547               listLocationsSettings,
548               getLocationSettings);
549       initDefaults(this);
550     }
551 
Builder(AgentsStubSettings settings)552     protected Builder(AgentsStubSettings settings) {
553       super(settings);
554 
555       getAgentSettings = settings.getAgentSettings.toBuilder();
556       setAgentSettings = settings.setAgentSettings.toBuilder();
557       deleteAgentSettings = settings.deleteAgentSettings.toBuilder();
558       searchAgentsSettings = settings.searchAgentsSettings.toBuilder();
559       trainAgentSettings = settings.trainAgentSettings.toBuilder();
560       trainAgentOperationSettings = settings.trainAgentOperationSettings.toBuilder();
561       exportAgentSettings = settings.exportAgentSettings.toBuilder();
562       exportAgentOperationSettings = settings.exportAgentOperationSettings.toBuilder();
563       importAgentSettings = settings.importAgentSettings.toBuilder();
564       importAgentOperationSettings = settings.importAgentOperationSettings.toBuilder();
565       restoreAgentSettings = settings.restoreAgentSettings.toBuilder();
566       restoreAgentOperationSettings = settings.restoreAgentOperationSettings.toBuilder();
567       getValidationResultSettings = settings.getValidationResultSettings.toBuilder();
568       listLocationsSettings = settings.listLocationsSettings.toBuilder();
569       getLocationSettings = settings.getLocationSettings.toBuilder();
570 
571       unaryMethodSettingsBuilders =
572           ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
573               getAgentSettings,
574               setAgentSettings,
575               deleteAgentSettings,
576               searchAgentsSettings,
577               trainAgentSettings,
578               exportAgentSettings,
579               importAgentSettings,
580               restoreAgentSettings,
581               getValidationResultSettings,
582               listLocationsSettings,
583               getLocationSettings);
584     }
585 
createDefault()586     private static Builder createDefault() {
587       Builder builder = new Builder(((ClientContext) null));
588 
589       builder.setTransportChannelProvider(defaultTransportChannelProvider());
590       builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
591       builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
592       builder.setEndpoint(getDefaultEndpoint());
593       builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
594       builder.setSwitchToMtlsEndpointAllowed(true);
595 
596       return initDefaults(builder);
597     }
598 
createHttpJsonDefault()599     private static Builder createHttpJsonDefault() {
600       Builder builder = new Builder(((ClientContext) null));
601 
602       builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build());
603       builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
604       builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build());
605       builder.setEndpoint(getDefaultEndpoint());
606       builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
607       builder.setSwitchToMtlsEndpointAllowed(true);
608 
609       return initDefaults(builder);
610     }
611 
initDefaults(Builder builder)612     private static Builder initDefaults(Builder builder) {
613       builder
614           .getAgentSettings()
615           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
616           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
617 
618       builder
619           .setAgentSettings()
620           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
621           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
622 
623       builder
624           .deleteAgentSettings()
625           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
626           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
627 
628       builder
629           .searchAgentsSettings()
630           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
631           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
632 
633       builder
634           .trainAgentSettings()
635           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
636           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
637 
638       builder
639           .exportAgentSettings()
640           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
641           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
642 
643       builder
644           .importAgentSettings()
645           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
646           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
647 
648       builder
649           .restoreAgentSettings()
650           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
651           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
652 
653       builder
654           .getValidationResultSettings()
655           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
656           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
657 
658       builder
659           .listLocationsSettings()
660           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
661           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
662 
663       builder
664           .getLocationSettings()
665           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
666           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
667 
668       builder
669           .trainAgentOperationSettings()
670           .setInitialCallSettings(
671               UnaryCallSettings.<TrainAgentRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
672                   .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
673                   .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"))
674                   .build())
675           .setResponseTransformer(
676               ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
677           .setMetadataTransformer(
678               ProtoOperationTransformers.MetadataTransformer.create(Struct.class))
679           .setPollingAlgorithm(
680               OperationTimedPollAlgorithm.create(
681                   RetrySettings.newBuilder()
682                       .setInitialRetryDelay(Duration.ofMillis(5000L))
683                       .setRetryDelayMultiplier(1.5)
684                       .setMaxRetryDelay(Duration.ofMillis(45000L))
685                       .setInitialRpcTimeout(Duration.ZERO)
686                       .setRpcTimeoutMultiplier(1.0)
687                       .setMaxRpcTimeout(Duration.ZERO)
688                       .setTotalTimeout(Duration.ofMillis(300000L))
689                       .build()));
690 
691       builder
692           .exportAgentOperationSettings()
693           .setInitialCallSettings(
694               UnaryCallSettings.<ExportAgentRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
695                   .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
696                   .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"))
697                   .build())
698           .setResponseTransformer(
699               ProtoOperationTransformers.ResponseTransformer.create(ExportAgentResponse.class))
700           .setMetadataTransformer(
701               ProtoOperationTransformers.MetadataTransformer.create(Struct.class))
702           .setPollingAlgorithm(
703               OperationTimedPollAlgorithm.create(
704                   RetrySettings.newBuilder()
705                       .setInitialRetryDelay(Duration.ofMillis(5000L))
706                       .setRetryDelayMultiplier(1.5)
707                       .setMaxRetryDelay(Duration.ofMillis(45000L))
708                       .setInitialRpcTimeout(Duration.ZERO)
709                       .setRpcTimeoutMultiplier(1.0)
710                       .setMaxRpcTimeout(Duration.ZERO)
711                       .setTotalTimeout(Duration.ofMillis(300000L))
712                       .build()));
713 
714       builder
715           .importAgentOperationSettings()
716           .setInitialCallSettings(
717               UnaryCallSettings.<ImportAgentRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
718                   .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
719                   .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"))
720                   .build())
721           .setResponseTransformer(
722               ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
723           .setMetadataTransformer(
724               ProtoOperationTransformers.MetadataTransformer.create(Struct.class))
725           .setPollingAlgorithm(
726               OperationTimedPollAlgorithm.create(
727                   RetrySettings.newBuilder()
728                       .setInitialRetryDelay(Duration.ofMillis(5000L))
729                       .setRetryDelayMultiplier(1.5)
730                       .setMaxRetryDelay(Duration.ofMillis(45000L))
731                       .setInitialRpcTimeout(Duration.ZERO)
732                       .setRpcTimeoutMultiplier(1.0)
733                       .setMaxRpcTimeout(Duration.ZERO)
734                       .setTotalTimeout(Duration.ofMillis(300000L))
735                       .build()));
736 
737       builder
738           .restoreAgentOperationSettings()
739           .setInitialCallSettings(
740               UnaryCallSettings
741                   .<RestoreAgentRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
742                   .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
743                   .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"))
744                   .build())
745           .setResponseTransformer(
746               ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
747           .setMetadataTransformer(
748               ProtoOperationTransformers.MetadataTransformer.create(Struct.class))
749           .setPollingAlgorithm(
750               OperationTimedPollAlgorithm.create(
751                   RetrySettings.newBuilder()
752                       .setInitialRetryDelay(Duration.ofMillis(5000L))
753                       .setRetryDelayMultiplier(1.5)
754                       .setMaxRetryDelay(Duration.ofMillis(45000L))
755                       .setInitialRpcTimeout(Duration.ZERO)
756                       .setRpcTimeoutMultiplier(1.0)
757                       .setMaxRpcTimeout(Duration.ZERO)
758                       .setTotalTimeout(Duration.ofMillis(300000L))
759                       .build()));
760 
761       return builder;
762     }
763 
764     /**
765      * Applies the given settings updater function to all of the unary API methods in this service.
766      *
767      * <p>Note: This method does not support applying settings to streaming methods.
768      */
applyToAllUnaryMethods( ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater)769     public Builder applyToAllUnaryMethods(
770         ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater) {
771       super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater);
772       return this;
773     }
774 
unaryMethodSettingsBuilders()775     public ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders() {
776       return unaryMethodSettingsBuilders;
777     }
778 
779     /** Returns the builder for the settings used for calls to getAgent. */
getAgentSettings()780     public UnaryCallSettings.Builder<GetAgentRequest, Agent> getAgentSettings() {
781       return getAgentSettings;
782     }
783 
784     /** Returns the builder for the settings used for calls to setAgent. */
setAgentSettings()785     public UnaryCallSettings.Builder<SetAgentRequest, Agent> setAgentSettings() {
786       return setAgentSettings;
787     }
788 
789     /** Returns the builder for the settings used for calls to deleteAgent. */
deleteAgentSettings()790     public UnaryCallSettings.Builder<DeleteAgentRequest, Empty> deleteAgentSettings() {
791       return deleteAgentSettings;
792     }
793 
794     /** Returns the builder for the settings used for calls to searchAgents. */
795     public PagedCallSettings.Builder<
796             SearchAgentsRequest, SearchAgentsResponse, SearchAgentsPagedResponse>
searchAgentsSettings()797         searchAgentsSettings() {
798       return searchAgentsSettings;
799     }
800 
801     /** Returns the builder for the settings used for calls to trainAgent. */
trainAgentSettings()802     public UnaryCallSettings.Builder<TrainAgentRequest, Operation> trainAgentSettings() {
803       return trainAgentSettings;
804     }
805 
806     /** Returns the builder for the settings used for calls to trainAgent. */
807     @BetaApi(
808         "The surface for use by generated code is not stable yet and may change in the future.")
809     public OperationCallSettings.Builder<TrainAgentRequest, Empty, Struct>
trainAgentOperationSettings()810         trainAgentOperationSettings() {
811       return trainAgentOperationSettings;
812     }
813 
814     /** Returns the builder for the settings used for calls to exportAgent. */
exportAgentSettings()815     public UnaryCallSettings.Builder<ExportAgentRequest, Operation> exportAgentSettings() {
816       return exportAgentSettings;
817     }
818 
819     /** Returns the builder for the settings used for calls to exportAgent. */
820     @BetaApi(
821         "The surface for use by generated code is not stable yet and may change in the future.")
822     public OperationCallSettings.Builder<ExportAgentRequest, ExportAgentResponse, Struct>
exportAgentOperationSettings()823         exportAgentOperationSettings() {
824       return exportAgentOperationSettings;
825     }
826 
827     /** Returns the builder for the settings used for calls to importAgent. */
importAgentSettings()828     public UnaryCallSettings.Builder<ImportAgentRequest, Operation> importAgentSettings() {
829       return importAgentSettings;
830     }
831 
832     /** Returns the builder for the settings used for calls to importAgent. */
833     @BetaApi(
834         "The surface for use by generated code is not stable yet and may change in the future.")
835     public OperationCallSettings.Builder<ImportAgentRequest, Empty, Struct>
importAgentOperationSettings()836         importAgentOperationSettings() {
837       return importAgentOperationSettings;
838     }
839 
840     /** Returns the builder for the settings used for calls to restoreAgent. */
restoreAgentSettings()841     public UnaryCallSettings.Builder<RestoreAgentRequest, Operation> restoreAgentSettings() {
842       return restoreAgentSettings;
843     }
844 
845     /** Returns the builder for the settings used for calls to restoreAgent. */
846     @BetaApi(
847         "The surface for use by generated code is not stable yet and may change in the future.")
848     public OperationCallSettings.Builder<RestoreAgentRequest, Empty, Struct>
restoreAgentOperationSettings()849         restoreAgentOperationSettings() {
850       return restoreAgentOperationSettings;
851     }
852 
853     /** Returns the builder for the settings used for calls to getValidationResult. */
854     public UnaryCallSettings.Builder<GetValidationResultRequest, ValidationResult>
getValidationResultSettings()855         getValidationResultSettings() {
856       return getValidationResultSettings;
857     }
858 
859     /** Returns the builder for the settings used for calls to listLocations. */
860     public PagedCallSettings.Builder<
861             ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings()862         listLocationsSettings() {
863       return listLocationsSettings;
864     }
865 
866     /** Returns the builder for the settings used for calls to getLocation. */
getLocationSettings()867     public UnaryCallSettings.Builder<GetLocationRequest, Location> getLocationSettings() {
868       return getLocationSettings;
869     }
870 
871     @Override
build()872     public AgentsStubSettings build() throws IOException {
873       return new AgentsStubSettings(this);
874     }
875   }
876 }
877