Skip to content

Commit 773f3f9

Browse files
committed
Updating pubsub to match gax-java 0.0.12
1 parent 97e4db2 commit 773f3f9

11 files changed

Lines changed: 664 additions & 410 deletions

File tree

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

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import java.io.IOException;
5353
import java.util.ArrayList;
5454
import java.util.List;
55+
import java.util.concurrent.ScheduledExecutorService;
5556

5657
// Manually-added imports: add custom (non-generated) imports after this point.
5758

@@ -65,10 +66,10 @@
6566
*
6667
* <pre>
6768
* <code>
68-
* try (PublisherApi publisherApi = PublisherApi.defaultInstance()) {
69-
* // make calls here
70-
* String name = "";
71-
* Topic callResult = createTopic(name);
69+
* try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
70+
* String name = "";
71+
*
72+
* Topic callResult = publisherApi.createTopic(name);
7273
* }
7374
* </code>
7475
* </pre>
@@ -100,15 +101,10 @@
100101
* <p>This class can be customized by passing in a custom instance of PublisherSettings to
101102
* create(). For example:
102103
*
103-
* <!-- TODO(garrettjones) refactor code to make this simpler -->
104104
* <pre>
105105
* <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)
106+
* PublisherSettings publisherSettings = PublisherSettings.defaultBuilder()
107+
* .provideChannelWith(myCredentials)
112108
* .build();
113109
* PublisherApi publisherApi = PublisherApi.create(publisherSettings);
114110
* </code>
@@ -119,7 +115,9 @@
119115
*/
120116
@javax.annotation.Generated("by GAPIC")
121117
public class PublisherApi implements AutoCloseable {
118+
private final PublisherSettings settings;
122119
private final ManagedChannel channel;
120+
private final ScheduledExecutorService executor;
123121
private final List<AutoCloseable> closeables = new ArrayList<>();
124122

125123
private final ApiCallable<Topic, Topic> createTopicCallable;
@@ -133,11 +131,15 @@ public class PublisherApi implements AutoCloseable {
133131
listTopicSubscriptionsPagedCallable;
134132
private final ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable;
135133

134+
public final PublisherSettings getSettings() {
135+
return settings;
136+
}
137+
136138
private static final PathTemplate PROJECT_PATH_TEMPLATE =
137-
PathTemplate.create("projects/{project}");
139+
PathTemplate.createWithoutUrlEncoding("projects/{project}");
138140

139141
private static final PathTemplate TOPIC_PATH_TEMPLATE =
140-
PathTemplate.create("projects/{project}/topics/{topic}");
142+
PathTemplate.createWithoutUrlEncoding("projects/{project}/topics/{topic}");
141143

142144
/**
143145
* Formats a string containing the fully-qualified path to represent
@@ -200,8 +202,8 @@ public static final String parseTopicFromTopicName(String topicName) {
200202
* <!-- manual edit -->
201203
* <!-- end manual edit -->
202204
*/
203-
public static final PublisherApi defaultInstance() throws IOException {
204-
return create(PublisherSettings.defaultInstance());
205+
public static final PublisherApi createWithDefaults() throws IOException {
206+
return create(PublisherSettings.defaultBuilder().build());
205207
}
206208

207209
/**
@@ -225,24 +227,32 @@ public static final PublisherApi create(PublisherSettings settings) throws IOExc
225227
* <!-- end manual edit -->
226228
*/
227229
protected PublisherApi(PublisherSettings settings) throws IOException {
228-
this.channel = settings.getChannel();
229-
230-
this.createTopicCallable = ApiCallable.create(settings.createTopicSettings(), settings);
231-
this.publishCallable = ApiCallable.create(settings.publishSettings(), settings);
230+
this.settings = settings;
231+
this.executor = settings.getExecutorProvider().getOrBuildExecutor();
232+
this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor);
233+
234+
this.createTopicCallable =
235+
ApiCallable.create(settings.createTopicSettings(), this.channel, this.executor);
236+
this.publishCallable =
237+
ApiCallable.create(settings.publishSettings(), this.channel, this.executor);
232238
if (settings.publishSettings().getBundlerFactory() != null) {
233239
closeables.add(settings.publishSettings().getBundlerFactory());
234240
}
235-
this.getTopicCallable = ApiCallable.create(settings.getTopicSettings(), settings);
236-
this.listTopicsCallable = ApiCallable.create(settings.listTopicsSettings(), settings);
241+
this.getTopicCallable =
242+
ApiCallable.create(settings.getTopicSettings(), this.channel, this.executor);
243+
this.listTopicsCallable =
244+
ApiCallable.create(settings.listTopicsSettings(), this.channel, this.executor);
237245
this.listTopicsPagedCallable =
238-
ApiCallable.createPagedVariant(settings.listTopicsSettings(), settings);
246+
ApiCallable.createPagedVariant(settings.listTopicsSettings(), this.channel, this.executor);
239247
this.listTopicSubscriptionsCallable =
240-
ApiCallable.create(settings.listTopicSubscriptionsSettings(), settings);
248+
ApiCallable.create(settings.listTopicSubscriptionsSettings(), this.channel, this.executor);
241249
this.listTopicSubscriptionsPagedCallable =
242-
ApiCallable.createPagedVariant(settings.listTopicSubscriptionsSettings(), settings);
243-
this.deleteTopicCallable = ApiCallable.create(settings.deleteTopicSettings(), settings);
250+
ApiCallable.createPagedVariant(
251+
settings.listTopicSubscriptionsSettings(), this.channel, this.executor);
252+
this.deleteTopicCallable =
253+
ApiCallable.create(settings.deleteTopicSettings(), this.channel, this.executor);
244254

245-
if (settings.shouldAutoCloseChannel()) {
255+
if (settings.getChannelProvider().shouldAutoClose()) {
246256
closeables.add(
247257
new Closeable() {
248258
@Override
@@ -251,6 +261,15 @@ public void close() throws IOException {
251261
}
252262
});
253263
}
264+
if (settings.getExecutorProvider().shouldAutoClose()) {
265+
closeables.add(
266+
new Closeable() {
267+
@Override
268+
public void close() throws IOException {
269+
executor.shutdown();
270+
}
271+
});
272+
}
254273
}
255274

256275
// ----- createTopic -----
@@ -296,7 +315,6 @@ private Topic createTopic(Topic request) {
296315
*
297316
* <!-- manual edit -->
298317
* <!-- end manual edit -->
299-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
300318
*/
301319
public final ApiCallable<Topic, Topic> createTopicCallable() {
302320
return createTopicCallable;
@@ -306,7 +324,7 @@ public final ApiCallable<Topic, Topic> createTopicCallable() {
306324

307325
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
308326
/**
309-
* Adds one or more messages to the topic. Generates `NOT_FOUND` if the topic
327+
* Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic
310328
* does not exist. The message payload must not be empty; it must contain
311329
* either a non-empty data field, or at least one attribute.
312330
*
@@ -326,7 +344,7 @@ public final PublishResponse publish(String topic, List<PubsubMessage> messages)
326344

327345
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
328346
/**
329-
* Adds one or more messages to the topic. Generates `NOT_FOUND` if the topic
347+
* Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic
330348
* does not exist. The message payload must not be empty; it must contain
331349
* either a non-empty data field, or at least one attribute.
332350
*
@@ -342,13 +360,12 @@ public PublishResponse publish(PublishRequest request) {
342360

343361
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
344362
/**
345-
* Adds one or more messages to the topic. Generates `NOT_FOUND` if the topic
363+
* Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic
346364
* does not exist. The message payload must not be empty; it must contain
347365
* either a non-empty data field, or at least one attribute.
348366
*
349367
* <!-- manual edit -->
350368
* <!-- end manual edit -->
351-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
352369
*/
353370
public final ApiCallable<PublishRequest, PublishResponse> publishCallable() {
354371
return publishCallable;
@@ -392,7 +409,6 @@ private Topic getTopic(GetTopicRequest request) {
392409
*
393410
* <!-- manual edit -->
394411
* <!-- end manual edit -->
395-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
396412
*/
397413
public final ApiCallable<GetTopicRequest, Topic> getTopicCallable() {
398414
return getTopicCallable;
@@ -435,7 +451,6 @@ public final PageAccessor<Topic> listTopics(ListTopicsRequest request) {
435451
*
436452
* <!-- manual edit -->
437453
* <!-- end manual edit -->
438-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
439454
*/
440455
public final ApiCallable<ListTopicsRequest, PageAccessor<Topic>> listTopicsPagedCallable() {
441456
return listTopicsPagedCallable;
@@ -447,7 +462,6 @@ public final ApiCallable<ListTopicsRequest, PageAccessor<Topic>> listTopicsPaged
447462
*
448463
* <!-- manual edit -->
449464
* <!-- end manual edit -->
450-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
451465
*/
452466
public final ApiCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCallable() {
453467
return listTopicsCallable;
@@ -491,7 +505,6 @@ public final PageAccessor<String> listTopicSubscriptions(ListTopicSubscriptionsR
491505
*
492506
* <!-- manual edit -->
493507
* <!-- end manual edit -->
494-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
495508
*/
496509
public final ApiCallable<ListTopicSubscriptionsRequest, PageAccessor<String>>
497510
listTopicSubscriptionsPagedCallable() {
@@ -504,7 +517,6 @@ public final PageAccessor<String> listTopicSubscriptions(ListTopicSubscriptionsR
504517
*
505518
* <!-- manual edit -->
506519
* <!-- end manual edit -->
507-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
508520
*/
509521
public final ApiCallable<ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse>
510522
listTopicSubscriptionsCallable() {
@@ -515,7 +527,7 @@ public final PageAccessor<String> listTopicSubscriptions(ListTopicSubscriptionsR
515527

516528
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
517529
/**
518-
* Deletes the topic with the given name. Generates `NOT_FOUND` if the topic
530+
* Deletes the topic with the given name. Returns `NOT_FOUND` if the topic
519531
* does not exist. After a topic is deleted, a new topic may be created with
520532
* the same name; this is an entirely new topic with none of the old
521533
* configuration or subscriptions. Existing subscriptions to this topic are
@@ -535,7 +547,7 @@ public final void deleteTopic(String topic) {
535547

536548
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
537549
/**
538-
* Deletes the topic with the given name. Generates `NOT_FOUND` if the topic
550+
* Deletes the topic with the given name. Returns `NOT_FOUND` if the topic
539551
* does not exist. After a topic is deleted, a new topic may be created with
540552
* the same name; this is an entirely new topic with none of the old
541553
* configuration or subscriptions. Existing subscriptions to this topic are
@@ -553,15 +565,14 @@ private void deleteTopic(DeleteTopicRequest request) {
553565

554566
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
555567
/**
556-
* Deletes the topic with the given name. Generates `NOT_FOUND` if the topic
568+
* Deletes the topic with the given name. Returns `NOT_FOUND` if the topic
557569
* does not exist. After a topic is deleted, a new topic may be created with
558570
* the same name; this is an entirely new topic with none of the old
559571
* configuration or subscriptions. Existing subscriptions to this topic are
560572
* not deleted, but their `topic` field is set to `_deleted-topic_`.
561573
*
562574
* <!-- manual edit -->
563575
* <!-- end manual edit -->
564-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
565576
*/
566577
public final ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable() {
567578
return deleteTopicCallable;

0 commit comments

Comments
 (0)