Skip to content

Commit 0b7b39a

Browse files
garrettjonesgooglemziccard
authored andcommitted
Using resurrected ServiceApiSettings in Settings classes
1 parent f253c54 commit 0b7b39a

6 files changed

Lines changed: 169 additions & 146 deletions

File tree

gcloud-java-pubsub/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<dependency>
2020
<groupId>com.google.api</groupId>
2121
<artifactId>gax</artifactId>
22-
<version>0.0.3</version>
22+
<version>0.0.4</version>
2323
</dependency>
2424
<dependency>
2525
<groupId>com.google.api.grpc</groupId>

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ public static PublisherApi create(PublisherSettings settings) throws IOException
213213
protected PublisherApi(PublisherSettings settings) throws IOException {
214214
this.channel = settings.getChannel();
215215

216-
for (ApiCallSettings method : settings.allMethods()) {
217-
if (method.getExecutor() == null) {
218-
method.setExecutor(settings.getExecutor());
219-
}
220-
}
221-
222216
this.createTopicCallable = settings.createTopicMethod().build(settings);
223217
this.publishCallable = settings.publishMethod().build(settings);
224218
this.getTopicCallable = settings.getTopicMethod().build(settings);

gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/PublisherSettings.java

Lines changed: 67 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder;
4141
import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder;
4242
import com.google.api.gax.grpc.PageDescriptor;
43+
import com.google.api.gax.grpc.ServiceApiSettings;
4344
import com.google.common.collect.ImmutableList;
4445
import com.google.common.collect.ImmutableMap;
4546
import com.google.common.collect.ImmutableSet;
@@ -62,7 +63,7 @@
6263

6364
// AUTO-GENERATED DOCUMENTATION AND CLASS - see instructions at the top of the file for editing.
6465
@javax.annotation.Generated("by GAPIC")
65-
public class PublisherSettings extends ApiCallSettings {
66+
public class PublisherSettings extends ServiceApiSettings {
6667

6768
// =========
6869
// Constants
@@ -131,16 +132,61 @@ public class PublisherSettings extends ApiCallSettings {
131132
RETRY_PARAM_DEFINITIONS = definitions.build();
132133
}
133134

134-
private final ApiCallableBuilder<Topic, Topic> createTopicMethod;
135-
private final ApiCallableBuilder<PublishRequest, PublishResponse> publishMethod;
136-
private final ApiCallableBuilder<GetTopicRequest, Topic> getTopicMethod;
137-
private final PageStreamingApiCallableBuilder<ListTopicsRequest, ListTopicsResponse, Topic>
138-
listTopicsMethod;
139-
private final PageStreamingApiCallableBuilder<
140-
ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String>
141-
listTopicSubscriptionsMethod;
142-
private final ApiCallableBuilder<DeleteTopicRequest, Empty> deleteTopicMethod;
143-
private final ImmutableList<? extends ApiCallSettings> allMethods;
135+
private static class MethodBuilders {
136+
public final ApiCallableBuilder<Topic, Topic> createTopicMethod;
137+
public final ApiCallableBuilder<PublishRequest, PublishResponse> publishMethod;
138+
public final ApiCallableBuilder<GetTopicRequest, Topic> getTopicMethod;
139+
public final PageStreamingApiCallableBuilder<ListTopicsRequest, ListTopicsResponse, Topic>
140+
listTopicsMethod;
141+
public final PageStreamingApiCallableBuilder<
142+
ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String>
143+
listTopicSubscriptionsMethod;
144+
public final ApiCallableBuilder<DeleteTopicRequest, Empty> deleteTopicMethod;
145+
public final ImmutableList<? extends ApiCallSettings> allMethods;
146+
147+
public MethodBuilders() {
148+
createTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_CREATE_TOPIC);
149+
createTopicMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"));
150+
createTopicMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default"));
151+
152+
publishMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_PUBLISH);
153+
publishMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"));
154+
publishMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default"));
155+
156+
getTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_GET_TOPIC);
157+
getTopicMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"));
158+
getTopicMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default"));
159+
160+
listTopicsMethod =
161+
new PageStreamingApiCallableBuilder<>(
162+
PublisherGrpc.METHOD_LIST_TOPICS, LIST_TOPICS_PAGE_STR_DESC);
163+
listTopicsMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"));
164+
listTopicsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default"));
165+
166+
listTopicSubscriptionsMethod =
167+
new PageStreamingApiCallableBuilder<>(
168+
PublisherGrpc.METHOD_LIST_TOPIC_SUBSCRIPTIONS, LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_DESC);
169+
listTopicsMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"));
170+
listTopicsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default"));
171+
172+
deleteTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_DELETE_TOPIC);
173+
deleteTopicMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"));
174+
deleteTopicMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default"));
175+
176+
allMethods =
177+
ImmutableList.<ApiCallSettings>builder()
178+
.add(
179+
createTopicMethod,
180+
publishMethod,
181+
getTopicMethod,
182+
listTopicsMethod,
183+
listTopicSubscriptionsMethod,
184+
deleteTopicMethod)
185+
.build();
186+
}
187+
}
188+
189+
private final MethodBuilders methods;
144190

145191
// ===============
146192
// Factory Methods
@@ -153,7 +199,7 @@ public class PublisherSettings extends ApiCallSettings {
153199
* <!-- end manual edit -->
154200
*/
155201
public static PublisherSettings create() {
156-
PublisherSettings settings = new PublisherSettings();
202+
PublisherSettings settings = new PublisherSettings(new MethodBuilders());
157203
settings.provideChannelWith(
158204
ConnectionSettings.builder()
159205
.setServiceAddress(DEFAULT_SERVICE_ADDRESS)
@@ -170,45 +216,9 @@ public static PublisherSettings create() {
170216
* <!-- manual edit -->
171217
* <!-- end manual edit -->
172218
*/
173-
protected PublisherSettings() {
174-
createTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_CREATE_TOPIC);
175-
createTopicMethod.setRetryDefaults(
176-
RETRYABLE_CODE_DEFINITIONS.get("idempotent"), RETRY_PARAM_DEFINITIONS.get("default"));
177-
178-
publishMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_PUBLISH);
179-
publishMethod.setRetryDefaults(
180-
RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"), RETRY_PARAM_DEFINITIONS.get("default"));
181-
182-
getTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_GET_TOPIC);
183-
getTopicMethod.setRetryDefaults(
184-
RETRYABLE_CODE_DEFINITIONS.get("idempotent"), RETRY_PARAM_DEFINITIONS.get("default"));
185-
186-
listTopicsMethod =
187-
new PageStreamingApiCallableBuilder<>(
188-
PublisherGrpc.METHOD_LIST_TOPICS, LIST_TOPICS_PAGE_STR_DESC);
189-
listTopicsMethod.setRetryDefaults(
190-
RETRYABLE_CODE_DEFINITIONS.get("idempotent"), RETRY_PARAM_DEFINITIONS.get("default"));
191-
192-
listTopicSubscriptionsMethod =
193-
new PageStreamingApiCallableBuilder<>(
194-
PublisherGrpc.METHOD_LIST_TOPIC_SUBSCRIPTIONS, LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_DESC);
195-
listTopicSubscriptionsMethod.setRetryDefaults(
196-
RETRYABLE_CODE_DEFINITIONS.get("idempotent"), RETRY_PARAM_DEFINITIONS.get("default"));
197-
198-
deleteTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_DELETE_TOPIC);
199-
deleteTopicMethod.setRetryDefaults(
200-
RETRYABLE_CODE_DEFINITIONS.get("idempotent"), RETRY_PARAM_DEFINITIONS.get("default"));
201-
202-
allMethods =
203-
ImmutableList.<ApiCallSettings>builder()
204-
.add(
205-
createTopicMethod,
206-
publishMethod,
207-
getTopicMethod,
208-
listTopicsMethod,
209-
listTopicSubscriptionsMethod,
210-
deleteTopicMethod)
211-
.build();
219+
protected PublisherSettings(MethodBuilders methods) {
220+
super(methods.allMethods);
221+
this.methods = methods;
212222
}
213223

214224
/**
@@ -218,7 +228,7 @@ protected PublisherSettings() {
218228
* <!-- end manual edit -->
219229
*/
220230
public ApiCallableBuilder<Topic, Topic> createTopicMethod() {
221-
return createTopicMethod;
231+
return methods.createTopicMethod;
222232
}
223233

224234
/**
@@ -228,7 +238,7 @@ public ApiCallableBuilder<Topic, Topic> createTopicMethod() {
228238
* <!-- end manual edit -->
229239
*/
230240
public ApiCallableBuilder<PublishRequest, PublishResponse> publishMethod() {
231-
return publishMethod;
241+
return methods.publishMethod;
232242
}
233243

234244
/**
@@ -238,7 +248,7 @@ public ApiCallableBuilder<PublishRequest, PublishResponse> publishMethod() {
238248
* <!-- end manual edit -->
239249
*/
240250
public ApiCallableBuilder<GetTopicRequest, Topic> getTopicMethod() {
241-
return getTopicMethod;
251+
return methods.getTopicMethod;
242252
}
243253

244254
/**
@@ -249,7 +259,7 @@ public ApiCallableBuilder<GetTopicRequest, Topic> getTopicMethod() {
249259
*/
250260
public PageStreamingApiCallableBuilder<ListTopicsRequest, ListTopicsResponse, Topic>
251261
listTopicsMethod() {
252-
return listTopicsMethod;
262+
return methods.listTopicsMethod;
253263
}
254264

255265
/**
@@ -261,7 +271,7 @@ public ApiCallableBuilder<GetTopicRequest, Topic> getTopicMethod() {
261271
public PageStreamingApiCallableBuilder<
262272
ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String>
263273
listTopicSubscriptionsMethod() {
264-
return listTopicSubscriptionsMethod;
274+
return methods.listTopicSubscriptionsMethod;
265275
}
266276

267277
/**
@@ -271,11 +281,7 @@ public ApiCallableBuilder<GetTopicRequest, Topic> getTopicMethod() {
271281
* <!-- end manual edit -->
272282
*/
273283
public ApiCallableBuilder<DeleteTopicRequest, Empty> deleteTopicMethod() {
274-
return deleteTopicMethod;
275-
}
276-
277-
public ImmutableList<? extends ApiCallSettings> allMethods() {
278-
return allMethods;
284+
return methods.deleteTopicMethod;
279285
}
280286

281287
private static PageDescriptor<ListTopicsRequest, ListTopicsResponse, Topic>

gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/SubscriberApi.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,6 @@ public static SubscriberApi create(SubscriberSettings settings) throws IOExcepti
216216
protected SubscriberApi(SubscriberSettings settings) throws IOException {
217217
this.channel = settings.getChannel();
218218

219-
for (ApiCallSettings method : settings.allMethods()) {
220-
if (method.getExecutor() == null) {
221-
method.setExecutor(settings.getExecutor());
222-
}
223-
}
224-
225219
this.createSubscriptionCallable = settings.createSubscriptionMethod().build(settings);
226220
this.getSubscriptionCallable = settings.getSubscriptionMethod().build(settings);
227221
this.listSubscriptionsCallable = settings.listSubscriptionsMethod().build(settings);

0 commit comments

Comments
 (0)