Skip to content

Commit 8350603

Browse files
committed
Update logging with latest generator.
1 parent 1ea7a77 commit 8350603

File tree

14 files changed

+1580
-469
lines changed

14 files changed

+1580
-469
lines changed

gcloud-java-logging/baseline/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Api.java

Lines changed: 110 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
package com.google.cloud.logging.spi.v2;
3535

36+
import com.google.api.gax.core.PageAccessor;
3637
import com.google.api.gax.grpc.ApiCallable;
3738
import com.google.api.gax.protobuf.PathTemplate;
3839
import com.google.logging.v2.CreateSinkRequest;
@@ -48,33 +49,88 @@
4849
import java.io.IOException;
4950
import java.util.ArrayList;
5051
import java.util.List;
52+
import java.util.concurrent.ScheduledExecutorService;
5153

5254
// Manually-added imports: add custom (non-generated) imports after this point.
5355

5456
// AUTO-GENERATED DOCUMENTATION AND SERVICE - see instructions at the top of the file for editing.
5557
/**
5658
* Service Description:
5759
*
60+
* <p>This class provides the ability to make remote calls to the backing service through method
61+
* calls that map to API methods. Sample code to get started:
62+
*
63+
* <pre>
64+
* <code>
65+
* try (ConfigServiceV2Api configServiceV2Api = ConfigServiceV2Api.createWithDefaults()) {
66+
* String projectName = "";
67+
* ListSinksResponse response = configServiceV2Api.listSinks(projectName);
68+
* }
69+
* </code>
70+
* </pre>
71+
*
72+
* <p>Note: close() needs to be called on the configServiceV2Api object to clean up resources such
73+
* as threads. In the example above, try-with-resources is used, which automatically calls
74+
* close().
75+
*
76+
* <p>The surface of this class includes several types of Java methods for each of the API's methods:
77+
*
78+
* <ol>
79+
* <li> A "flattened" method. With this type of method, the fields of the request type have been
80+
* converted into function parameters. It may be the case that not all fields are available
81+
* as parameters, and not every API method will have a flattened method entry point.
82+
* <li> A "request object" method. This type of method only takes one parameter, a request
83+
* object, which must be constructed before the call. Not every API method will have a request
84+
* object method.
85+
* <li> A "callable" method. This type of method takes no parameters and returns an immutable
86+
* ApiCallable object, which can be used to initiate calls to the service.
87+
* </ol>
88+
*
89+
* <p>See the individual methods for example code.
90+
*
91+
* <p>Many parameters require resource names to be formatted in a particular way. To assist
92+
* with these names, this class includes a format method for each type of name, and additionally
93+
* a parse method to extract the individual identifiers contained within names that are
94+
* returned.
95+
*
96+
* <p>This class can be customized by passing in a custom instance of ConfigServiceV2Settings to
97+
* create(). For example:
98+
*
99+
* <pre>
100+
* <code>
101+
* ConfigServiceV2Settings configServiceV2Settings = ConfigServiceV2Settings.defaultBuilder()
102+
* .provideChannelWith(myCredentials)
103+
* .build();
104+
* ConfigServiceV2Api configServiceV2Api = ConfigServiceV2Api.create(configServiceV2Settings);
105+
* </code>
106+
* </pre>
107+
*
58108
* <!-- manual edit -->
59109
* <!-- end manual edit -->
60110
*/
61111
@javax.annotation.Generated("by GAPIC")
62112
public class ConfigServiceV2Api implements AutoCloseable {
113+
private final ConfigServiceV2Settings settings;
63114
private final ManagedChannel channel;
115+
private final ScheduledExecutorService executor;
64116
private final List<AutoCloseable> closeables = new ArrayList<>();
65117

66118
private final ApiCallable<ListSinksRequest, ListSinksResponse> listSinksCallable;
67-
private final ApiCallable<ListSinksRequest, Iterable<LogSink>> listSinksIterableCallable;
119+
private final ApiCallable<ListSinksRequest, PageAccessor<LogSink>> listSinksPagedCallable;
68120
private final ApiCallable<GetSinkRequest, LogSink> getSinkCallable;
69121
private final ApiCallable<CreateSinkRequest, LogSink> createSinkCallable;
70122
private final ApiCallable<UpdateSinkRequest, LogSink> updateSinkCallable;
71123
private final ApiCallable<DeleteSinkRequest, Empty> deleteSinkCallable;
72124

125+
public final ConfigServiceV2Settings getSettings() {
126+
return settings;
127+
}
128+
73129
private static final PathTemplate PROJECT_PATH_TEMPLATE =
74-
PathTemplate.create("projects/{project}");
130+
PathTemplate.createWithoutUrlEncoding("projects/{project}");
75131

76132
private static final PathTemplate SINK_PATH_TEMPLATE =
77-
PathTemplate.create("projects/{project}/sinks/{sink}");
133+
PathTemplate.createWithoutUrlEncoding("projects/{project}/sinks/{sink}");
78134

79135
/**
80136
* Formats a string containing the fully-qualified path to represent
@@ -137,8 +193,8 @@ public static final String parseSinkFromSinkName(String sinkName) {
137193
* <!-- manual edit -->
138194
* <!-- end manual edit -->
139195
*/
140-
public static final ConfigServiceV2Api defaultInstance() throws IOException {
141-
return create(ConfigServiceV2Settings.defaultInstance());
196+
public static final ConfigServiceV2Api createWithDefaults() throws IOException {
197+
return create(ConfigServiceV2Settings.defaultBuilder().build());
142198
}
143199

144200
/**
@@ -163,17 +219,24 @@ public static final ConfigServiceV2Api create(ConfigServiceV2Settings settings)
163219
* <!-- end manual edit -->
164220
*/
165221
protected ConfigServiceV2Api(ConfigServiceV2Settings settings) throws IOException {
166-
this.channel = settings.getChannel();
167-
168-
this.listSinksCallable = ApiCallable.create(settings.listSinksSettings(), settings);
169-
this.listSinksIterableCallable =
170-
ApiCallable.createIterable(settings.listSinksSettings(), settings);
171-
this.getSinkCallable = ApiCallable.create(settings.getSinkSettings(), settings);
172-
this.createSinkCallable = ApiCallable.create(settings.createSinkSettings(), settings);
173-
this.updateSinkCallable = ApiCallable.create(settings.updateSinkSettings(), settings);
174-
this.deleteSinkCallable = ApiCallable.create(settings.deleteSinkSettings(), settings);
175-
176-
if (settings.shouldAutoCloseChannel()) {
222+
this.settings = settings;
223+
this.executor = settings.getExecutorProvider().getOrBuildExecutor();
224+
this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor);
225+
226+
this.listSinksCallable =
227+
ApiCallable.create(settings.listSinksSettings(), this.channel, this.executor);
228+
this.listSinksPagedCallable =
229+
ApiCallable.createPagedVariant(settings.listSinksSettings(), this.channel, this.executor);
230+
this.getSinkCallable =
231+
ApiCallable.create(settings.getSinkSettings(), this.channel, this.executor);
232+
this.createSinkCallable =
233+
ApiCallable.create(settings.createSinkSettings(), this.channel, this.executor);
234+
this.updateSinkCallable =
235+
ApiCallable.create(settings.updateSinkSettings(), this.channel, this.executor);
236+
this.deleteSinkCallable =
237+
ApiCallable.create(settings.deleteSinkSettings(), this.channel, this.executor);
238+
239+
if (settings.getChannelProvider().shouldAutoClose()) {
177240
closeables.add(
178241
new Closeable() {
179242
@Override
@@ -182,6 +245,15 @@ public void close() throws IOException {
182245
}
183246
});
184247
}
248+
if (settings.getExecutorProvider().shouldAutoClose()) {
249+
closeables.add(
250+
new Closeable() {
251+
@Override
252+
public void close() throws IOException {
253+
executor.shutdown();
254+
}
255+
});
256+
}
185257
}
186258

187259
// ----- listSinks -----
@@ -195,9 +267,10 @@ public void close() throws IOException {
195267
*
196268
* @param projectName Required. The resource name of the project containing the sinks.
197269
* Example: `"projects/my-logging-project"`, `"projects/01234567890"`.
198-
* @throws ApiException if the remote call fails
270+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
199271
*/
200-
public final Iterable<LogSink> listSinks(String projectName) {
272+
public final PageAccessor<LogSink> listSinks(String projectName) {
273+
PROJECT_PATH_TEMPLATE.validate(projectName);
201274
ListSinksRequest request = ListSinksRequest.newBuilder().setProjectName(projectName).build();
202275
return listSinks(request);
203276
}
@@ -210,10 +283,10 @@ public final Iterable<LogSink> listSinks(String projectName) {
210283
* <!-- end manual edit -->
211284
*
212285
* @param request The request object containing all of the parameters for the API call.
213-
* @throws ApiException if the remote call fails
286+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
214287
*/
215-
public final Iterable<LogSink> listSinks(ListSinksRequest request) {
216-
return listSinksIterableCallable().call(request);
288+
public final PageAccessor<LogSink> listSinks(ListSinksRequest request) {
289+
return listSinksPagedCallable().call(request);
217290
}
218291

219292
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
@@ -222,10 +295,9 @@ public final Iterable<LogSink> listSinks(ListSinksRequest request) {
222295
*
223296
* <!-- manual edit -->
224297
* <!-- end manual edit -->
225-
* @throws ApiException if the remote call fails
226298
*/
227-
public final ApiCallable<ListSinksRequest, Iterable<LogSink>> listSinksIterableCallable() {
228-
return listSinksIterableCallable;
299+
public final ApiCallable<ListSinksRequest, PageAccessor<LogSink>> listSinksPagedCallable() {
300+
return listSinksPagedCallable;
229301
}
230302

231303
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
@@ -234,7 +306,6 @@ public final ApiCallable<ListSinksRequest, Iterable<LogSink>> listSinksIterableC
234306
*
235307
* <!-- manual edit -->
236308
* <!-- end manual edit -->
237-
* @throws ApiException if the remote call fails
238309
*/
239310
public final ApiCallable<ListSinksRequest, ListSinksResponse> listSinksCallable() {
240311
return listSinksCallable;
@@ -251,11 +322,11 @@ public final ApiCallable<ListSinksRequest, ListSinksResponse> listSinksCallable(
251322
*
252323
* @param sinkName The resource name of the sink to return.
253324
* Example: `"projects/my-project-id/sinks/my-sink-id"`.
254-
* @throws ApiException if the remote call fails
325+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
255326
*/
256327
public final LogSink getSink(String sinkName) {
328+
SINK_PATH_TEMPLATE.validate(sinkName);
257329
GetSinkRequest request = GetSinkRequest.newBuilder().setSinkName(sinkName).build();
258-
259330
return getSink(request);
260331
}
261332

@@ -267,7 +338,7 @@ public final LogSink getSink(String sinkName) {
267338
* <!-- end manual edit -->
268339
*
269340
* @param request The request object containing all of the parameters for the API call.
270-
* @throws ApiException if the remote call fails
341+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
271342
*/
272343
private LogSink getSink(GetSinkRequest request) {
273344
return getSinkCallable().call(request);
@@ -279,7 +350,6 @@ private LogSink getSink(GetSinkRequest request) {
279350
*
280351
* <!-- manual edit -->
281352
* <!-- end manual edit -->
282-
* @throws ApiException if the remote call fails
283353
*/
284354
public final ApiCallable<GetSinkRequest, LogSink> getSinkCallable() {
285355
return getSinkCallable;
@@ -300,12 +370,13 @@ public final ApiCallable<GetSinkRequest, LogSink> getSinkCallable() {
300370
* The new sink must be provided in the request.
301371
* @param sink The new sink, which must not have an identifier that already
302372
* exists.
303-
* @throws ApiException if the remote call fails
373+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
304374
*/
305375
public final LogSink createSink(String projectName, LogSink sink) {
376+
PROJECT_PATH_TEMPLATE.validate(projectName);
377+
306378
CreateSinkRequest request =
307379
CreateSinkRequest.newBuilder().setProjectName(projectName).setSink(sink).build();
308-
309380
return createSink(request);
310381
}
311382

@@ -317,7 +388,7 @@ public final LogSink createSink(String projectName, LogSink sink) {
317388
* <!-- end manual edit -->
318389
*
319390
* @param request The request object containing all of the parameters for the API call.
320-
* @throws ApiException if the remote call fails
391+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
321392
*/
322393
public LogSink createSink(CreateSinkRequest request) {
323394
return createSinkCallable().call(request);
@@ -329,7 +400,6 @@ public LogSink createSink(CreateSinkRequest request) {
329400
*
330401
* <!-- manual edit -->
331402
* <!-- end manual edit -->
332-
* @throws ApiException if the remote call fails
333403
*/
334404
public final ApiCallable<CreateSinkRequest, LogSink> createSinkCallable() {
335405
return createSinkCallable;
@@ -353,12 +423,13 @@ public final ApiCallable<CreateSinkRequest, LogSink> createSinkCallable() {
353423
* @param sink The updated sink, whose name must be the same as the sink
354424
* identifier in `sinkName`. If `sinkName` does not exist, then
355425
* this method creates a new sink.
356-
* @throws ApiException if the remote call fails
426+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
357427
*/
358428
public final LogSink updateSink(String sinkName, LogSink sink) {
429+
SINK_PATH_TEMPLATE.validate(sinkName);
430+
359431
UpdateSinkRequest request =
360432
UpdateSinkRequest.newBuilder().setSinkName(sinkName).setSink(sink).build();
361-
362433
return updateSink(request);
363434
}
364435

@@ -370,7 +441,7 @@ public final LogSink updateSink(String sinkName, LogSink sink) {
370441
* <!-- end manual edit -->
371442
*
372443
* @param request The request object containing all of the parameters for the API call.
373-
* @throws ApiException if the remote call fails
444+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
374445
*/
375446
public LogSink updateSink(UpdateSinkRequest request) {
376447
return updateSinkCallable().call(request);
@@ -382,7 +453,6 @@ public LogSink updateSink(UpdateSinkRequest request) {
382453
*
383454
* <!-- manual edit -->
384455
* <!-- end manual edit -->
385-
* @throws ApiException if the remote call fails
386456
*/
387457
public final ApiCallable<UpdateSinkRequest, LogSink> updateSinkCallable() {
388458
return updateSinkCallable;
@@ -399,11 +469,11 @@ public final ApiCallable<UpdateSinkRequest, LogSink> updateSinkCallable() {
399469
*
400470
* @param sinkName The resource name of the sink to delete.
401471
* Example: `"projects/my-project-id/sinks/my-sink-id"`.
402-
* @throws ApiException if the remote call fails
472+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
403473
*/
404474
public final void deleteSink(String sinkName) {
475+
SINK_PATH_TEMPLATE.validate(sinkName);
405476
DeleteSinkRequest request = DeleteSinkRequest.newBuilder().setSinkName(sinkName).build();
406-
407477
deleteSink(request);
408478
}
409479

@@ -415,7 +485,7 @@ public final void deleteSink(String sinkName) {
415485
* <!-- end manual edit -->
416486
*
417487
* @param request The request object containing all of the parameters for the API call.
418-
* @throws ApiException if the remote call fails
488+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
419489
*/
420490
private void deleteSink(DeleteSinkRequest request) {
421491
deleteSinkCallable().call(request);
@@ -427,7 +497,6 @@ private void deleteSink(DeleteSinkRequest request) {
427497
*
428498
* <!-- manual edit -->
429499
* <!-- end manual edit -->
430-
* @throws ApiException if the remote call fails
431500
*/
432501
public final ApiCallable<DeleteSinkRequest, Empty> deleteSinkCallable() {
433502
return deleteSinkCallable;

0 commit comments

Comments
 (0)