Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: generate sample code in the Java microgenerator #498

Merged
merged 1 commit into from Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Large diffs are not rendered by default.

Expand Up @@ -52,6 +52,18 @@
* <p>This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods. Sample code to get started:
*
* <pre>{@code
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
* CommitCursorRequest request =
* CommitCursorRequest.newBuilder()
* .setSubscription("subscription341203229")
* .setPartition(-1799810326)
* .setCursor(Cursor.newBuilder().build())
* .build();
* CommitCursorResponse response = cursorServiceClient.commitCursor(request);
* }
* }</pre>
*
* <p>Note: close() needs to be called on the CursorServiceClient object to clean up resources such
* as threads. In the example above, try-with-resources is used, which automatically calls close().
*
Expand Down Expand Up @@ -156,6 +168,18 @@ public CursorServiceStub getStub() {
* Establishes a stream with the server for managing committed cursors.
*
* <p>Sample code:
*
* <pre>{@code
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
* BidiStream<StreamingCommitCursorRequest, StreamingCommitCursorResponse> bidiStream =
* cursorServiceClient.streamingCommitCursorCallable().call();
* StreamingCommitCursorRequest request = StreamingCommitCursorRequest.newBuilder().build();
* bidiStream.send(request);
* for (StreamingCommitCursorResponse response : bidiStream) {
* // Do something when a response is received.
* }
* }
* }</pre>
*/
public final BidiStreamingCallable<StreamingCommitCursorRequest, StreamingCommitCursorResponse>
streamingCommitCursorCallable() {
Expand All @@ -166,6 +190,20 @@ public CursorServiceStub getStub() {
/**
* Updates the committed cursor.
*
* <p>Sample code:
*
* <pre>{@code
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
* CommitCursorRequest request =
* CommitCursorRequest.newBuilder()
* .setSubscription("subscription341203229")
* .setPartition(-1799810326)
* .setCursor(Cursor.newBuilder().build())
* .build();
* CommitCursorResponse response = cursorServiceClient.commitCursor(request);
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
Expand All @@ -178,6 +216,21 @@ public final CommitCursorResponse commitCursor(CommitCursorRequest request) {
* Updates the committed cursor.
*
* <p>Sample code:
*
* <pre>{@code
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
* CommitCursorRequest request =
* CommitCursorRequest.newBuilder()
* .setSubscription("subscription341203229")
* .setPartition(-1799810326)
* .setCursor(Cursor.newBuilder().build())
* .build();
* ApiFuture<CommitCursorResponse> future =
* cursorServiceClient.commitCursorCallable().futureCall(request);
* // Do something.
* CommitCursorResponse response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<CommitCursorRequest, CommitCursorResponse> commitCursorCallable() {
return stub.commitCursorCallable();
Expand All @@ -187,6 +240,18 @@ public final UnaryCallable<CommitCursorRequest, CommitCursorResponse> commitCurs
/**
* Returns all committed cursor information for a subscription.
*
* <p>Sample code:
*
* <pre>{@code
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
* SubscriptionName parent = SubscriptionName.of("[PROJECT]", "[LOCATION]", "[SUBSCRIPTION]");
* for (PartitionCursor element :
* cursorServiceClient.listPartitionCursors(parent).iterateAll()) {
* // doThingsWith(element);
* }
* }
* }</pre>
*
* @param parent Required. The subscription for which to retrieve cursors. Structured like
* `projects/{project_number}/locations/{location}/subscriptions/{subscription_id}`.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
Expand All @@ -203,6 +268,18 @@ public final ListPartitionCursorsPagedResponse listPartitionCursors(Subscription
/**
* Returns all committed cursor information for a subscription.
*
* <p>Sample code:
*
* <pre>{@code
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
* String parent = SubscriptionName.of("[PROJECT]", "[LOCATION]", "[SUBSCRIPTION]").toString();
* for (PartitionCursor element :
* cursorServiceClient.listPartitionCursors(parent).iterateAll()) {
* // doThingsWith(element);
* }
* }
* }</pre>
*
* @param parent Required. The subscription for which to retrieve cursors. Structured like
* `projects/{project_number}/locations/{location}/subscriptions/{subscription_id}`.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
Expand All @@ -217,6 +294,24 @@ public final ListPartitionCursorsPagedResponse listPartitionCursors(String paren
/**
* Returns all committed cursor information for a subscription.
*
* <p>Sample code:
*
* <pre>{@code
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
* ListPartitionCursorsRequest request =
* ListPartitionCursorsRequest.newBuilder()
* .setParent(
* SubscriptionName.of("[PROJECT]", "[LOCATION]", "[SUBSCRIPTION]").toString())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* for (PartitionCursor element :
* cursorServiceClient.listPartitionCursors(request).iterateAll()) {
* // doThingsWith(element);
* }
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
Expand All @@ -230,6 +325,24 @@ public final ListPartitionCursorsPagedResponse listPartitionCursors(
* Returns all committed cursor information for a subscription.
*
* <p>Sample code:
*
* <pre>{@code
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
* ListPartitionCursorsRequest request =
* ListPartitionCursorsRequest.newBuilder()
* .setParent(
* SubscriptionName.of("[PROJECT]", "[LOCATION]", "[SUBSCRIPTION]").toString())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* ApiFuture<PartitionCursor> future =
* cursorServiceClient.listPartitionCursorsPagedCallable().futureCall(request);
* // Do something.
* for (PartitionCursor element : future.get().iterateAll()) {
* // doThingsWith(element);
* }
* }
* }</pre>
*/
public final UnaryCallable<ListPartitionCursorsRequest, ListPartitionCursorsPagedResponse>
listPartitionCursorsPagedCallable() {
Expand All @@ -241,6 +354,24 @@ public final ListPartitionCursorsPagedResponse listPartitionCursors(
* Returns all committed cursor information for a subscription.
*
* <p>Sample code:
*
* <pre>{@code
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
* while (true) {
* ListPartitionCursorsResponse response =
* cursorServiceClient.listPartitionCursorsCallable().call(request);
* for (PartitionCursor element : response.getResponsesList()) {
* // doThingsWith(element);
* }
* String nextPageToken = response.getNextPageToken();
* if (!Strings.isNullOrEmpty(nextPageToken)) {
* request = request.toBuilder().setPageToken(nextPageToken).build();
* } else {
* break;
* }
* }
* }
* }</pre>
*/
public final UnaryCallable<ListPartitionCursorsRequest, ListPartitionCursorsResponse>
listPartitionCursorsCallable() {
Expand Down
Expand Up @@ -35,6 +35,19 @@
* <p>This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods. Sample code to get started:
*
* <pre>{@code
* try (PartitionAssignmentServiceClient partitionAssignmentServiceClient =
* PartitionAssignmentServiceClient.create()) {
* BidiStream<PartitionAssignmentRequest, PartitionAssignment> bidiStream =
* partitionAssignmentServiceClient.assignPartitionsCallable().call();
* PartitionAssignmentRequest request = PartitionAssignmentRequest.newBuilder().build();
* bidiStream.send(request);
* for (PartitionAssignment response : bidiStream) {
* // Do something when a response is received.
* }
* }
* }</pre>
*
* <p>Note: close() needs to be called on the PartitionAssignmentServiceClient object to clean up
* resources such as threads. In the example above, try-with-resources is used, which automatically
* calls close().
Expand Down Expand Up @@ -149,6 +162,19 @@ public PartitionAssignmentServiceStub getStub() {
* reflect the new assignment.
*
* <p>Sample code:
*
* <pre>{@code
* try (PartitionAssignmentServiceClient partitionAssignmentServiceClient =
* PartitionAssignmentServiceClient.create()) {
* BidiStream<PartitionAssignmentRequest, PartitionAssignment> bidiStream =
* partitionAssignmentServiceClient.assignPartitionsCallable().call();
* PartitionAssignmentRequest request = PartitionAssignmentRequest.newBuilder().build();
* bidiStream.send(request);
* for (PartitionAssignment response : bidiStream) {
* // Do something when a response is received.
* }
* }
* }</pre>
*/
public final BidiStreamingCallable<PartitionAssignmentRequest, PartitionAssignment>
assignPartitionsCallable() {
Expand Down
Expand Up @@ -37,6 +37,18 @@
* <p>This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods. Sample code to get started:
*
* <pre>{@code
* try (PublisherServiceClient publisherServiceClient = PublisherServiceClient.create()) {
* BidiStream<PublishRequest, PublishResponse> bidiStream =
* publisherServiceClient.publishCallable().call();
* PublishRequest request = PublishRequest.newBuilder().build();
* bidiStream.send(request);
* for (PublishResponse response : bidiStream) {
* // Do something when a response is received.
* }
* }
* }</pre>
*
* <p>Note: close() needs to be called on the PublisherServiceClient object to clean up resources
* such as threads. In the example above, try-with-resources is used, which automatically calls
* close().
Expand Down Expand Up @@ -149,6 +161,18 @@ public PublisherServiceStub getStub() {
* stream.
*
* <p>Sample code:
*
* <pre>{@code
* try (PublisherServiceClient publisherServiceClient = PublisherServiceClient.create()) {
* BidiStream<PublishRequest, PublishResponse> bidiStream =
* publisherServiceClient.publishCallable().call();
* PublishRequest request = PublishRequest.newBuilder().build();
* bidiStream.send(request);
* for (PublishResponse response : bidiStream) {
* // Do something when a response is received.
* }
* }
* }</pre>
*/
public final BidiStreamingCallable<PublishRequest, PublishResponse> publishCallable() {
return stub.publishCallable();
Expand Down
Expand Up @@ -35,6 +35,18 @@
* <p>This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods. Sample code to get started:
*
* <pre>{@code
* try (SubscriberServiceClient subscriberServiceClient = SubscriberServiceClient.create()) {
* BidiStream<SubscribeRequest, SubscribeResponse> bidiStream =
* subscriberServiceClient.subscribeCallable().call();
* SubscribeRequest request = SubscribeRequest.newBuilder().build();
* bidiStream.send(request);
* for (SubscribeResponse response : bidiStream) {
* // Do something when a response is received.
* }
* }
* }</pre>
*
* <p>Note: close() needs to be called on the SubscriberServiceClient object to clean up resources
* such as threads. In the example above, try-with-resources is used, which automatically calls
* close().
Expand Down Expand Up @@ -142,6 +154,18 @@ public SubscriberServiceStub getStub() {
* Establishes a stream with the server for receiving messages.
*
* <p>Sample code:
*
* <pre>{@code
* try (SubscriberServiceClient subscriberServiceClient = SubscriberServiceClient.create()) {
* BidiStream<SubscribeRequest, SubscribeResponse> bidiStream =
* subscriberServiceClient.subscribeCallable().call();
* SubscribeRequest request = SubscribeRequest.newBuilder().build();
* bidiStream.send(request);
* for (SubscribeResponse response : bidiStream) {
* // Do something when a response is received.
* }
* }
* }</pre>
*/
public final BidiStreamingCallable<SubscribeRequest, SubscribeResponse> subscribeCallable() {
return stub.subscribeCallable();
Expand Down