Skip to content

Commit 0fcafa5

Browse files
committed
Update with latest surface fixes based Java export review.
Refactorings: - Remove section headers from comments - Remove innerClass and move util methods to top level. - Rename ApiCallableBuilder to just Builder - Rename XPath into XName - Rename XMethod into XCallSettings in XSettings classe Improvements: - Let the user decide whether to auto-close provided channel - Make all generated methods final - Use Duration instead of long to avoid time unit confusion - Support bundling limits configuration Others: - Update unit tests - Update pom and dependency
1 parent a1b6c65 commit 0fcafa5

File tree

10 files changed

+577
-700
lines changed

10 files changed

+577
-700
lines changed

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

Lines changed: 96 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@
6666
*/
6767
@javax.annotation.Generated("by GAPIC")
6868
public class PublisherApi implements AutoCloseable {
69-
// ========
70-
// Members
71-
// ========
72-
7369
private final ManagedChannel channel;
7470
private final List<AutoCloseable> closeables = new ArrayList<>();
7571

@@ -84,105 +80,88 @@ public class PublisherApi implements AutoCloseable {
8480
listTopicSubscriptionsIterableCallable;
8581
private final ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable;
8682

87-
public static class ResourceNames {
88-
89-
// =======================
90-
// ResourceNames Constants
91-
// =======================
92-
93-
/**
94-
* A PathTemplate representing the fully-qualified path to represent
95-
* a project resource.
96-
*
97-
* <!-- manual edit -->
98-
* <!-- end manual edit -->
99-
*/
100-
private static final PathTemplate PROJECT_PATH_TEMPLATE =
101-
PathTemplate.create("projects/{project}");
102-
103-
/**
104-
* A PathTemplate representing the fully-qualified path to represent
105-
* a topic resource.
106-
*
107-
* <!-- manual edit -->
108-
* <!-- end manual edit -->
109-
*/
110-
private static final PathTemplate TOPIC_PATH_TEMPLATE =
111-
PathTemplate.create("projects/{project}/topics/{topic}");
112-
113-
private ResourceNames() {}
114-
115-
// ==============================
116-
// Resource Name Helper Functions
117-
// ==============================
118-
119-
/**
120-
* Formats a string containing the fully-qualified path to represent
121-
* a project resource.
122-
*
123-
* <!-- manual edit -->
124-
* <!-- end manual edit -->
125-
*/
126-
public static final String formatProjectPath(String project) {
127-
return PROJECT_PATH_TEMPLATE.instantiate("project", project);
128-
}
83+
/**
84+
* A PathTemplate representing the fully-qualified path to represent
85+
* a project resource.
86+
*
87+
* <!-- manual edit -->
88+
* <!-- end manual edit -->
89+
*/
90+
private static final PathTemplate PROJECT_PATH_TEMPLATE =
91+
PathTemplate.create("projects/{project}");
12992

130-
/**
131-
* Formats a string containing the fully-qualified path to represent
132-
* a topic resource.
133-
*
134-
* <!-- manual edit -->
135-
* <!-- end manual edit -->
136-
*/
137-
public static final String formatTopicPath(String project, String topic) {
138-
return TOPIC_PATH_TEMPLATE.instantiate("project", project, "topic", topic);
139-
}
93+
/**
94+
* A PathTemplate representing the fully-qualified path to represent
95+
* a topic resource.
96+
*
97+
* <!-- manual edit -->
98+
* <!-- end manual edit -->
99+
*/
100+
private static final PathTemplate TOPIC_PATH_TEMPLATE =
101+
PathTemplate.create("projects/{project}/topics/{topic}");
140102

141-
/**
142-
* Parses the project from the given fully-qualified path which
143-
* represents a project resource.
144-
*
145-
* <!-- manual edit -->
146-
* <!-- end manual edit -->
147-
*/
148-
public static final String parseProjectFromProjectPath(String projectPath) {
149-
return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project");
150-
}
103+
/**
104+
* Formats a string containing the fully-qualified path to represent
105+
* a project resource.
106+
*
107+
* <!-- manual edit -->
108+
* <!-- end manual edit -->
109+
*/
110+
public static final String formatProjectName(String project) {
111+
return PROJECT_PATH_TEMPLATE.instantiate("project", project);
112+
}
151113

152-
/**
153-
* Parses the project from the given fully-qualified path which
154-
* represents a topic resource.
155-
*
156-
* <!-- manual edit -->
157-
* <!-- end manual edit -->
158-
*/
159-
public static final String parseProjectFromTopicPath(String topicPath) {
160-
return TOPIC_PATH_TEMPLATE.parse(topicPath).get("project");
161-
}
114+
/**
115+
* Formats a string containing the fully-qualified path to represent
116+
* a topic resource.
117+
*
118+
* <!-- manual edit -->
119+
* <!-- end manual edit -->
120+
*/
121+
public static final String formatTopicName(String project, String topic) {
122+
return TOPIC_PATH_TEMPLATE.instantiate("project", project, "topic", topic);
123+
}
162124

163-
/**
164-
* Parses the topic from the given fully-qualified path which
165-
* represents a topic resource.
166-
*
167-
* <!-- manual edit -->
168-
* <!-- end manual edit -->
169-
*/
170-
public static final String parseTopicFromTopicPath(String topicPath) {
171-
return TOPIC_PATH_TEMPLATE.parse(topicPath).get("topic");
172-
}
125+
/**
126+
* Parses the project from the given fully-qualified path which
127+
* represents a project resource.
128+
*
129+
* <!-- manual edit -->
130+
* <!-- end manual edit -->
131+
*/
132+
public static final String parseProjectFromProjectName(String projectName) {
133+
return PROJECT_PATH_TEMPLATE.parse(projectName).get("project");
134+
}
135+
136+
/**
137+
* Parses the project from the given fully-qualified path which
138+
* represents a topic resource.
139+
*
140+
* <!-- manual edit -->
141+
* <!-- end manual edit -->
142+
*/
143+
public static final String parseProjectFromTopicName(String topicName) {
144+
return TOPIC_PATH_TEMPLATE.parse(topicName).get("project");
173145
}
174146

175-
// ===============
176-
// Factory Methods
177-
// ===============
147+
/**
148+
* Parses the topic from the given fully-qualified path which
149+
* represents a topic resource.
150+
*
151+
* <!-- manual edit -->
152+
* <!-- end manual edit -->
153+
*/
154+
public static final String parseTopicFromTopicName(String topicName) {
155+
return TOPIC_PATH_TEMPLATE.parse(topicName).get("topic");
156+
}
178157

179158
/**
180159
* Constructs an instance of PublisherApi with default settings.
181160
*
182161
* <!-- manual edit -->
183162
* <!-- end manual edit -->
184163
*/
185-
public static PublisherApi create() throws IOException {
164+
public static final PublisherApi create() throws IOException {
186165
return create(PublisherSettings.create());
187166
}
188167

@@ -194,7 +173,7 @@ public static PublisherApi create() throws IOException {
194173
* <!-- manual edit -->
195174
* <!-- end manual edit -->
196175
*/
197-
public static PublisherApi create(PublisherSettings settings) throws IOException {
176+
public static final PublisherApi create(PublisherSettings settings) throws IOException {
198177
return new PublisherApi(settings);
199178
}
200179

@@ -226,19 +205,17 @@ protected PublisherApi(PublisherSettings settings) throws IOException {
226205
settings.listTopicSubscriptionsMethod().buildPageStreaming(settings);
227206
this.deleteTopicCallable = settings.deleteTopicMethod().build(settings);
228207

229-
closeables.add(
230-
new Closeable() {
231-
@Override
232-
public void close() throws IOException {
233-
channel.shutdown();
234-
}
235-
});
208+
if (settings.shouldAutoCloseChannel()) {
209+
closeables.add(
210+
new Closeable() {
211+
@Override
212+
public void close() throws IOException {
213+
channel.shutdown();
214+
}
215+
});
216+
}
236217
}
237218

238-
// =============
239-
// Service Calls
240-
// =============
241-
242219
// ----- createTopic -----
243220

244221
// AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing.
@@ -255,7 +232,7 @@ public void close() throws IOException {
255232
* signs (`%`). It must be between 3 and 255 characters in length, and it
256233
* must not start with `"goog"`.
257234
*/
258-
public Topic createTopic(String name) {
235+
public final Topic createTopic(String name) {
259236
Topic request = Topic.newBuilder().setName(name).build();
260237

261238
return createTopic(request);
@@ -281,7 +258,7 @@ private Topic createTopic(Topic request) {
281258
* <!-- manual edit -->
282259
* <!-- end manual edit -->
283260
*/
284-
public ApiCallable<Topic, Topic> createTopicCallable() {
261+
public final ApiCallable<Topic, Topic> createTopicCallable() {
285262
return createTopicCallable;
286263
}
287264

@@ -299,7 +276,7 @@ public ApiCallable<Topic, Topic> createTopicCallable() {
299276
* @param topic The messages in the request will be published on this topic.
300277
* @param messages The messages to publish.
301278
*/
302-
public PublishResponse publish(String topic, List<PubsubMessage> messages) {
279+
public final PublishResponse publish(String topic, List<PubsubMessage> messages) {
303280
PublishRequest request =
304281
PublishRequest.newBuilder().setTopic(topic).addAllMessages(messages).build();
305282

@@ -330,7 +307,7 @@ public PublishResponse publish(PublishRequest request) {
330307
* <!-- manual edit -->
331308
* <!-- end manual edit -->
332309
*/
333-
public ApiCallable<PublishRequest, PublishResponse> publishCallable() {
310+
public final ApiCallable<PublishRequest, PublishResponse> publishCallable() {
334311
return publishCallable;
335312
}
336313

@@ -345,7 +322,7 @@ public ApiCallable<PublishRequest, PublishResponse> publishCallable() {
345322
*
346323
* @param topic The name of the topic to get.
347324
*/
348-
public Topic getTopic(String topic) {
325+
public final Topic getTopic(String topic) {
349326
GetTopicRequest request = GetTopicRequest.newBuilder().setTopic(topic).build();
350327

351328
return getTopic(request);
@@ -371,7 +348,7 @@ private Topic getTopic(GetTopicRequest request) {
371348
* <!-- manual edit -->
372349
* <!-- end manual edit -->
373350
*/
374-
public ApiCallable<GetTopicRequest, Topic> getTopicCallable() {
351+
public final ApiCallable<GetTopicRequest, Topic> getTopicCallable() {
375352
return getTopicCallable;
376353
}
377354

@@ -384,7 +361,7 @@ public ApiCallable<GetTopicRequest, Topic> getTopicCallable() {
384361
* <!-- manual edit -->
385362
* <!-- end manual edit -->
386363
*/
387-
public Iterable<Topic> listTopics(String project) {
364+
public final Iterable<Topic> listTopics(String project) {
388365
ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(project).build();
389366
return listTopics(request);
390367
}
@@ -398,7 +375,7 @@ public Iterable<Topic> listTopics(String project) {
398375
*
399376
* @param request The request object containing all of the parameters for the API call.
400377
*/
401-
public Iterable<Topic> listTopics(ListTopicsRequest request) {
378+
public final Iterable<Topic> listTopics(ListTopicsRequest request) {
402379
return listTopicsIterableCallable().call(request);
403380
}
404381

@@ -409,7 +386,7 @@ public Iterable<Topic> listTopics(ListTopicsRequest request) {
409386
* <!-- manual edit -->
410387
* <!-- end manual edit -->
411388
*/
412-
public ApiCallable<ListTopicsRequest, Iterable<Topic>> listTopicsIterableCallable() {
389+
public final ApiCallable<ListTopicsRequest, Iterable<Topic>> listTopicsIterableCallable() {
413390
return listTopicsIterableCallable;
414391
}
415392

@@ -420,7 +397,7 @@ public ApiCallable<ListTopicsRequest, Iterable<Topic>> listTopicsIterableCallabl
420397
* <!-- manual edit -->
421398
* <!-- end manual edit -->
422399
*/
423-
public ApiCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCallable() {
400+
public final ApiCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCallable() {
424401
return listTopicsCallable;
425402
}
426403

@@ -433,7 +410,7 @@ public ApiCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCallable() {
433410
* <!-- manual edit -->
434411
* <!-- end manual edit -->
435412
*/
436-
public Iterable<String> listTopicSubscriptions(String topic) {
413+
public final Iterable<String> listTopicSubscriptions(String topic) {
437414
ListTopicSubscriptionsRequest request =
438415
ListTopicSubscriptionsRequest.newBuilder().setTopic(topic).build();
439416
return listTopicSubscriptions(request);
@@ -448,7 +425,7 @@ public Iterable<String> listTopicSubscriptions(String topic) {
448425
*
449426
* @param request The request object containing all of the parameters for the API call.
450427
*/
451-
public Iterable<String> listTopicSubscriptions(ListTopicSubscriptionsRequest request) {
428+
public final Iterable<String> listTopicSubscriptions(ListTopicSubscriptionsRequest request) {
452429
return listTopicSubscriptionsIterableCallable().call(request);
453430
}
454431

@@ -459,7 +436,7 @@ public Iterable<String> listTopicSubscriptions(ListTopicSubscriptionsRequest req
459436
* <!-- manual edit -->
460437
* <!-- end manual edit -->
461438
*/
462-
public ApiCallable<ListTopicSubscriptionsRequest, Iterable<String>>
439+
public final ApiCallable<ListTopicSubscriptionsRequest, Iterable<String>>
463440
listTopicSubscriptionsIterableCallable() {
464441
return listTopicSubscriptionsIterableCallable;
465442
}
@@ -471,7 +448,7 @@ public Iterable<String> listTopicSubscriptions(ListTopicSubscriptionsRequest req
471448
* <!-- manual edit -->
472449
* <!-- end manual edit -->
473450
*/
474-
public ApiCallable<ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse>
451+
public final ApiCallable<ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse>
475452
listTopicSubscriptionsCallable() {
476453
return listTopicSubscriptionsCallable;
477454
}
@@ -491,7 +468,7 @@ public Iterable<String> listTopicSubscriptions(ListTopicSubscriptionsRequest req
491468
*
492469
* @param topic Name of the topic to delete.
493470
*/
494-
public void deleteTopic(String topic) {
471+
public final void deleteTopic(String topic) {
495472
DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopic(topic).build();
496473

497474
deleteTopic(request);
@@ -525,14 +502,10 @@ private void deleteTopic(DeleteTopicRequest request) {
525502
* <!-- manual edit -->
526503
* <!-- end manual edit -->
527504
*/
528-
public ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable() {
505+
public final ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable() {
529506
return deleteTopicCallable;
530507
}
531508

532-
// ========
533-
// Cleanup
534-
// ========
535-
536509
/**
537510
* Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately
538511
* cancelled.
@@ -541,7 +514,7 @@ public ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable() {
541514
* <!-- end manual edit -->
542515
*/
543516
@Override
544-
public void close() throws Exception {
517+
public final void close() throws Exception {
545518
for (AutoCloseable closeable : closeables) {
546519
closeable.close();
547520
}

0 commit comments

Comments
 (0)