GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [samplecode] Implement rpc default method sample code by summer-ji-eng · Pull Request #594 · googleapis/sdk-platform-java

This repository was archived by the owner on Oct 29, 2026. It is now read-only.

Conversation

@summer-ji-eng

@summer-ji-eng summer-ji-eng commented Dec 10, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

RPC default method has 3 types sample code for:

  1. paged (gapic-generator sample code)
  * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
  *   ListShelvesRequest request =
  *       ListShelvesRequest.newBuilder()
  *           .setPageSize(883849137)
  *           .setPageToken("pageToken873572522")
  *           .build();
  *   for (Shelf element : libraryServiceClient.listShelves(request).iterateAll()) {
  *     // doThingsWith(element);
  *   }
  * }
  1. lro (gapic-generator sample code)
   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
   *   UpgradeInstanceRequest request =
   *       UpgradeInstanceRequest.newBuilder()
   *           .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString())
   *           .setRedisVersion("redisVersion-1972584739")
   *           .build();
   *   Instance response = cloudRedisClient.upgradeInstanceAsync(request).get();
   * }

or if method return void, the last line is cloudRedisClient.upgradeInstanceAsync(request).get();
3. pure unary (gapic-generator sample code)

   * try (MetricsClient metricsClient = MetricsClient.create()) {
   *   CreateLogMetricRequest request =
   *       CreateLogMetricRequest.newBuilder()
   *           .setParent(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
   *           .setMetric(LogMetric.newBuilder().build())
   *           .build();
   *   LogMetric response = metricsClient.createLogMetric(request);
   * }

Or if the method return void, the last line is metricsClient.createLogMetric(request);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@summer-ji-eng
Implement rpc default method sample code
ef07c63
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Dec 10, 2020
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Dec 10, 2020
summer-ji-eng
summer-ji-eng commented Dec 10, 2020
View reviewed changes
Comment thread src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@summer-ji-eng
Add unit test
25d6723
@summer-ji-eng
summer-ji-eng marked this pull request as ready for review December 13, 2020 08:02
@summer-ji-eng
summer-ji-eng requested a review from xiaozhenliu-gg5 as a code owner December 13, 2020 08:02
@summer-ji-eng
summer-ji-eng requested a review from miraleung December 13, 2020 08:03
@summer-ji-eng summer-ji-eng mentioned this pull request Dec 14, 2020
[draft][5/5]Implement default unary rpc method's sample code #517
Closed
miraleung
miraleung suggested changes Dec 15, 2020
View reviewed changes
Comment thread src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java Outdated
.build();
bodyStatements.add(loopIteratorStatement);
} else {
TypeNode methodOutputType =

@miraleung miraleung Dec 15, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this could probably reuse composeUnaryRpcMethodSampleCode and composeUnaryLroRpcMethodSampleCode.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@summer-ji-eng summer-ji-eng Dec 15, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @miraleung, thanks for the valuable suggestion.

Make composeUnaryRpcMethodSampleCode, composeUnaryPagedRpcMethodSampleCode, and composeUnaryLroRpcMethodSampleCode re-usable for default method.

Update the unit test based on the new approach.

Open to discuss a better approach to re-use the utility methods. 🙏

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@summer-ji-eng
summer-ji-eng force-pushed the default_unary_samplecode_1 branch from abc6879 to 25d6723 Compare December 15, 2020 05:38
@summer-ji-eng
refactor to reuse private functions
535f2ae
@summer-ji-eng
summer-ji-eng requested a review from miraleung December 15, 2020 20:31
miraleung
miraleung suggested changes Dec 15, 2020
View reviewed changes
Comment thread src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@summer-ji-eng
refactor body statements
12d5df2
@summer-ji-eng
summer-ji-eng requested a review from miraleung December 16, 2020 07:01
miraleung
miraleung approved these changes Dec 16, 2020
View reviewed changes

@miraleung miraleung left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach is much better, thanks! LGTM with last comments addressed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java
bodyStatements.addAll(
composeUnaryLroRpcMethodSampleCodeBodyStatements(
method, clientVarExpr, rpcMethodArgVarExprs, bodyExprs));
} else {

@miraleung miraleung Dec 16, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need any extra handling for streaming methods?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@summer-ji-eng summer-ji-eng Dec 17, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to handle streaming methods here in composeRpcMethodHeaderSampleCode.
The caller is createMethodVariants only pass in the non-stream method in:

if (method.stream().equals(Stream.NONE)) {
        javaMethods.addAll(
            createMethodVariants(method, clientName, messageTypes, types, resourceNames));
        javaMethods.add(
            createMethodDefaultMethod(method, clientName, messageTypes, types, resourceNames));
      }

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@summer-ji-eng
fix nit with body exprs position
3fcc3e0
@summer-ji-eng

summer-ji-eng commented Dec 17, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing @miraleung. Merge into samplecode-master now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@summer-ji-eng
summer-ji-eng merged commit 087bfb1 into samplecode-master Dec 17, 2020
@summer-ji-eng
summer-ji-eng deleted the default_unary_samplecode_1 branch December 17, 2020 04:49
summer-ji-eng added a commit that referenced this pull request Dec 22, 2020
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
38644a3
summer-ji-eng added a commit that referenced this pull request Dec 22, 2020
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
d9fb13b
summer-ji-eng added a commit that referenced this pull request Dec 29, 2020
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
3c11e45
summer-ji-eng added a commit that referenced this pull request Dec 29, 2020
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
8043183
@summer-ji-eng
summer-ji-eng restored the default_unary_samplecode_1 branch December 30, 2020 07:48
summer-ji-eng added a commit that referenced this pull request Dec 31, 2020
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
f4645fe
summer-ji-eng added a commit that referenced this pull request Dec 31, 2020
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
1c483f7
summer-ji-eng added a commit that referenced this pull request Dec 31, 2020
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
1b81037
summer-ji-eng added a commit that referenced this pull request Jan 5, 2021
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
e6dae3f
summer-ji-eng added a commit that referenced this pull request Jan 5, 2021
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
36a900a
summer-ji-eng added a commit that referenced this pull request Jan 5, 2021
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
746ecd2
summer-ji-eng added a commit that referenced this pull request Jan 15, 2021
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
717ae88
summer-ji-eng added a commit that referenced this pull request Jan 15, 2021
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
5342b40
summer-ji-eng added a commit that referenced this pull request Jan 15, 2021
@summer-ji-eng
[samplecode] Implement rpc default method sample code (#594)
1fbc63c
@summer-ji-eng
summer-ji-eng deleted the default_unary_samplecode_1 branch January 19, 2021 23:18
suztomo pushed a commit that referenced this pull request Mar 21, 2023
@renovate-bot
build(deps): update dependency org.codehaus.mojo:animal-sniffer-annot…
40e168e
…ations to v1.21 (#594)
suztomo pushed a commit that referenced this pull request Mar 21, 2023
@renovate-bot
deps: update dependency com.google.api:gax-bom to v2.6.0 (#594)
123ebcc
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.api:gax-bom](https://togithub.com/googleapis/gax-java) | `2.5.0` -> `2.6.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.6.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.6.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.6.0/compatibility-slim/2.5.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.6.0/confidence-slim/2.5.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/gax-java</summary>

### [`v2.6.0`](https://togithub.com/googleapis/gax-java/blob/master/CHANGELOG.md#&#8203;260-httpswwwgithubcomgoogleapisgax-javacomparev253v260-2021-10-15)

[Compare Source](https://togithub.com/googleapis/gax-java/compare/v2.5.0...v2.6.0)

##### Features

-   remove deprecated Generated annotation ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))

##### Bug Fixes

-   Fix com.google.rpc.Code to StatusCode.Code conversion logic ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))

##### Dependencies

-   update api-common to 2.0.5 ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))
-   update auto-value to 1.8.2 ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))
-   update com_google_protobuf to 3.18.1 ([#&#8203;1519](https://www.togithub.com/googleapis/gax-java/issues/1519)) ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))
-   update google-http-client to 1.40.1 ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))
-   update grpc to 1.41.0 ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))
-   update guava to v31 ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))

##### [2.5.3](https://www.github.com/googleapis/gax-java/compare/v2.5.2...v2.5.3) (2021-10-13)

##### Bug Fixes

-   Fix `com.google.rpc.Code` to `StatusCode.Code` conversion  logic ([#&#8203;1508](https://www.togithub.com/googleapis/gax-java/issues/1508)) ([61b1617](https://www.github.com/googleapis/gax-java/commit/61b161799faf292be1394111381f8a35e757b85a))

##### [2.5.2](https://www.github.com/googleapis/gax-java/compare/v2.5.1...v2.5.2) (2021-10-13)

##### Dependencies

-   release multiple artifacts at once ([#&#8203;1506](https://www.togithub.com/googleapis/gax-java/issues/1506)) ([8c022f6](https://www.github.com/googleapis/gax-java/commit/8c022f69f7878280e00f200f65a931ff0f8cfe45))

##### [2.5.1](https://www.github.com/googleapis/gax-java/compare/v2.5.0...v2.5.1) (2021-10-08)

##### Dependencies

-   fix release pipeline ([#&#8203;1500](https://www.togithub.com/googleapis/gax-java/issues/1500)) ([f8ae03b](https://www.github.com/googleapis/gax-java/commit/f8ae03bbf0389d5fd943d214c1058ee012be757b))

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-core).
suztomo pushed a commit that referenced this pull request Mar 21, 2023
@release-please
chore: release 2.1.8 (#582)
a311e92
🤖 I have created a release \*beep\* \*boop\*
---
### [2.1.8](https://www.github.com/googleapis/java-core/compare/v2.1.7...v2.1.8) (2021-10-15)


### Dependencies

* update dependency com.google.api-client:google-api-client-bom to v1.32.2 ([#593](https://www.github.com/googleapis/java-core/issues/593)) ([5471efd](https://www.github.com/googleapis/java-core/commit/5471efda5271fc21df2ace74d4aa59dfff610a53))
* update dependency com.google.api:api-common to v2.0.4 ([#585](https://www.github.com/googleapis/java-core/issues/585)) ([3063023](https://www.github.com/googleapis/java-core/commit/3063023e34e10deef2a65d82a39a36d03296f145))
* update dependency com.google.api:api-common to v2.0.5 ([#589](https://www.github.com/googleapis/java-core/issues/589)) ([354ff97](https://www.github.com/googleapis/java-core/commit/354ff97f777f7b151744fc542bb43cb9caa3ba4a))
* update dependency com.google.api:gax-bom to v2.6.0 ([#594](https://www.github.com/googleapis/java-core/issues/594)) ([123ebcc](https://www.github.com/googleapis/java-core/commit/123ebcc927585ff42e4b6cdbde26deb527b45621))
* update dependency com.google.api.grpc:proto-google-common-protos to v2.6.0 ([#578](https://www.github.com/googleapis/java-core/issues/578)) ([cfd5d51](https://www.github.com/googleapis/java-core/commit/cfd5d51c5e82690a2eac536fbd75e3c789c52e36))
* update dependency com.google.api.grpc:proto-google-iam-v1 to v1.1.3 ([#574](https://www.github.com/googleapis/java-core/issues/574)) ([92c2a59](https://www.github.com/googleapis/java-core/commit/92c2a599d916d0103ad152c380c1f4c1a8bcfd81))
* update dependency com.google.api.grpc:proto-google-iam-v1 to v1.1.4 ([#584](https://www.github.com/googleapis/java-core/issues/584)) ([6984a40](https://www.github.com/googleapis/java-core/commit/6984a407a1b8f3466d0d695465f988d9138c95f6))
* update dependency com.google.api.grpc:proto-google-iam-v1 to v1.1.5 ([#587](https://www.github.com/googleapis/java-core/issues/587)) ([30e3d99](https://www.github.com/googleapis/java-core/commit/30e3d99f893da41af9ae3ac22356bed2bddc1fa8))
* update dependency com.google.api.grpc:proto-google-iam-v1 to v1.1.6 ([#590](https://www.github.com/googleapis/java-core/issues/590)) ([e7446c8](https://www.github.com/googleapis/java-core/commit/e7446c8475ee339abcf3f77bb993689501235014))
* update dependency com.google.auth:google-auth-library-bom to v1.2.0 ([#581](https://www.github.com/googleapis/java-core/issues/581)) ([3390141](https://www.github.com/googleapis/java-core/commit/3390141b28f90690956222c0d6661d502f91c706))
* update dependency com.google.auth:google-auth-library-bom to v1.2.1 ([#591](https://www.github.com/googleapis/java-core/issues/591)) ([7c4a658](https://www.github.com/googleapis/java-core/commit/7c4a6580faed1201d7e136d40f71a8805235e8ba))
* update dependency com.google.guava:guava-bom to v31 ([#577](https://www.github.com/googleapis/java-core/issues/577)) ([a72fd39](https://www.github.com/googleapis/java-core/commit/a72fd395d4eded744fb110dd01bac12906d7c564))
* update dependency com.google.http-client:google-http-client-bom to v1.40.1 ([#588](https://www.github.com/googleapis/java-core/issues/588)) ([a9402ff](https://www.github.com/googleapis/java-core/commit/a9402ff2d38eb220988550c04f2c27975ca9c6b9))
* update dependency com.google.protobuf:protobuf-bom to v3.18.1 ([#583](https://www.github.com/googleapis/java-core/issues/583)) ([6ccb52f](https://www.github.com/googleapis/java-core/commit/6ccb52f7386abbc2232178678523befc7e4b7e16))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@xiaozhenliu-gg5 xiaozhenliu-gg5 Awaiting requested review from xiaozhenliu-gg5
1 more reviewer
@miraleung miraleung miraleung approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@summer-ji-eng @miraleung
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.