Skip to content

Commit b2115f3

Browse files
Regenerating code, new settings classes
* Moving settings constants and data into new settings classes * Making use of ApiCallableBuilder in the new settings classes * Simplifying the Api classes
1 parent d549d3f commit b2115f3

10 files changed

Lines changed: 2811 additions & 514 deletions

File tree

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

Lines changed: 555 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
/*
16+
* EDITING INSTRUCTIONS
17+
* This file was generated from the file
18+
* https://github.com/google/googleapis/blob/master/google/pubsub/v1/pubsub.proto
19+
* and updates to that file get reflected here through a refresh process.
20+
* For the short term, the refresh process will only be runnable by Google engineers.
21+
* Manual additions are allowed because the refresh process performs
22+
* a 3-way merge in order to preserve those manual additions. In order to not
23+
* break the refresh process, only certain types of modifications are
24+
* allowed.
25+
*
26+
* Allowed modifications - currently these are the only types allowed:
27+
* 1. New methods (these should be added to the end of the class)
28+
* 2. New imports
29+
* 3. Additional documentation between "manual edit" demarcations
30+
*
31+
* Happy editing!
32+
*/
33+
34+
package com.google.gcloud.pubsub.spi;
35+
36+
import com.google.api.gax.core.BackoffParams;
37+
import com.google.api.gax.core.ConnectionSettings;
38+
import com.google.api.gax.core.RetryParams;
39+
import com.google.api.gax.grpc.ApiCallSettings;
40+
import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder;
41+
import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder;
42+
import com.google.api.gax.grpc.PageDescriptor;
43+
import com.google.common.collect.ImmutableList;
44+
import com.google.common.collect.ImmutableMap;
45+
import com.google.common.collect.ImmutableSet;
46+
import com.google.common.collect.Lists;
47+
import com.google.common.collect.Sets;
48+
import com.google.protobuf.Empty;
49+
import com.google.pubsub.v1.DeleteTopicRequest;
50+
import com.google.pubsub.v1.GetTopicRequest;
51+
import com.google.pubsub.v1.ListTopicSubscriptionsRequest;
52+
import com.google.pubsub.v1.ListTopicSubscriptionsResponse;
53+
import com.google.pubsub.v1.ListTopicsRequest;
54+
import com.google.pubsub.v1.ListTopicsResponse;
55+
import com.google.pubsub.v1.PublishRequest;
56+
import com.google.pubsub.v1.PublishResponse;
57+
import com.google.pubsub.v1.PublisherGrpc;
58+
import com.google.pubsub.v1.Topic;
59+
import io.grpc.Status;
60+
61+
// Manually-added imports: add custom (non-generated) imports after this point.
62+
63+
// AUTO-GENERATED DOCUMENTATION AND CLASS - see instructions at the top of the file for editing.
64+
@javax.annotation.Generated("by GAPIC")
65+
public class PublisherSettings extends ApiCallSettings {
66+
67+
// =========
68+
// Constants
69+
// =========
70+
71+
/**
72+
* The default address of the service.
73+
*
74+
* <!-- manual edit -->
75+
* <!-- end manual edit -->
76+
*/
77+
public static final String DEFAULT_SERVICE_ADDRESS = "pubsub-experimental.googleapis.com";
78+
79+
/**
80+
* The default port of the service.
81+
*
82+
* <!-- manual edit -->
83+
* <!-- end manual edit -->
84+
*/
85+
public static final int DEFAULT_SERVICE_PORT = 443;
86+
87+
/**
88+
* The default scopes of the service.
89+
*/
90+
public static ImmutableList<String> DEFAULT_SERVICE_SCOPES =
91+
ImmutableList.<String>builder()
92+
.add("https://www.googleapis.com/auth/pubsub")
93+
.add("https://www.googleapis.com/auth/cloud-platform")
94+
.build();
95+
96+
private static final ImmutableMap<String, ImmutableSet<Status.Code>> RETRYABLE_CODE_DEFINITIONS;
97+
98+
static {
99+
ImmutableMap.Builder<String, ImmutableSet<Status.Code>> definitions = ImmutableMap.builder();
100+
definitions.put(
101+
"idempotent",
102+
Sets.immutableEnumSet(
103+
Lists.<Status.Code>newArrayList(
104+
Status.Code.DEADLINE_EXCEEDED, Status.Code.UNAVAILABLE)));
105+
definitions.put("non_idempotent", Sets.immutableEnumSet(Lists.<Status.Code>newArrayList()));
106+
RETRYABLE_CODE_DEFINITIONS = definitions.build();
107+
}
108+
109+
private static final ImmutableMap<String, RetryParams> RETRY_PARAM_DEFINITIONS;
110+
111+
static {
112+
ImmutableMap.Builder<String, RetryParams> definitions = ImmutableMap.builder();
113+
RetryParams params = null;
114+
params =
115+
RetryParams.newBuilder()
116+
.setRetryBackoff(
117+
BackoffParams.newBuilder()
118+
.setInitialDelayMillis(100L)
119+
.setDelayMultiplier(1.2)
120+
.setMaxDelayMillis(1000L)
121+
.build())
122+
.setTimeoutBackoff(
123+
BackoffParams.newBuilder()
124+
.setInitialDelayMillis(300L)
125+
.setDelayMultiplier(1.3)
126+
.setMaxDelayMillis(3000L)
127+
.build())
128+
.setTotalTimeout(30000L)
129+
.build();
130+
definitions.put("default", params);
131+
RETRY_PARAM_DEFINITIONS = definitions.build();
132+
}
133+
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;
144+
145+
// ===============
146+
// Factory Methods
147+
// ===============
148+
149+
/**
150+
* Constructs an instance of PublisherSettings with default settings.
151+
*
152+
* <!-- manual edit -->
153+
* <!-- end manual edit -->
154+
*/
155+
public static PublisherSettings create() {
156+
PublisherSettings settings = new PublisherSettings();
157+
settings.provideChannelWith(
158+
ConnectionSettings.builder()
159+
.setServiceAddress(DEFAULT_SERVICE_ADDRESS)
160+
.setPort(DEFAULT_SERVICE_PORT)
161+
.provideCredentialsWith(DEFAULT_SERVICE_SCOPES)
162+
.build());
163+
return settings;
164+
}
165+
166+
/**
167+
* Constructs an instance of PublisherSettings with default settings. This is protected so that it
168+
* easy to make a subclass, but otherwise, the static factory methods should be preferred.
169+
*
170+
* <!-- manual edit -->
171+
* <!-- end manual edit -->
172+
*/
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();
212+
}
213+
214+
/**
215+
* Returns the ApiCallableBuilder for the API method createTopic.
216+
*
217+
* <!-- manual edit -->
218+
* <!-- end manual edit -->
219+
*/
220+
public ApiCallableBuilder<Topic, Topic> createTopicMethod() {
221+
return createTopicMethod;
222+
}
223+
224+
/**
225+
* Returns the ApiCallableBuilder for the API method publish.
226+
*
227+
* <!-- manual edit -->
228+
* <!-- end manual edit -->
229+
*/
230+
public ApiCallableBuilder<PublishRequest, PublishResponse> publishMethod() {
231+
return publishMethod;
232+
}
233+
234+
/**
235+
* Returns the ApiCallableBuilder for the API method getTopic.
236+
*
237+
* <!-- manual edit -->
238+
* <!-- end manual edit -->
239+
*/
240+
public ApiCallableBuilder<GetTopicRequest, Topic> getTopicMethod() {
241+
return getTopicMethod;
242+
}
243+
244+
/**
245+
* Returns the PageStreamingApiCallableBuilder for the API method listTopics.
246+
*
247+
* <!-- manual edit -->
248+
* <!-- end manual edit -->
249+
*/
250+
public PageStreamingApiCallableBuilder<ListTopicsRequest, ListTopicsResponse, Topic>
251+
listTopicsMethod() {
252+
return listTopicsMethod;
253+
}
254+
255+
/**
256+
* Returns the PageStreamingApiCallableBuilder for the API method listTopicSubscriptions.
257+
*
258+
* <!-- manual edit -->
259+
* <!-- end manual edit -->
260+
*/
261+
public PageStreamingApiCallableBuilder<
262+
ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String>
263+
listTopicSubscriptionsMethod() {
264+
return listTopicSubscriptionsMethod;
265+
}
266+
267+
/**
268+
* Returns the ApiCallableBuilder for the API method deleteTopic.
269+
*
270+
* <!-- manual edit -->
271+
* <!-- end manual edit -->
272+
*/
273+
public ApiCallableBuilder<DeleteTopicRequest, Empty> deleteTopicMethod() {
274+
return deleteTopicMethod;
275+
}
276+
277+
public ImmutableList<? extends ApiCallSettings> allMethods() {
278+
return allMethods;
279+
}
280+
281+
private static PageDescriptor<ListTopicsRequest, ListTopicsResponse, Topic>
282+
LIST_TOPICS_PAGE_STR_DESC =
283+
new PageDescriptor<ListTopicsRequest, ListTopicsResponse, Topic>() {
284+
@Override
285+
public Object emptyToken() {
286+
return "";
287+
}
288+
289+
@Override
290+
public ListTopicsRequest injectToken(ListTopicsRequest payload, Object token) {
291+
return ListTopicsRequest.newBuilder(payload).setPageToken((String) token).build();
292+
}
293+
294+
@Override
295+
public Object extractNextToken(ListTopicsResponse payload) {
296+
return payload.getNextPageToken();
297+
}
298+
299+
@Override
300+
public Iterable<Topic> extractResources(ListTopicsResponse payload) {
301+
return payload.getTopicsList();
302+
}
303+
};
304+
305+
private static PageDescriptor<
306+
ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String>
307+
LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_DESC =
308+
new PageDescriptor<
309+
ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String>() {
310+
@Override
311+
public Object emptyToken() {
312+
return "";
313+
}
314+
315+
@Override
316+
public ListTopicSubscriptionsRequest injectToken(
317+
ListTopicSubscriptionsRequest payload, Object token) {
318+
return ListTopicSubscriptionsRequest.newBuilder(payload)
319+
.setPageToken((String) token)
320+
.build();
321+
}
322+
323+
@Override
324+
public Object extractNextToken(ListTopicSubscriptionsResponse payload) {
325+
return payload.getNextPageToken();
326+
}
327+
328+
@Override
329+
public Iterable<String> extractResources(ListTopicSubscriptionsResponse payload) {
330+
return payload.getSubscriptionsList();
331+
}
332+
};
333+
}

0 commit comments

Comments
 (0)