Skip to content

Commit 9b2f341

Browse files
shinfanmziccard
authored andcommitted
Update gcloud pubsub. (googleapis#951)
- compatible with GAX 0.0.11 - better documentation
1 parent 87ff28e commit 9b2f341

File tree

9 files changed

+717
-151
lines changed

9 files changed

+717
-151
lines changed

gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java

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

3434
package com.google.cloud.pubsub.spi.v1;
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.protobuf.Empty;
@@ -59,6 +60,60 @@
5960
* Service Description: The service that an application uses to manipulate topics, and to send
6061
* messages to a topic.
6162
*
63+
* <p>This class provides the ability to make remote calls to the backing service through method
64+
* calls that map to API methods. Sample code to get started:
65+
*
66+
* <pre>
67+
* <code>
68+
* try (PublisherApi publisherApi = PublisherApi.defaultInstance()) {
69+
* // make calls here
70+
* String name = "";
71+
* Topic callResult = createTopic(name);
72+
* }
73+
* </code>
74+
* </pre>
75+
*
76+
* <p>Note: close() needs to be called on the publisherApi object to clean up resources such
77+
* as threads. In the example above, try-with-resources is used, which automatically calls
78+
* close().
79+
*
80+
* <p>The surface of this class includes several types of Java methods for each of the API's methods:
81+
*
82+
* <ol>
83+
* <li> A "flattened" method. With this type of method, the fields of the request type have been
84+
* converted into function parameters. It may be the case that not all fields are available
85+
* as parameters, and not every API method will have a flattened method entry point.
86+
* <li> A "request object" method. This type of method only takes one parameter, a request
87+
* object, which must be constructed before the call. Not every API method will have a request
88+
* object method.
89+
* <li> A "callable" method. This type of method takes no parameters and returns an immutable
90+
* ApiCallable object, which can be used to initiate calls to the service.
91+
* </ol>
92+
*
93+
* <p>See the individual methods for example code.
94+
*
95+
* <p>Many parameters require resource names to be formatted in a particular way. To assist
96+
* with these names, this class includes a format method for each type of name, and additionally
97+
* a parse method to extract the individual identifiers contained within names that are
98+
* returned.
99+
*
100+
* <p>This class can be customized by passing in a custom instance of PublisherSettings to
101+
* create(). For example:
102+
*
103+
* <!-- TODO(garrettjones) refactor code to make this simpler -->
104+
* <pre>
105+
* <code>
106+
* ConnectionSettings defaultConnectionSettings =
107+
* PublisherSettings.defaultInstance().toBuilder().getConnectionSettings();
108+
* ConnectionSettings updatedConnectionSettings =
109+
* defaultConnectionSettings.toBuilder().provideCredentialsWith(myCredentials).build();
110+
* PublisherSettings publisherSettings = PublisherSettings.defaultInstance().toBuilder().
111+
* provideChannelWith(updatedConnectionSettings)
112+
* .build();
113+
* PublisherApi publisherApi = PublisherApi.create(publisherSettings);
114+
* </code>
115+
* </pre>
116+
*
62117
* <!-- manual edit -->
63118
* <!-- end manual edit -->
64119
*/
@@ -71,11 +126,11 @@ public class PublisherApi implements AutoCloseable {
71126
private final ApiCallable<PublishRequest, PublishResponse> publishCallable;
72127
private final ApiCallable<GetTopicRequest, Topic> getTopicCallable;
73128
private final ApiCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCallable;
74-
private final ApiCallable<ListTopicsRequest, Iterable<Topic>> listTopicsIterableCallable;
129+
private final ApiCallable<ListTopicsRequest, PageAccessor<Topic>> listTopicsPagedCallable;
75130
private final ApiCallable<ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse>
76131
listTopicSubscriptionsCallable;
77-
private final ApiCallable<ListTopicSubscriptionsRequest, Iterable<String>>
78-
listTopicSubscriptionsIterableCallable;
132+
private final ApiCallable<ListTopicSubscriptionsRequest, PageAccessor<String>>
133+
listTopicSubscriptionsPagedCallable;
79134
private final ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable;
80135

81136
private static final PathTemplate PROJECT_PATH_TEMPLATE =
@@ -179,12 +234,12 @@ protected PublisherApi(PublisherSettings settings) throws IOException {
179234
}
180235
this.getTopicCallable = ApiCallable.create(settings.getTopicSettings(), settings);
181236
this.listTopicsCallable = ApiCallable.create(settings.listTopicsSettings(), settings);
182-
this.listTopicsIterableCallable =
183-
ApiCallable.createIterable(settings.listTopicsSettings(), settings);
237+
this.listTopicsPagedCallable =
238+
ApiCallable.createPagedVariant(settings.listTopicsSettings(), settings);
184239
this.listTopicSubscriptionsCallable =
185240
ApiCallable.create(settings.listTopicSubscriptionsSettings(), settings);
186-
this.listTopicSubscriptionsIterableCallable =
187-
ApiCallable.createIterable(settings.listTopicSubscriptionsSettings(), settings);
241+
this.listTopicSubscriptionsPagedCallable =
242+
ApiCallable.createPagedVariant(settings.listTopicSubscriptionsSettings(), settings);
188243
this.deleteTopicCallable = ApiCallable.create(settings.deleteTopicSettings(), settings);
189244

190245
if (settings.shouldAutoCloseChannel()) {
@@ -213,7 +268,7 @@ public void close() throws IOException {
213268
* underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
214269
* signs (`%`). It must be between 3 and 255 characters in length, and it
215270
* must not start with `"goog"`.
216-
* @throws ApiException if the remote call fails
271+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
217272
*/
218273
public final Topic createTopic(String name) {
219274
Topic request = Topic.newBuilder().setName(name).build();
@@ -229,7 +284,7 @@ public final Topic createTopic(String name) {
229284
* <!-- end manual edit -->
230285
*
231286
* @param request The request object containing all of the parameters for the API call.
232-
* @throws ApiException if the remote call fails
287+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
233288
*/
234289
private Topic createTopic(Topic request) {
235290
return createTopicCallable().call(request);
@@ -241,7 +296,7 @@ private Topic createTopic(Topic request) {
241296
*
242297
* <!-- manual edit -->
243298
* <!-- end manual edit -->
244-
* @throws ApiException if the remote call fails
299+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
245300
*/
246301
public final ApiCallable<Topic, Topic> createTopicCallable() {
247302
return createTopicCallable;
@@ -260,7 +315,7 @@ public final ApiCallable<Topic, Topic> createTopicCallable() {
260315
*
261316
* @param topic The messages in the request will be published on this topic.
262317
* @param messages The messages to publish.
263-
* @throws ApiException if the remote call fails
318+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
264319
*/
265320
public final PublishResponse publish(String topic, List<PubsubMessage> messages) {
266321
PublishRequest request =
@@ -279,7 +334,7 @@ public final PublishResponse publish(String topic, List<PubsubMessage> messages)
279334
* <!-- end manual edit -->
280335
*
281336
* @param request The request object containing all of the parameters for the API call.
282-
* @throws ApiException if the remote call fails
337+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
283338
*/
284339
public PublishResponse publish(PublishRequest request) {
285340
return publishCallable().call(request);
@@ -293,7 +348,7 @@ public PublishResponse publish(PublishRequest request) {
293348
*
294349
* <!-- manual edit -->
295350
* <!-- end manual edit -->
296-
* @throws ApiException if the remote call fails
351+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
297352
*/
298353
public final ApiCallable<PublishRequest, PublishResponse> publishCallable() {
299354
return publishCallable;
@@ -309,7 +364,7 @@ public final ApiCallable<PublishRequest, PublishResponse> publishCallable() {
309364
* <!-- end manual edit -->
310365
*
311366
* @param topic The name of the topic to get.
312-
* @throws ApiException if the remote call fails
367+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
313368
*/
314369
public final Topic getTopic(String topic) {
315370
GetTopicRequest request = GetTopicRequest.newBuilder().setTopic(topic).build();
@@ -325,7 +380,7 @@ public final Topic getTopic(String topic) {
325380
* <!-- end manual edit -->
326381
*
327382
* @param request The request object containing all of the parameters for the API call.
328-
* @throws ApiException if the remote call fails
383+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
329384
*/
330385
private Topic getTopic(GetTopicRequest request) {
331386
return getTopicCallable().call(request);
@@ -337,7 +392,7 @@ private Topic getTopic(GetTopicRequest request) {
337392
*
338393
* <!-- manual edit -->
339394
* <!-- end manual edit -->
340-
* @throws ApiException if the remote call fails
395+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
341396
*/
342397
public final ApiCallable<GetTopicRequest, Topic> getTopicCallable() {
343398
return getTopicCallable;
@@ -353,9 +408,9 @@ public final ApiCallable<GetTopicRequest, Topic> getTopicCallable() {
353408
* <!-- end manual edit -->
354409
*
355410
* @param project The name of the cloud project that topics belong to.
356-
* @throws ApiException if the remote call fails
411+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
357412
*/
358-
public final Iterable<Topic> listTopics(String project) {
413+
public final PageAccessor<Topic> listTopics(String project) {
359414
ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(project).build();
360415
return listTopics(request);
361416
}
@@ -368,10 +423,10 @@ public final Iterable<Topic> listTopics(String project) {
368423
* <!-- end manual edit -->
369424
*
370425
* @param request The request object containing all of the parameters for the API call.
371-
* @throws ApiException if the remote call fails
426+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
372427
*/
373-
public final Iterable<Topic> listTopics(ListTopicsRequest request) {
374-
return listTopicsIterableCallable().call(request);
428+
public final PageAccessor<Topic> listTopics(ListTopicsRequest request) {
429+
return listTopicsPagedCallable().call(request);
375430
}
376431

377432
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
@@ -380,10 +435,10 @@ public final Iterable<Topic> listTopics(ListTopicsRequest request) {
380435
*
381436
* <!-- manual edit -->
382437
* <!-- end manual edit -->
383-
* @throws ApiException if the remote call fails
438+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
384439
*/
385-
public final ApiCallable<ListTopicsRequest, Iterable<Topic>> listTopicsIterableCallable() {
386-
return listTopicsIterableCallable;
440+
public final ApiCallable<ListTopicsRequest, PageAccessor<Topic>> listTopicsPagedCallable() {
441+
return listTopicsPagedCallable;
387442
}
388443

389444
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
@@ -392,7 +447,7 @@ public final ApiCallable<ListTopicsRequest, Iterable<Topic>> listTopicsIterableC
392447
*
393448
* <!-- manual edit -->
394449
* <!-- end manual edit -->
395-
* @throws ApiException if the remote call fails
450+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
396451
*/
397452
public final ApiCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCallable() {
398453
return listTopicsCallable;
@@ -408,9 +463,9 @@ public final ApiCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCallab
408463
* <!-- end manual edit -->
409464
*
410465
* @param topic The name of the topic that subscriptions are attached to.
411-
* @throws ApiException if the remote call fails
466+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
412467
*/
413-
public final Iterable<String> listTopicSubscriptions(String topic) {
468+
public final PageAccessor<String> listTopicSubscriptions(String topic) {
414469
ListTopicSubscriptionsRequest request =
415470
ListTopicSubscriptionsRequest.newBuilder().setTopic(topic).build();
416471
return listTopicSubscriptions(request);
@@ -424,10 +479,10 @@ public final Iterable<String> listTopicSubscriptions(String topic) {
424479
* <!-- end manual edit -->
425480
*
426481
* @param request The request object containing all of the parameters for the API call.
427-
* @throws ApiException if the remote call fails
482+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
428483
*/
429-
public final Iterable<String> listTopicSubscriptions(ListTopicSubscriptionsRequest request) {
430-
return listTopicSubscriptionsIterableCallable().call(request);
484+
public final PageAccessor<String> listTopicSubscriptions(ListTopicSubscriptionsRequest request) {
485+
return listTopicSubscriptionsPagedCallable().call(request);
431486
}
432487

433488
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
@@ -436,11 +491,11 @@ public final Iterable<String> listTopicSubscriptions(ListTopicSubscriptionsReque
436491
*
437492
* <!-- manual edit -->
438493
* <!-- end manual edit -->
439-
* @throws ApiException if the remote call fails
494+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
440495
*/
441-
public final ApiCallable<ListTopicSubscriptionsRequest, Iterable<String>>
442-
listTopicSubscriptionsIterableCallable() {
443-
return listTopicSubscriptionsIterableCallable;
496+
public final ApiCallable<ListTopicSubscriptionsRequest, PageAccessor<String>>
497+
listTopicSubscriptionsPagedCallable() {
498+
return listTopicSubscriptionsPagedCallable;
444499
}
445500

446501
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
@@ -449,7 +504,7 @@ public final Iterable<String> listTopicSubscriptions(ListTopicSubscriptionsReque
449504
*
450505
* <!-- manual edit -->
451506
* <!-- end manual edit -->
452-
* @throws ApiException if the remote call fails
507+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
453508
*/
454509
public final ApiCallable<ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse>
455510
listTopicSubscriptionsCallable() {
@@ -470,7 +525,7 @@ public final Iterable<String> listTopicSubscriptions(ListTopicSubscriptionsReque
470525
* <!-- end manual edit -->
471526
*
472527
* @param topic Name of the topic to delete.
473-
* @throws ApiException if the remote call fails
528+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
474529
*/
475530
public final void deleteTopic(String topic) {
476531
DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopic(topic).build();
@@ -490,7 +545,7 @@ public final void deleteTopic(String topic) {
490545
* <!-- end manual edit -->
491546
*
492547
* @param request The request object containing all of the parameters for the API call.
493-
* @throws ApiException if the remote call fails
548+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
494549
*/
495550
private void deleteTopic(DeleteTopicRequest request) {
496551
deleteTopicCallable().call(request);
@@ -506,7 +561,7 @@ private void deleteTopic(DeleteTopicRequest request) {
506561
*
507562
* <!-- manual edit -->
508563
* <!-- end manual edit -->
509-
* @throws ApiException if the remote call fails
564+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
510565
*/
511566
public final ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable() {
512567
return deleteTopicCallable;

0 commit comments

Comments
 (0)