Skip to content

Commit b42165e

Browse files
docs: generate sample code in the Java microgenerator (#498)
This PR was generated using Autosynth. 🌈 Synth log will be available here: https://source.cloud.google.com/results/invocations/128acacc-8b90-47cc-a3cd-e13068edfb12/targets - [ ] To automatically regenerate this PR, check this box. PiperOrigin-RevId: 356341083 Source-Link: googleapis/googleapis@8d8c008
1 parent 36ec74f commit b42165e

File tree

8 files changed

+963
-2
lines changed

8 files changed

+963
-2
lines changed

google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/v1/AdminServiceClient.java

Lines changed: 614 additions & 0 deletions
Large diffs are not rendered by default.

google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/v1/CursorServiceClient.java

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@
5252
* <p>This class provides the ability to make remote calls to the backing service through method
5353
* calls that map to API methods. Sample code to get started:
5454
*
55+
* <pre>{@code
56+
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
57+
* CommitCursorRequest request =
58+
* CommitCursorRequest.newBuilder()
59+
* .setSubscription("subscription341203229")
60+
* .setPartition(-1799810326)
61+
* .setCursor(Cursor.newBuilder().build())
62+
* .build();
63+
* CommitCursorResponse response = cursorServiceClient.commitCursor(request);
64+
* }
65+
* }</pre>
66+
*
5567
* <p>Note: close() needs to be called on the CursorServiceClient object to clean up resources such
5668
* as threads. In the example above, try-with-resources is used, which automatically calls close().
5769
*
@@ -156,6 +168,18 @@ public CursorServiceStub getStub() {
156168
* Establishes a stream with the server for managing committed cursors.
157169
*
158170
* <p>Sample code:
171+
*
172+
* <pre>{@code
173+
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
174+
* BidiStream<StreamingCommitCursorRequest, StreamingCommitCursorResponse> bidiStream =
175+
* cursorServiceClient.streamingCommitCursorCallable().call();
176+
* StreamingCommitCursorRequest request = StreamingCommitCursorRequest.newBuilder().build();
177+
* bidiStream.send(request);
178+
* for (StreamingCommitCursorResponse response : bidiStream) {
179+
* // Do something when a response is received.
180+
* }
181+
* }
182+
* }</pre>
159183
*/
160184
public final BidiStreamingCallable<StreamingCommitCursorRequest, StreamingCommitCursorResponse>
161185
streamingCommitCursorCallable() {
@@ -166,6 +190,20 @@ public CursorServiceStub getStub() {
166190
/**
167191
* Updates the committed cursor.
168192
*
193+
* <p>Sample code:
194+
*
195+
* <pre>{@code
196+
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
197+
* CommitCursorRequest request =
198+
* CommitCursorRequest.newBuilder()
199+
* .setSubscription("subscription341203229")
200+
* .setPartition(-1799810326)
201+
* .setCursor(Cursor.newBuilder().build())
202+
* .build();
203+
* CommitCursorResponse response = cursorServiceClient.commitCursor(request);
204+
* }
205+
* }</pre>
206+
*
169207
* @param request The request object containing all of the parameters for the API call.
170208
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
171209
*/
@@ -178,6 +216,21 @@ public final CommitCursorResponse commitCursor(CommitCursorRequest request) {
178216
* Updates the committed cursor.
179217
*
180218
* <p>Sample code:
219+
*
220+
* <pre>{@code
221+
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
222+
* CommitCursorRequest request =
223+
* CommitCursorRequest.newBuilder()
224+
* .setSubscription("subscription341203229")
225+
* .setPartition(-1799810326)
226+
* .setCursor(Cursor.newBuilder().build())
227+
* .build();
228+
* ApiFuture<CommitCursorResponse> future =
229+
* cursorServiceClient.commitCursorCallable().futureCall(request);
230+
* // Do something.
231+
* CommitCursorResponse response = future.get();
232+
* }
233+
* }</pre>
181234
*/
182235
public final UnaryCallable<CommitCursorRequest, CommitCursorResponse> commitCursorCallable() {
183236
return stub.commitCursorCallable();
@@ -187,6 +240,18 @@ public final UnaryCallable<CommitCursorRequest, CommitCursorResponse> commitCurs
187240
/**
188241
* Returns all committed cursor information for a subscription.
189242
*
243+
* <p>Sample code:
244+
*
245+
* <pre>{@code
246+
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
247+
* SubscriptionName parent = SubscriptionName.of("[PROJECT]", "[LOCATION]", "[SUBSCRIPTION]");
248+
* for (PartitionCursor element :
249+
* cursorServiceClient.listPartitionCursors(parent).iterateAll()) {
250+
* // doThingsWith(element);
251+
* }
252+
* }
253+
* }</pre>
254+
*
190255
* @param parent Required. The subscription for which to retrieve cursors. Structured like
191256
* `projects/{project_number}/locations/{location}/subscriptions/{subscription_id}`.
192257
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
@@ -203,6 +268,18 @@ public final ListPartitionCursorsPagedResponse listPartitionCursors(Subscription
203268
/**
204269
* Returns all committed cursor information for a subscription.
205270
*
271+
* <p>Sample code:
272+
*
273+
* <pre>{@code
274+
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
275+
* String parent = SubscriptionName.of("[PROJECT]", "[LOCATION]", "[SUBSCRIPTION]").toString();
276+
* for (PartitionCursor element :
277+
* cursorServiceClient.listPartitionCursors(parent).iterateAll()) {
278+
* // doThingsWith(element);
279+
* }
280+
* }
281+
* }</pre>
282+
*
206283
* @param parent Required. The subscription for which to retrieve cursors. Structured like
207284
* `projects/{project_number}/locations/{location}/subscriptions/{subscription_id}`.
208285
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
@@ -217,6 +294,24 @@ public final ListPartitionCursorsPagedResponse listPartitionCursors(String paren
217294
/**
218295
* Returns all committed cursor information for a subscription.
219296
*
297+
* <p>Sample code:
298+
*
299+
* <pre>{@code
300+
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
301+
* ListPartitionCursorsRequest request =
302+
* ListPartitionCursorsRequest.newBuilder()
303+
* .setParent(
304+
* SubscriptionName.of("[PROJECT]", "[LOCATION]", "[SUBSCRIPTION]").toString())
305+
* .setPageSize(883849137)
306+
* .setPageToken("pageToken873572522")
307+
* .build();
308+
* for (PartitionCursor element :
309+
* cursorServiceClient.listPartitionCursors(request).iterateAll()) {
310+
* // doThingsWith(element);
311+
* }
312+
* }
313+
* }</pre>
314+
*
220315
* @param request The request object containing all of the parameters for the API call.
221316
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
222317
*/
@@ -230,6 +325,24 @@ public final ListPartitionCursorsPagedResponse listPartitionCursors(
230325
* Returns all committed cursor information for a subscription.
231326
*
232327
* <p>Sample code:
328+
*
329+
* <pre>{@code
330+
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
331+
* ListPartitionCursorsRequest request =
332+
* ListPartitionCursorsRequest.newBuilder()
333+
* .setParent(
334+
* SubscriptionName.of("[PROJECT]", "[LOCATION]", "[SUBSCRIPTION]").toString())
335+
* .setPageSize(883849137)
336+
* .setPageToken("pageToken873572522")
337+
* .build();
338+
* ApiFuture<PartitionCursor> future =
339+
* cursorServiceClient.listPartitionCursorsPagedCallable().futureCall(request);
340+
* // Do something.
341+
* for (PartitionCursor element : future.get().iterateAll()) {
342+
* // doThingsWith(element);
343+
* }
344+
* }
345+
* }</pre>
233346
*/
234347
public final UnaryCallable<ListPartitionCursorsRequest, ListPartitionCursorsPagedResponse>
235348
listPartitionCursorsPagedCallable() {
@@ -241,6 +354,24 @@ public final ListPartitionCursorsPagedResponse listPartitionCursors(
241354
* Returns all committed cursor information for a subscription.
242355
*
243356
* <p>Sample code:
357+
*
358+
* <pre>{@code
359+
* try (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
360+
* while (true) {
361+
* ListPartitionCursorsResponse response =
362+
* cursorServiceClient.listPartitionCursorsCallable().call(request);
363+
* for (PartitionCursor element : response.getResponsesList()) {
364+
* // doThingsWith(element);
365+
* }
366+
* String nextPageToken = response.getNextPageToken();
367+
* if (!Strings.isNullOrEmpty(nextPageToken)) {
368+
* request = request.toBuilder().setPageToken(nextPageToken).build();
369+
* } else {
370+
* break;
371+
* }
372+
* }
373+
* }
374+
* }</pre>
244375
*/
245376
public final UnaryCallable<ListPartitionCursorsRequest, ListPartitionCursorsResponse>
246377
listPartitionCursorsCallable() {

google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/v1/PartitionAssignmentServiceClient.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@
3535
* <p>This class provides the ability to make remote calls to the backing service through method
3636
* calls that map to API methods. Sample code to get started:
3737
*
38+
* <pre>{@code
39+
* try (PartitionAssignmentServiceClient partitionAssignmentServiceClient =
40+
* PartitionAssignmentServiceClient.create()) {
41+
* BidiStream<PartitionAssignmentRequest, PartitionAssignment> bidiStream =
42+
* partitionAssignmentServiceClient.assignPartitionsCallable().call();
43+
* PartitionAssignmentRequest request = PartitionAssignmentRequest.newBuilder().build();
44+
* bidiStream.send(request);
45+
* for (PartitionAssignment response : bidiStream) {
46+
* // Do something when a response is received.
47+
* }
48+
* }
49+
* }</pre>
50+
*
3851
* <p>Note: close() needs to be called on the PartitionAssignmentServiceClient object to clean up
3952
* resources such as threads. In the example above, try-with-resources is used, which automatically
4053
* calls close().
@@ -149,6 +162,19 @@ public PartitionAssignmentServiceStub getStub() {
149162
* reflect the new assignment.
150163
*
151164
* <p>Sample code:
165+
*
166+
* <pre>{@code
167+
* try (PartitionAssignmentServiceClient partitionAssignmentServiceClient =
168+
* PartitionAssignmentServiceClient.create()) {
169+
* BidiStream<PartitionAssignmentRequest, PartitionAssignment> bidiStream =
170+
* partitionAssignmentServiceClient.assignPartitionsCallable().call();
171+
* PartitionAssignmentRequest request = PartitionAssignmentRequest.newBuilder().build();
172+
* bidiStream.send(request);
173+
* for (PartitionAssignment response : bidiStream) {
174+
* // Do something when a response is received.
175+
* }
176+
* }
177+
* }</pre>
152178
*/
153179
public final BidiStreamingCallable<PartitionAssignmentRequest, PartitionAssignment>
154180
assignPartitionsCallable() {

google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/v1/PublisherServiceClient.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
3737
* <p>This class provides the ability to make remote calls to the backing service through method
3838
* calls that map to API methods. Sample code to get started:
3939
*
40+
* <pre>{@code
41+
* try (PublisherServiceClient publisherServiceClient = PublisherServiceClient.create()) {
42+
* BidiStream<PublishRequest, PublishResponse> bidiStream =
43+
* publisherServiceClient.publishCallable().call();
44+
* PublishRequest request = PublishRequest.newBuilder().build();
45+
* bidiStream.send(request);
46+
* for (PublishResponse response : bidiStream) {
47+
* // Do something when a response is received.
48+
* }
49+
* }
50+
* }</pre>
51+
*
4052
* <p>Note: close() needs to be called on the PublisherServiceClient object to clean up resources
4153
* such as threads. In the example above, try-with-resources is used, which automatically calls
4254
* close().
@@ -149,6 +161,18 @@ public PublisherServiceStub getStub() {
149161
* stream.
150162
*
151163
* <p>Sample code:
164+
*
165+
* <pre>{@code
166+
* try (PublisherServiceClient publisherServiceClient = PublisherServiceClient.create()) {
167+
* BidiStream<PublishRequest, PublishResponse> bidiStream =
168+
* publisherServiceClient.publishCallable().call();
169+
* PublishRequest request = PublishRequest.newBuilder().build();
170+
* bidiStream.send(request);
171+
* for (PublishResponse response : bidiStream) {
172+
* // Do something when a response is received.
173+
* }
174+
* }
175+
* }</pre>
152176
*/
153177
public final BidiStreamingCallable<PublishRequest, PublishResponse> publishCallable() {
154178
return stub.publishCallable();

google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/v1/SubscriberServiceClient.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535
* <p>This class provides the ability to make remote calls to the backing service through method
3636
* calls that map to API methods. Sample code to get started:
3737
*
38+
* <pre>{@code
39+
* try (SubscriberServiceClient subscriberServiceClient = SubscriberServiceClient.create()) {
40+
* BidiStream<SubscribeRequest, SubscribeResponse> bidiStream =
41+
* subscriberServiceClient.subscribeCallable().call();
42+
* SubscribeRequest request = SubscribeRequest.newBuilder().build();
43+
* bidiStream.send(request);
44+
* for (SubscribeResponse response : bidiStream) {
45+
* // Do something when a response is received.
46+
* }
47+
* }
48+
* }</pre>
49+
*
3850
* <p>Note: close() needs to be called on the SubscriberServiceClient object to clean up resources
3951
* such as threads. In the example above, try-with-resources is used, which automatically calls
4052
* close().
@@ -142,6 +154,18 @@ public SubscriberServiceStub getStub() {
142154
* Establishes a stream with the server for receiving messages.
143155
*
144156
* <p>Sample code:
157+
*
158+
* <pre>{@code
159+
* try (SubscriberServiceClient subscriberServiceClient = SubscriberServiceClient.create()) {
160+
* BidiStream<SubscribeRequest, SubscribeResponse> bidiStream =
161+
* subscriberServiceClient.subscribeCallable().call();
162+
* SubscribeRequest request = SubscribeRequest.newBuilder().build();
163+
* bidiStream.send(request);
164+
* for (SubscribeResponse response : bidiStream) {
165+
* // Do something when a response is received.
166+
* }
167+
* }
168+
* }</pre>
145169
*/
146170
public final BidiStreamingCallable<SubscribeRequest, SubscribeResponse> subscribeCallable() {
147171
return stub.subscribeCallable();

0 commit comments

Comments
 (0)