Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 70f3b23

Browse filesBrowse files
committed
[samplecode][1/3]Implement Pure Unary RPC sample code (#573)
1 parent da6d2eb commit 70f3b23
Copy full SHA for 70f3b23

File tree

Expand file treeCollapse file tree

2 files changed

+19
-96
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-96
lines changed

‎src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java

Copy file name to clipboardExpand all lines: src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,12 @@ private static List<MethodDefinition> createMethodVariants(
614614
return javaMethods;
615615
}
616616

617-
private static MethodDefinition createMethodDefaultMethod(Method method, TypeStore typeStore) {
617+
private static MethodDefinition createMethodDefaultMethod(
618+
Method method,
619+
String clientName,
620+
Map<String, Message> messageTypes,
621+
TypeStore typeStore,
622+
Map<String, ResourceName> resourceNames) {
618623
String methodName = JavaStyle.toLowerCamelCase(method.name());
619624
TypeNode methodInputType = method.inputType();
620625
TypeNode methodOutputType =
@@ -647,6 +652,11 @@ private static MethodDefinition createMethodDefaultMethod(Method method, TypeSto
647652
callableMethodName = String.format(OPERATION_CALLABLE_NAME_PATTERN, methodName);
648653
}
649654

655+
Optional<String> defaultMethodSampleCode =
656+
Optional.of(
657+
ServiceClientSampleCodeComposer.composeRpcDefaultMethodHeaderSampleCode(
658+
method, typeStore.get(clientName), resourceNames, messageTypes));
659+
650660
MethodInvocationExpr callableMethodExpr =
651661
MethodInvocationExpr.builder().setMethodName(callableMethodName).build();
652662
callableMethodExpr =
@@ -659,7 +669,8 @@ private static MethodDefinition createMethodDefaultMethod(Method method, TypeSto
659669
MethodDefinition.Builder methodBuilder =
660670
MethodDefinition.builder()
661671
.setHeaderCommentStatements(
662-
ServiceClientCommentComposer.createRpcMethodHeaderComment(method))
672+
ServiceClientCommentComposer.createRpcMethodHeaderComment(
673+
method, defaultMethodSampleCode))
663674
.setScope(ScopeNode.PUBLIC)
664675
.setIsFinal(true)
665676
.setName(String.format(method.hasLro() ? "%sAsync" : "%s", methodName))

‎test/integration/goldens/logging/MetricsClient.java

Copy file name to clipboardExpand all lines: test/integration/goldens/logging/MetricsClient.java
+6-94Lines changed: 6 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,6 @@ public MetricsServiceV2Stub getStub() {
152152
/**
153153
* Lists logs-based metrics.
154154
*
155-
* <p>Sample code:
156-
*
157-
* <pre>{@code
158-
* try (MetricsClient metricsClient = MetricsClient.create()) {
159-
* ProjectName parent = ProjectName.of("[PROJECT]");
160-
* for (LogMetric element : metricsClient.listLogMetrics(parent).iterateAll()) {
161-
* // doThingsWith(element);
162-
* }
163-
* }
164-
* }</pre>
165-
*
166155
* @param parent Required. The name of the project containing the metrics:
167156
* <p>"projects/[PROJECT_ID]"
168157
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
@@ -179,17 +168,6 @@ public final ListLogMetricsPagedResponse listLogMetrics(ProjectName parent) {
179168
/**
180169
* Lists logs-based metrics.
181170
*
182-
* <p>Sample code:
183-
*
184-
* <pre>{@code
185-
* try (MetricsClient metricsClient = MetricsClient.create()) {
186-
* String parent = ProjectName.of("[PROJECT]").toString();
187-
* for (LogMetric element : metricsClient.listLogMetrics(parent).iterateAll()) {
188-
* // doThingsWith(element);
189-
* }
190-
* }
191-
* }</pre>
192-
*
193171
* @param parent Required. The name of the project containing the metrics:
194172
* <p>"projects/[PROJECT_ID]"
195173
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
@@ -203,22 +181,6 @@ public final ListLogMetricsPagedResponse listLogMetrics(String parent) {
203181
/**
204182
* Lists logs-based metrics.
205183
*
206-
* <p>Sample code:
207-
*
208-
* <pre>{@code
209-
* try (MetricsClient metricsClient = MetricsClient.create()) {
210-
* ListLogMetricsRequest request =
211-
* ListLogMetricsRequest.newBuilder()
212-
* .setParent(ProjectName.of("[PROJECT]").toString())
213-
* .setPageToken("pageToken873572522")
214-
* .setPageSize(883849137)
215-
* .build();
216-
* for (LogMetric element : metricsClient.listLogMetrics(request).iterateAll()) {
217-
* // doThingsWith(element);
218-
* }
219-
* }
220-
* }</pre>
221-
*
222184
* @param request The request object containing all of the parameters for the API call.
223185
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
224186
*/
@@ -261,7 +223,7 @@ public final ListLogMetricsPagedResponse listLogMetrics(ListLogMetricsRequest re
261223
* }
262224
* }</pre>
263225
*
264-
* @param metricName Required. The resource name of the desired metric:
226+
* @param metric_name Required. The resource name of the desired metric:
265227
* <p>"projects/[PROJECT_ID]/metrics/[METRIC_ID]"
266228
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
267229
*/
@@ -286,7 +248,7 @@ public final LogMetric getLogMetric(LogMetricName metricName) {
286248
* }
287249
* }</pre>
288250
*
289-
* @param metricName Required. The resource name of the desired metric:
251+
* @param metric_name Required. The resource name of the desired metric:
290252
* <p>"projects/[PROJECT_ID]/metrics/[METRIC_ID]"
291253
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
292254
*/
@@ -300,18 +262,6 @@ public final LogMetric getLogMetric(String metricName) {
300262
/**
301263
* Gets a logs-based metric.
302264
*
303-
* <p>Sample code:
304-
*
305-
* <pre>{@code
306-
* try (MetricsClient metricsClient = MetricsClient.create()) {
307-
* GetLogMetricRequest request =
308-
* GetLogMetricRequest.newBuilder()
309-
* .setMetricName(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
310-
* .build();
311-
* LogMetric response = metricsClient.getLogMetric(request);
312-
* }
313-
* }</pre>
314-
*
315265
* @param request The request object containing all of the parameters for the API call.
316266
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
317267
*/
@@ -390,19 +340,6 @@ public final LogMetric createLogMetric(String parent, LogMetric metric) {
390340
/**
391341
* Creates a logs-based metric.
392342
*
393-
* <p>Sample code:
394-
*
395-
* <pre>{@code
396-
* try (MetricsClient metricsClient = MetricsClient.create()) {
397-
* CreateLogMetricRequest request =
398-
* CreateLogMetricRequest.newBuilder()
399-
* .setParent(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
400-
* .setMetric(LogMetric.newBuilder().build())
401-
* .build();
402-
* LogMetric response = metricsClient.createLogMetric(request);
403-
* }
404-
* }</pre>
405-
*
406343
* @param request The request object containing all of the parameters for the API call.
407344
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
408345
*/
@@ -434,7 +371,7 @@ public final UnaryCallable<CreateLogMetricRequest, LogMetric> createLogMetricCal
434371
* }
435372
* }</pre>
436373
*
437-
* @param metricName Required. The resource name of the metric to update:
374+
* @param metric_name Required. The resource name of the metric to update:
438375
* <p>"projects/[PROJECT_ID]/metrics/[METRIC_ID]"
439376
* <p>The updated metric must be provided in the request and it's `name` field must be the
440377
* same as `[METRIC_ID]` If the metric does not exist in `[PROJECT_ID]`, then a new metric is
@@ -465,7 +402,7 @@ public final LogMetric updateLogMetric(LogMetricName metricName, LogMetric metri
465402
* }
466403
* }</pre>
467404
*
468-
* @param metricName Required. The resource name of the metric to update:
405+
* @param metric_name Required. The resource name of the metric to update:
469406
* <p>"projects/[PROJECT_ID]/metrics/[METRIC_ID]"
470407
* <p>The updated metric must be provided in the request and it's `name` field must be the
471408
* same as `[METRIC_ID]` If the metric does not exist in `[PROJECT_ID]`, then a new metric is
@@ -483,19 +420,6 @@ public final LogMetric updateLogMetric(String metricName, LogMetric metric) {
483420
/**
484421
* Creates or updates a logs-based metric.
485422
*
486-
* <p>Sample code:
487-
*
488-
* <pre>{@code
489-
* try (MetricsClient metricsClient = MetricsClient.create()) {
490-
* UpdateLogMetricRequest request =
491-
* UpdateLogMetricRequest.newBuilder()
492-
* .setMetricName(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
493-
* .setMetric(LogMetric.newBuilder().build())
494-
* .build();
495-
* LogMetric response = metricsClient.updateLogMetric(request);
496-
* }
497-
* }</pre>
498-
*
499423
* @param request The request object containing all of the parameters for the API call.
500424
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
501425
*/
@@ -526,7 +450,7 @@ public final UnaryCallable<UpdateLogMetricRequest, LogMetric> updateLogMetricCal
526450
* }
527451
* }</pre>
528452
*
529-
* @param metricName Required. The resource name of the metric to delete:
453+
* @param metric_name Required. The resource name of the metric to delete:
530454
* <p>"projects/[PROJECT_ID]/metrics/[METRIC_ID]"
531455
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
532456
*/
@@ -551,7 +475,7 @@ public final void deleteLogMetric(LogMetricName metricName) {
551475
* }
552476
* }</pre>
553477
*
554-
* @param metricName Required. The resource name of the metric to delete:
478+
* @param metric_name Required. The resource name of the metric to delete:
555479
* <p>"projects/[PROJECT_ID]/metrics/[METRIC_ID]"
556480
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
557481
*/
@@ -565,18 +489,6 @@ public final void deleteLogMetric(String metricName) {
565489
/**
566490
* Deletes a logs-based metric.
567491
*
568-
* <p>Sample code:
569-
*
570-
* <pre>{@code
571-
* try (MetricsClient metricsClient = MetricsClient.create()) {
572-
* DeleteLogMetricRequest request =
573-
* DeleteLogMetricRequest.newBuilder()
574-
* .setMetricName(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
575-
* .build();
576-
* metricsClient.deleteLogMetric(request);
577-
* }
578-
* }</pre>
579-
*
580492
* @param request The request object containing all of the parameters for the API call.
581493
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
582494
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.