11/*
2- * Copyright 2017 , Google LLC All rights reserved.
2+ * Copyright 2018 , Google LLC All rights reserved.
33 *
44 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions are
3232import static com .google .longrunning .PagedResponseWrappers .ListOperationsPagedResponse ;
3333
3434import com .google .api .core .ApiFunction ;
35- import com .google .api .core .ApiFuture ;
3635import com .google .api .core .BetaApi ;
37- import com .google .api .gax .core .GaxProperties ;
3836import com .google .api .gax .core .GoogleCredentialsProvider ;
3937import com .google .api .gax .core .InstantiatingExecutorProvider ;
40- import com .google .api .gax .grpc .GaxGrpcProperties ;
41- import com .google .api .gax .grpc .GrpcTransportChannel ;
42- import com .google .api .gax .retrying .RetrySettings ;
43- import com .google .api .gax .rpc .ApiCallContext ;
4438import com .google .api .gax .rpc .ApiClientHeaderProvider ;
4539import com .google .api .gax .rpc .ClientContext ;
4640import com .google .api .gax .rpc .ClientSettings ;
47- import com .google .api .gax .rpc .PageContext ;
4841import com .google .api .gax .rpc .PagedCallSettings ;
49- import com .google .api .gax .rpc .PagedListDescriptor ;
50- import com .google .api .gax .rpc .PagedListResponseFactory ;
51- import com .google .api .gax .rpc .StatusCode ;
5242import com .google .api .gax .rpc .UnaryCallSettings ;
53- import com .google .api .gax .rpc .UnaryCallable ;
54- import com .google .common .collect .ImmutableList ;
55- import com .google .common .collect .ImmutableMap ;
56- import com .google .common .collect .ImmutableSet ;
57- import com .google .common .collect .Lists ;
58- import com .google .longrunning .stub .GrpcOperationsStub ;
59- import com .google .longrunning .stub .OperationsStub ;
43+ import com .google .longrunning .stub .OperationsStubSettings ;
6044import com .google .protobuf .Empty ;
6145import java .io .IOException ;
6246import javax .annotation .Generated ;
63- import org .threeten .bp .Duration ;
6447
6548// AUTO-GENERATED DOCUMENTATION AND CLASS
6649/** Settings class to configure an instance of {@link OperationsClient}. */
6750@ Generated ("by GAPIC v0.0.5" )
6851@ BetaApi
6952public class OperationsSettings extends ClientSettings <OperationsSettings > {
70- private final UnaryCallSettings <GetOperationRequest , Operation > getOperationSettings ;
71- private final PagedCallSettings <
72- ListOperationsRequest , ListOperationsResponse , ListOperationsPagedResponse >
73- listOperationsSettings ;
74- private final UnaryCallSettings <CancelOperationRequest , Empty > cancelOperationSettings ;
75- private final UnaryCallSettings <DeleteOperationRequest , Empty > deleteOperationSettings ;
76-
7753 /** Returns the object with the settings used for calls to getOperation. */
7854 public UnaryCallSettings <GetOperationRequest , Operation > getOperationSettings () {
79- return getOperationSettings ;
55+ return (( OperationsStubSettings ) getStubSettings ()). getOperationSettings () ;
8056 }
8157
8258 /** Returns the object with the settings used for calls to listOperations. */
8359 public PagedCallSettings <
8460 ListOperationsRequest , ListOperationsResponse , ListOperationsPagedResponse >
8561 listOperationsSettings () {
86- return listOperationsSettings ;
62+ return (( OperationsStubSettings ) getStubSettings ()). listOperationsSettings () ;
8763 }
8864
8965 /** Returns the object with the settings used for calls to cancelOperation. */
9066 public UnaryCallSettings <CancelOperationRequest , Empty > cancelOperationSettings () {
91- return cancelOperationSettings ;
67+ return (( OperationsStubSettings ) getStubSettings ()). cancelOperationSettings () ;
9268 }
9369
9470 /** Returns the object with the settings used for calls to deleteOperation. */
9571 public UnaryCallSettings <DeleteOperationRequest , Empty > deleteOperationSettings () {
96- return deleteOperationSettings ;
72+ return (( OperationsStubSettings ) getStubSettings ()). deleteOperationSettings () ;
9773 }
9874
99- @ BetaApi ("A restructuring of stub classes is planned, so this may break in the future" )
100- public OperationsStub createStub () throws IOException {
101- if (getTransportChannelProvider ()
102- .getTransportName ()
103- .equals (GrpcTransportChannel .getGrpcTransportName ())) {
104- return GrpcOperationsStub .create (this );
105- } else {
106- throw new UnsupportedOperationException (
107- "Transport not supported: " + getTransportChannelProvider ().getTransportName ());
108- }
75+ public static final OperationsSettings create (OperationsStubSettings stub ) throws IOException {
76+ return new OperationsSettings .Builder (stub .toBuilder ()).build ();
10977 }
11078
11179 /** Returns a builder for the default ExecutorProvider for this service. */
11280 public static InstantiatingExecutorProvider .Builder defaultExecutorProviderBuilder () {
113- return InstantiatingExecutorProvider . newBuilder ();
81+ return OperationsStubSettings . defaultExecutorProviderBuilder ();
11482 }
11583
11684 /** Returns a builder for the default credentials for this service. */
11785 public static GoogleCredentialsProvider .Builder defaultCredentialsProviderBuilder () {
118- return GoogleCredentialsProvider . newBuilder ();
86+ return OperationsStubSettings . defaultCredentialsProviderBuilder ();
11987 }
12088
12189 @ BetaApi ("The surface for customizing headers is not stable yet and may change in the future." )
12290 public static ApiClientHeaderProvider .Builder defaultApiClientHeaderProviderBuilder () {
123- return ApiClientHeaderProvider .newBuilder ()
124- .setGeneratedLibToken ("gapic" , GaxProperties .getLibraryVersion (OperationsSettings .class ))
125- .setTransportToken (
126- GaxGrpcProperties .getGrpcTokenName (), GaxGrpcProperties .getGrpcVersion ());
91+ return OperationsStubSettings .defaultApiClientHeaderProviderBuilder ();
12792 }
12893
12994 /** Returns a new builder for this class. */
@@ -141,181 +106,34 @@ public Builder toBuilder() {
141106 return new Builder (this );
142107 }
143108
144- private OperationsSettings (Builder settingsBuilder ) throws IOException {
109+ protected OperationsSettings (Builder settingsBuilder ) throws IOException {
145110 super (settingsBuilder );
146-
147- getOperationSettings = settingsBuilder .getOperationSettings ().build ();
148- listOperationsSettings = settingsBuilder .listOperationsSettings ().build ();
149- cancelOperationSettings = settingsBuilder .cancelOperationSettings ().build ();
150- deleteOperationSettings = settingsBuilder .deleteOperationSettings ().build ();
151111 }
152112
153- private static final PagedListDescriptor <ListOperationsRequest , ListOperationsResponse , Operation >
154- LIST_OPERATIONS_PAGE_STR_DESC =
155- new PagedListDescriptor <ListOperationsRequest , ListOperationsResponse , Operation >() {
156- @ Override
157- public String emptyToken () {
158- return "" ;
159- }
160-
161- @ Override
162- public ListOperationsRequest injectToken (ListOperationsRequest payload , String token ) {
163- return ListOperationsRequest .newBuilder (payload ).setPageToken (token ).build ();
164- }
165-
166- @ Override
167- public ListOperationsRequest injectPageSize (
168- ListOperationsRequest payload , int pageSize ) {
169- return ListOperationsRequest .newBuilder (payload ).setPageSize (pageSize ).build ();
170- }
171-
172- @ Override
173- public Integer extractPageSize (ListOperationsRequest payload ) {
174- return payload .getPageSize ();
175- }
176-
177- @ Override
178- public String extractNextToken (ListOperationsResponse payload ) {
179- return payload .getNextPageToken ();
180- }
181-
182- @ Override
183- public Iterable <Operation > extractResources (ListOperationsResponse payload ) {
184- return payload .getOperationsList ();
185- }
186- };
187-
188- private static final PagedListResponseFactory <
189- ListOperationsRequest , ListOperationsResponse , ListOperationsPagedResponse >
190- LIST_OPERATIONS_PAGE_STR_FACT =
191- new PagedListResponseFactory <
192- ListOperationsRequest , ListOperationsResponse , ListOperationsPagedResponse >() {
193- @ Override
194- public ApiFuture <ListOperationsPagedResponse > getFuturePagedResponse (
195- UnaryCallable <ListOperationsRequest , ListOperationsResponse > callable ,
196- ListOperationsRequest request ,
197- ApiCallContext context ,
198- ApiFuture <ListOperationsResponse > futureResponse ) {
199- PageContext <ListOperationsRequest , ListOperationsResponse , Operation > pageContext =
200- PageContext .create (callable , LIST_OPERATIONS_PAGE_STR_DESC , request , context );
201- return ListOperationsPagedResponse .createAsync (pageContext , futureResponse );
202- }
203- };
204-
205113 /** Builder for OperationsSettings. */
206114 public static class Builder extends ClientSettings .Builder <OperationsSettings , Builder > {
207- private final ImmutableList <UnaryCallSettings .Builder <?, ?>> unaryMethodSettingsBuilders ;
208-
209- private final UnaryCallSettings .Builder <GetOperationRequest , Operation > getOperationSettings ;
210- private final PagedCallSettings .Builder <
211- ListOperationsRequest , ListOperationsResponse , ListOperationsPagedResponse >
212- listOperationsSettings ;
213- private final UnaryCallSettings .Builder <CancelOperationRequest , Empty > cancelOperationSettings ;
214- private final UnaryCallSettings .Builder <DeleteOperationRequest , Empty > deleteOperationSettings ;
215-
216- private static final ImmutableMap <String , ImmutableSet <StatusCode .Code >>
217- RETRYABLE_CODE_DEFINITIONS ;
218-
219- static {
220- ImmutableMap .Builder <String , ImmutableSet <StatusCode .Code >> definitions =
221- ImmutableMap .builder ();
222- definitions .put (
223- "idempotent" ,
224- ImmutableSet .copyOf (
225- Lists .<StatusCode .Code >newArrayList (
226- StatusCode .Code .DEADLINE_EXCEEDED , StatusCode .Code .UNAVAILABLE )));
227- definitions .put ("non_idempotent" , ImmutableSet .copyOf (Lists .<StatusCode .Code >newArrayList ()));
228- RETRYABLE_CODE_DEFINITIONS = definitions .build ();
229- }
230-
231- private static final ImmutableMap <String , RetrySettings > RETRY_PARAM_DEFINITIONS ;
232-
233- static {
234- ImmutableMap .Builder <String , RetrySettings > definitions = ImmutableMap .builder ();
235- RetrySettings settings = null ;
236- settings =
237- RetrySettings .newBuilder ()
238- .setInitialRetryDelay (Duration .ofMillis (100L ))
239- .setRetryDelayMultiplier (1.3 )
240- .setMaxRetryDelay (Duration .ofMillis (60000L ))
241- .setInitialRpcTimeout (Duration .ofMillis (90000L ))
242- .setRpcTimeoutMultiplier (1.0 )
243- .setMaxRpcTimeout (Duration .ofMillis (90000L ))
244- .setTotalTimeout (Duration .ofMillis (600000L ))
245- .build ();
246- definitions .put ("default" , settings );
247- RETRY_PARAM_DEFINITIONS = definitions .build ();
248- }
249-
250- private Builder () {
115+ protected Builder () throws IOException {
251116 this ((ClientContext ) null );
252117 }
253118
254- private Builder (ClientContext clientContext ) {
255- super (clientContext );
256-
257- getOperationSettings = UnaryCallSettings .newUnaryCallSettingsBuilder ();
258-
259- listOperationsSettings = PagedCallSettings .newBuilder (LIST_OPERATIONS_PAGE_STR_FACT );
260-
261- cancelOperationSettings = UnaryCallSettings .newUnaryCallSettingsBuilder ();
262-
263- deleteOperationSettings = UnaryCallSettings .newUnaryCallSettingsBuilder ();
264-
265- unaryMethodSettingsBuilders =
266- ImmutableList .<UnaryCallSettings .Builder <?, ?>>of (
267- getOperationSettings ,
268- listOperationsSettings ,
269- cancelOperationSettings ,
270- deleteOperationSettings );
271-
272- initDefaults (this );
119+ protected Builder (ClientContext clientContext ) {
120+ super (OperationsStubSettings .newBuilder (clientContext ));
273121 }
274122
275123 private static Builder createDefault () {
276- Builder builder = new Builder ((ClientContext ) null );
277- return initDefaults (builder );
124+ return new Builder (OperationsStubSettings .newBuilder ());
278125 }
279126
280- private static Builder initDefaults (Builder builder ) {
281-
282- builder
283- .getOperationSettings ()
284- .setRetryableCodes (RETRYABLE_CODE_DEFINITIONS .get ("idempotent" ))
285- .setRetrySettings (RETRY_PARAM_DEFINITIONS .get ("default" ));
286-
287- builder
288- .listOperationsSettings ()
289- .setRetryableCodes (RETRYABLE_CODE_DEFINITIONS .get ("idempotent" ))
290- .setRetrySettings (RETRY_PARAM_DEFINITIONS .get ("default" ));
291-
292- builder
293- .cancelOperationSettings ()
294- .setRetryableCodes (RETRYABLE_CODE_DEFINITIONS .get ("idempotent" ))
295- .setRetrySettings (RETRY_PARAM_DEFINITIONS .get ("default" ));
296-
297- builder
298- .deleteOperationSettings ()
299- .setRetryableCodes (RETRYABLE_CODE_DEFINITIONS .get ("idempotent" ))
300- .setRetrySettings (RETRY_PARAM_DEFINITIONS .get ("default" ));
301-
302- return builder ;
127+ protected Builder (OperationsSettings settings ) {
128+ super (settings .getStubSettings ().toBuilder ());
303129 }
304130
305- private Builder (OperationsSettings settings ) {
306- super (settings );
307-
308- getOperationSettings = settings .getOperationSettings .toBuilder ();
309- listOperationsSettings = settings .listOperationsSettings .toBuilder ();
310- cancelOperationSettings = settings .cancelOperationSettings .toBuilder ();
311- deleteOperationSettings = settings .deleteOperationSettings .toBuilder ();
131+ protected Builder (OperationsStubSettings .Builder stubSettings ) {
132+ super (stubSettings );
133+ }
312134
313- unaryMethodSettingsBuilders =
314- ImmutableList .<UnaryCallSettings .Builder <?, ?>>of (
315- getOperationSettings ,
316- listOperationsSettings ,
317- cancelOperationSettings ,
318- deleteOperationSettings );
135+ public OperationsStubSettings .Builder getStubSettingsBuilder () {
136+ return ((OperationsStubSettings .Builder ) getStubSettings ());
319137 }
320138
321139 /**
@@ -325,30 +143,31 @@ private Builder(OperationsSettings settings) {
325143 */
326144 public Builder applyToAllUnaryMethods (
327145 ApiFunction <UnaryCallSettings .Builder <?, ?>, Void > settingsUpdater ) throws Exception {
328- super .applyToAllUnaryMethods (unaryMethodSettingsBuilders , settingsUpdater );
146+ super .applyToAllUnaryMethods (
147+ getStubSettingsBuilder ().unaryMethodSettingsBuilders (), settingsUpdater );
329148 return this ;
330149 }
331150
332151 /** Returns the builder for the settings used for calls to getOperation. */
333152 public UnaryCallSettings .Builder <GetOperationRequest , Operation > getOperationSettings () {
334- return getOperationSettings ;
153+ return getStubSettingsBuilder (). getOperationSettings () ;
335154 }
336155
337156 /** Returns the builder for the settings used for calls to listOperations. */
338157 public PagedCallSettings .Builder <
339158 ListOperationsRequest , ListOperationsResponse , ListOperationsPagedResponse >
340159 listOperationsSettings () {
341- return listOperationsSettings ;
160+ return getStubSettingsBuilder (). listOperationsSettings () ;
342161 }
343162
344163 /** Returns the builder for the settings used for calls to cancelOperation. */
345164 public UnaryCallSettings .Builder <CancelOperationRequest , Empty > cancelOperationSettings () {
346- return cancelOperationSettings ;
165+ return getStubSettingsBuilder (). cancelOperationSettings () ;
347166 }
348167
349168 /** Returns the builder for the settings used for calls to deleteOperation. */
350169 public UnaryCallSettings .Builder <DeleteOperationRequest , Empty > deleteOperationSettings () {
351- return deleteOperationSettings ;
170+ return getStubSettingsBuilder (). deleteOperationSettings () ;
352171 }
353172
354173 @ Override
0 commit comments