Skip to content

Commit f9a9ed0

Browse files
michaelbausormziccard
authored andcommitted
Updating pubsub to match gax-java 0.0.12 (googleapis#981)
1 parent 8586506 commit f9a9ed0

11 files changed

Lines changed: 622 additions & 337 deletions

File tree

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

Lines changed: 44 additions & 34 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,9 @@
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+
* Topic callResult = publisherApi.createTopic(name);
7272
* }
7373
* </code>
7474
* </pre>
@@ -100,15 +100,10 @@
100100
* <p>This class can be customized by passing in a custom instance of PublisherSettings to
101101
* create(). For example:
102102
*
103-
* <!-- TODO(garrettjones) refactor code to make this simpler -->
104103
* <pre>
105104
* <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)
105+
* PublisherSettings publisherSettings = PublisherSettings.defaultBuilder()
106+
* .provideChannelWith(myCredentials)
112107
* .build();
113108
* PublisherApi publisherApi = PublisherApi.create(publisherSettings);
114109
* </code>
@@ -119,7 +114,9 @@
119114
*/
120115
@javax.annotation.Generated("by GAPIC")
121116
public class PublisherApi implements AutoCloseable {
117+
private final PublisherSettings settings;
122118
private final ManagedChannel channel;
119+
private final ScheduledExecutorService executor;
123120
private final List<AutoCloseable> closeables = new ArrayList<>();
124121

125122
private final ApiCallable<Topic, Topic> createTopicCallable;
@@ -133,11 +130,15 @@ public class PublisherApi implements AutoCloseable {
133130
listTopicSubscriptionsPagedCallable;
134131
private final ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable;
135132

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

139140
private static final PathTemplate TOPIC_PATH_TEMPLATE =
140-
PathTemplate.create("projects/{project}/topics/{topic}");
141+
PathTemplate.createWithoutUrlEncoding("projects/{project}/topics/{topic}");
141142

142143
/**
143144
* Formats a string containing the fully-qualified path to represent
@@ -200,8 +201,8 @@ public static final String parseTopicFromTopicName(String topicName) {
200201
* <!-- manual edit -->
201202
* <!-- end manual edit -->
202203
*/
203-
public static final PublisherApi defaultInstance() throws IOException {
204-
return create(PublisherSettings.defaultInstance());
204+
public static final PublisherApi createWithDefaults() throws IOException {
205+
return create(PublisherSettings.defaultBuilder().build());
205206
}
206207

207208
/**
@@ -225,24 +226,32 @@ public static final PublisherApi create(PublisherSettings settings) throws IOExc
225226
* <!-- end manual edit -->
226227
*/
227228
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);
229+
this.settings = settings;
230+
this.executor = settings.getExecutorProvider().getOrBuildExecutor();
231+
this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor);
232+
233+
this.createTopicCallable =
234+
ApiCallable.create(settings.createTopicSettings(), this.channel, this.executor);
235+
this.publishCallable =
236+
ApiCallable.create(settings.publishSettings(), this.channel, this.executor);
232237
if (settings.publishSettings().getBundlerFactory() != null) {
233238
closeables.add(settings.publishSettings().getBundlerFactory());
234239
}
235-
this.getTopicCallable = ApiCallable.create(settings.getTopicSettings(), settings);
236-
this.listTopicsCallable = ApiCallable.create(settings.listTopicsSettings(), settings);
240+
this.getTopicCallable =
241+
ApiCallable.create(settings.getTopicSettings(), this.channel, this.executor);
242+
this.listTopicsCallable =
243+
ApiCallable.create(settings.listTopicsSettings(), this.channel, this.executor);
237244
this.listTopicsPagedCallable =
238-
ApiCallable.createPagedVariant(settings.listTopicsSettings(), settings);
245+
ApiCallable.createPagedVariant(settings.listTopicsSettings(), this.channel, this.executor);
239246
this.listTopicSubscriptionsCallable =
240-
ApiCallable.create(settings.listTopicSubscriptionsSettings(), settings);
247+
ApiCallable.create(settings.listTopicSubscriptionsSettings(), this.channel, this.executor);
241248
this.listTopicSubscriptionsPagedCallable =
242-
ApiCallable.createPagedVariant(settings.listTopicSubscriptionsSettings(), settings);
243-
this.deleteTopicCallable = ApiCallable.create(settings.deleteTopicSettings(), settings);
249+
ApiCallable.createPagedVariant(
250+
settings.listTopicSubscriptionsSettings(), this.channel, this.executor);
251+
this.deleteTopicCallable =
252+
ApiCallable.create(settings.deleteTopicSettings(), this.channel, this.executor);
244253

245-
if (settings.shouldAutoCloseChannel()) {
254+
if (settings.getChannelProvider().shouldAutoClose()) {
246255
closeables.add(
247256
new Closeable() {
248257
@Override
@@ -251,6 +260,15 @@ public void close() throws IOException {
251260
}
252261
});
253262
}
263+
if (settings.getExecutorProvider().shouldAutoClose()) {
264+
closeables.add(
265+
new Closeable() {
266+
@Override
267+
public void close() throws IOException {
268+
executor.shutdown();
269+
}
270+
});
271+
}
254272
}
255273

256274
// ----- createTopic -----
@@ -296,7 +314,6 @@ private Topic createTopic(Topic request) {
296314
*
297315
* <!-- manual edit -->
298316
* <!-- end manual edit -->
299-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
300317
*/
301318
public final ApiCallable<Topic, Topic> createTopicCallable() {
302319
return createTopicCallable;
@@ -348,7 +365,6 @@ public PublishResponse publish(PublishRequest request) {
348365
*
349366
* <!-- manual edit -->
350367
* <!-- end manual edit -->
351-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
352368
*/
353369
public final ApiCallable<PublishRequest, PublishResponse> publishCallable() {
354370
return publishCallable;
@@ -392,7 +408,6 @@ private Topic getTopic(GetTopicRequest request) {
392408
*
393409
* <!-- manual edit -->
394410
* <!-- end manual edit -->
395-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
396411
*/
397412
public final ApiCallable<GetTopicRequest, Topic> getTopicCallable() {
398413
return getTopicCallable;
@@ -435,7 +450,6 @@ public final PageAccessor<Topic> listTopics(ListTopicsRequest request) {
435450
*
436451
* <!-- manual edit -->
437452
* <!-- end manual edit -->
438-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
439453
*/
440454
public final ApiCallable<ListTopicsRequest, PageAccessor<Topic>> listTopicsPagedCallable() {
441455
return listTopicsPagedCallable;
@@ -447,7 +461,6 @@ public final ApiCallable<ListTopicsRequest, PageAccessor<Topic>> listTopicsPaged
447461
*
448462
* <!-- manual edit -->
449463
* <!-- end manual edit -->
450-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
451464
*/
452465
public final ApiCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCallable() {
453466
return listTopicsCallable;
@@ -491,7 +504,6 @@ public final PageAccessor<String> listTopicSubscriptions(ListTopicSubscriptionsR
491504
*
492505
* <!-- manual edit -->
493506
* <!-- end manual edit -->
494-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
495507
*/
496508
public final ApiCallable<ListTopicSubscriptionsRequest, PageAccessor<String>>
497509
listTopicSubscriptionsPagedCallable() {
@@ -504,7 +516,6 @@ public final PageAccessor<String> listTopicSubscriptions(ListTopicSubscriptionsR
504516
*
505517
* <!-- manual edit -->
506518
* <!-- end manual edit -->
507-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
508519
*/
509520
public final ApiCallable<ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse>
510521
listTopicSubscriptionsCallable() {
@@ -561,7 +572,6 @@ private void deleteTopic(DeleteTopicRequest request) {
561572
*
562573
* <!-- manual edit -->
563574
* <!-- end manual edit -->
564-
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
565575
*/
566576
public final ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable() {
567577
return deleteTopicCallable;

0 commit comments

Comments
 (0)