From 8e884fda92f9e3af1a657bb31cdb91cbfaccb461 Mon Sep 17 00:00:00 2001 From: Shin Fan Date: Mon, 28 Mar 2016 15:53:51 -0700 Subject: [PATCH] Update with latest surface fixes based Java export review. Refactorings: - 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 - Update unit tests - Update pom and dependency --- .../gcloud/pubsub/spi/v1/PublisherApi.java | 219 ++++++++--------- .../pubsub/spi/v1/PublisherSettings.java | 76 +++--- .../gcloud/pubsub/spi/v1/SubscriberApi.java | 225 ++++++++---------- .../pubsub/spi/v1/SubscriberSettings.java | 76 +++--- gcloud-java-pubsub/pom.xml | 24 +- .../gcloud/pubsub/spi/v1/PublisherApi.java | 219 ++++++++--------- .../pubsub/spi/v1/PublisherSettings.java | 76 +++--- .../gcloud/pubsub/spi/v1/SubscriberApi.java | 225 ++++++++---------- .../pubsub/spi/v1/SubscriberSettings.java | 76 +++--- .../pubsub/spi/v1/PublisherApiTest.java | 66 ++--- 10 files changed, 577 insertions(+), 705 deletions(-) diff --git a/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherApi.java b/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherApi.java index fa6da27a72bd..8394e5ae74ed 100644 --- a/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherApi.java +++ b/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherApi.java @@ -66,10 +66,6 @@ */ @javax.annotation.Generated("by GAPIC") public class PublisherApi implements AutoCloseable { - // ======== - // Members - // ======== - private final ManagedChannel channel; private final List closeables = new ArrayList<>(); @@ -84,97 +80,80 @@ public class PublisherApi implements AutoCloseable { listTopicSubscriptionsIterableCallable; private final ApiCallable deleteTopicCallable; - public static class ResourceNames { - - // ======================= - // ResourceNames Constants - // ======================= - - /** - * A PathTemplate representing the fully-qualified path to represent - * a project resource. - * - * - * - */ - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.create("projects/{project}"); - - /** - * A PathTemplate representing the fully-qualified path to represent - * a topic resource. - * - * - * - */ - private static final PathTemplate TOPIC_PATH_TEMPLATE = - PathTemplate.create("projects/{project}/topics/{topic}"); - - private ResourceNames() {} - - // ============================== - // Resource Name Helper Functions - // ============================== - - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * - * - */ - public static final String formatProjectPath(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } + /** + * A PathTemplate representing the fully-qualified path to represent + * a project resource. + * + * + * + */ + private static final PathTemplate PROJECT_PATH_TEMPLATE = + PathTemplate.create("projects/{project}"); - /** - * Formats a string containing the fully-qualified path to represent - * a topic resource. - * - * - * - */ - public static final String formatTopicPath(String project, String topic) { - return TOPIC_PATH_TEMPLATE.instantiate("project", project, "topic", topic); - } + /** + * A PathTemplate representing the fully-qualified path to represent + * a topic resource. + * + * + * + */ + private static final PathTemplate TOPIC_PATH_TEMPLATE = + PathTemplate.create("projects/{project}/topics/{topic}"); - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * - * - */ - public static final String parseProjectFromProjectPath(String projectPath) { - return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project"); - } + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * + * + */ + public static final String formatProjectName(String project) { + return PROJECT_PATH_TEMPLATE.instantiate("project", project); + } - /** - * Parses the project from the given fully-qualified path which - * represents a topic resource. - * - * - * - */ - public static final String parseProjectFromTopicPath(String topicPath) { - return TOPIC_PATH_TEMPLATE.parse(topicPath).get("project"); - } + /** + * Formats a string containing the fully-qualified path to represent + * a topic resource. + * + * + * + */ + public static final String formatTopicName(String project, String topic) { + return TOPIC_PATH_TEMPLATE.instantiate("project", project, "topic", topic); + } - /** - * Parses the topic from the given fully-qualified path which - * represents a topic resource. - * - * - * - */ - public static final String parseTopicFromTopicPath(String topicPath) { - return TOPIC_PATH_TEMPLATE.parse(topicPath).get("topic"); - } + /** + * Parses the project from the given fully-qualified path which + * represents a project resource. + * + * + * + */ + public static final String parseProjectFromProjectName(String projectName) { + return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a topic resource. + * + * + * + */ + public static final String parseProjectFromTopicName(String topicName) { + return TOPIC_PATH_TEMPLATE.parse(topicName).get("project"); } - // =============== - // Factory Methods - // =============== + /** + * Parses the topic from the given fully-qualified path which + * represents a topic resource. + * + * + * + */ + public static final String parseTopicFromTopicName(String topicName) { + return TOPIC_PATH_TEMPLATE.parse(topicName).get("topic"); + } /** * Constructs an instance of PublisherApi with default settings. @@ -182,7 +161,7 @@ public static final String parseTopicFromTopicPath(String topicPath) { * * */ - public static PublisherApi create() throws IOException { + public static final PublisherApi create() throws IOException { return create(PublisherSettings.create()); } @@ -194,7 +173,7 @@ public static PublisherApi create() throws IOException { * * */ - public static PublisherApi create(PublisherSettings settings) throws IOException { + public static final PublisherApi create(PublisherSettings settings) throws IOException { return new PublisherApi(settings); } @@ -226,19 +205,17 @@ protected PublisherApi(PublisherSettings settings) throws IOException { settings.listTopicSubscriptionsMethod().buildPageStreaming(settings); this.deleteTopicCallable = settings.deleteTopicMethod().build(settings); - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - channel.shutdown(); - } - }); + if (settings.shouldAutoCloseChannel()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + channel.shutdown(); + } + }); + } } - // ============= - // Service Calls - // ============= - // ----- createTopic ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -255,7 +232,7 @@ public void close() throws IOException { * signs (`%`). It must be between 3 and 255 characters in length, and it * must not start with `"goog"`. */ - public Topic createTopic(String name) { + public final Topic createTopic(String name) { Topic request = Topic.newBuilder().setName(name).build(); return createTopic(request); @@ -281,7 +258,7 @@ private Topic createTopic(Topic request) { * * */ - public ApiCallable createTopicCallable() { + public final ApiCallable createTopicCallable() { return createTopicCallable; } @@ -299,7 +276,7 @@ public ApiCallable createTopicCallable() { * @param topic The messages in the request will be published on this topic. * @param messages The messages to publish. */ - public PublishResponse publish(String topic, List messages) { + public final PublishResponse publish(String topic, List messages) { PublishRequest request = PublishRequest.newBuilder().setTopic(topic).addAllMessages(messages).build(); @@ -330,7 +307,7 @@ public PublishResponse publish(PublishRequest request) { * * */ - public ApiCallable publishCallable() { + public final ApiCallable publishCallable() { return publishCallable; } @@ -345,7 +322,7 @@ public ApiCallable publishCallable() { * * @param topic The name of the topic to get. */ - public Topic getTopic(String topic) { + public final Topic getTopic(String topic) { GetTopicRequest request = GetTopicRequest.newBuilder().setTopic(topic).build(); return getTopic(request); @@ -371,7 +348,7 @@ private Topic getTopic(GetTopicRequest request) { * * */ - public ApiCallable getTopicCallable() { + public final ApiCallable getTopicCallable() { return getTopicCallable; } @@ -384,7 +361,7 @@ public ApiCallable getTopicCallable() { * * */ - public Iterable listTopics(String project) { + public final Iterable listTopics(String project) { ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(project).build(); return listTopics(request); } @@ -398,7 +375,7 @@ public Iterable listTopics(String project) { * * @param request The request object containing all of the parameters for the API call. */ - public Iterable listTopics(ListTopicsRequest request) { + public final Iterable listTopics(ListTopicsRequest request) { return listTopicsIterableCallable().call(request); } @@ -409,7 +386,7 @@ public Iterable listTopics(ListTopicsRequest request) { * * */ - public ApiCallable> listTopicsIterableCallable() { + public final ApiCallable> listTopicsIterableCallable() { return listTopicsIterableCallable; } @@ -420,7 +397,7 @@ public ApiCallable> listTopicsIterableCallabl * * */ - public ApiCallable listTopicsCallable() { + public final ApiCallable listTopicsCallable() { return listTopicsCallable; } @@ -433,7 +410,7 @@ public ApiCallable listTopicsCallable() { * * */ - public Iterable listTopicSubscriptions(String topic) { + public final Iterable listTopicSubscriptions(String topic) { ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder().setTopic(topic).build(); return listTopicSubscriptions(request); @@ -448,7 +425,7 @@ public Iterable listTopicSubscriptions(String topic) { * * @param request The request object containing all of the parameters for the API call. */ - public Iterable listTopicSubscriptions(ListTopicSubscriptionsRequest request) { + public final Iterable listTopicSubscriptions(ListTopicSubscriptionsRequest request) { return listTopicSubscriptionsIterableCallable().call(request); } @@ -459,7 +436,7 @@ public Iterable listTopicSubscriptions(ListTopicSubscriptionsRequest req * * */ - public ApiCallable> + public final ApiCallable> listTopicSubscriptionsIterableCallable() { return listTopicSubscriptionsIterableCallable; } @@ -471,7 +448,7 @@ public Iterable listTopicSubscriptions(ListTopicSubscriptionsRequest req * * */ - public ApiCallable + public final ApiCallable listTopicSubscriptionsCallable() { return listTopicSubscriptionsCallable; } @@ -491,7 +468,7 @@ public Iterable listTopicSubscriptions(ListTopicSubscriptionsRequest req * * @param topic Name of the topic to delete. */ - public void deleteTopic(String topic) { + public final void deleteTopic(String topic) { DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopic(topic).build(); deleteTopic(request); @@ -525,14 +502,10 @@ private void deleteTopic(DeleteTopicRequest request) { * * */ - public ApiCallable deleteTopicCallable() { + public final ApiCallable deleteTopicCallable() { return deleteTopicCallable; } - // ======== - // Cleanup - // ======== - /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. @@ -541,7 +514,7 @@ public ApiCallable deleteTopicCallable() { * */ @Override - public void close() throws Exception { + public final void close() throws Exception { for (AutoCloseable closeable : closeables) { closeable.close(); } diff --git a/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherSettings.java b/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherSettings.java index 11566404546f..8b3d434b8e49 100644 --- a/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherSettings.java +++ b/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherSettings.java @@ -37,10 +37,12 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetryParams; import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.BundlableApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder; +import com.google.api.gax.grpc.ApiCallable; +import com.google.api.gax.grpc.ApiCallable.Builder; +import com.google.api.gax.grpc.ApiCallable.BundlableBuilder; +import com.google.api.gax.grpc.ApiCallable.PageStreamingBuilder; import com.google.api.gax.grpc.BundlingDescriptor; +import com.google.api.gax.grpc.BundlingSettings; import com.google.api.gax.grpc.PageStreamingDescriptor; import com.google.api.gax.grpc.RequestIssuer; import com.google.api.gax.grpc.ServiceApiSettings; @@ -65,6 +67,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.joda.time.Duration; // Manually-added imports: add custom (non-generated) imports after this point. @@ -72,10 +75,6 @@ @javax.annotation.Generated("by GAPIC") public class PublisherSettings extends ServiceApiSettings { - // ========= - // Constants - // ========= - /** * The default address of the service. * @@ -123,17 +122,17 @@ public class PublisherSettings extends ServiceApiSettings { RetryParams.newBuilder() .setRetryBackoff( BackoffParams.newBuilder() - .setInitialDelayMillis(100L) + .setInitialDelay(Duration.millis(100L)) .setDelayMultiplier(1.2) - .setMaxDelayMillis(1000L) + .setMaxDelay(Duration.millis(1000L)) .build()) .setTimeoutBackoff( BackoffParams.newBuilder() - .setInitialDelayMillis(300L) - .setDelayMultiplier(1.3) - .setMaxDelayMillis(3000L) + .setInitialDelay(Duration.millis(2000L)) + .setDelayMultiplier(1.5) + .setMaxDelay(Duration.millis(30000L)) .build()) - .setTotalTimeout(30000L) + .setTotalTimeout(Duration.millis(45000L)) .build(); definitions.put("default", params); RETRY_PARAM_DEFINITIONS = definitions.build(); @@ -142,45 +141,54 @@ public class PublisherSettings extends ServiceApiSettings { private final MethodBuilders methods; private static class MethodBuilders { - private final ApiCallableBuilder createTopicMethod; - private final BundlableApiCallableBuilder publishMethod; - private final ApiCallableBuilder getTopicMethod; - private final PageStreamingApiCallableBuilder + private final ApiCallable.Builder createTopicMethod; + private final ApiCallable.BundlableBuilder publishMethod; + private final ApiCallable.Builder getTopicMethod; + private final ApiCallable.PageStreamingBuilder listTopicsMethod; - private final PageStreamingApiCallableBuilder< + private final ApiCallable.PageStreamingBuilder< ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> listTopicSubscriptionsMethod; - private final ApiCallableBuilder deleteTopicMethod; + private final ApiCallable.Builder deleteTopicMethod; private final ImmutableList allMethods; public MethodBuilders() { - createTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_CREATE_TOPIC); + createTopicMethod = new Builder<>(PublisherGrpc.METHOD_CREATE_TOPIC); createTopicMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); createTopicMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); + BundlingSettings publishBundlingSettings = + BundlingSettings.newBuilder() + .setElementCountThreshold(800) + .setElementCountLimit(1000) + .setRequestByteThreshold(8388608) + .setRequestByteLimit(10485760) + .setDelayThreshold(Duration.millis(100)) + .setBlockingCallCountThreshold(1) + .build(); publishMethod = - new BundlableApiCallableBuilder<>(PublisherGrpc.METHOD_PUBLISH, PUBLISH_BUNDLING_DESC); + new BundlableBuilder<>( + PublisherGrpc.METHOD_PUBLISH, PUBLISH_BUNDLING_DESC, publishBundlingSettings); publishMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); publishMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - getTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_GET_TOPIC); + getTopicMethod = new Builder<>(PublisherGrpc.METHOD_GET_TOPIC); getTopicMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); getTopicMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); listTopicsMethod = - new PageStreamingApiCallableBuilder<>( - PublisherGrpc.METHOD_LIST_TOPICS, LIST_TOPICS_PAGE_STR_DESC); + new PageStreamingBuilder<>(PublisherGrpc.METHOD_LIST_TOPICS, LIST_TOPICS_PAGE_STR_DESC); listTopicsMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); listTopicsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); listTopicSubscriptionsMethod = - new PageStreamingApiCallableBuilder<>( + new PageStreamingBuilder<>( PublisherGrpc.METHOD_LIST_TOPIC_SUBSCRIPTIONS, LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_DESC); listTopicSubscriptionsMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); listTopicSubscriptionsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - deleteTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_DELETE_TOPIC); + deleteTopicMethod = new Builder<>(PublisherGrpc.METHOD_DELETE_TOPIC); deleteTopicMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); deleteTopicMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); @@ -197,10 +205,6 @@ public MethodBuilders() { } } - // =============== - // Factory Methods - // =============== - /** * Constructs an instance of PublisherSettings with default settings. * @@ -237,7 +241,7 @@ protected PublisherSettings(MethodBuilders methods) { * * */ - public ApiCallableBuilder createTopicMethod() { + public final ApiCallable.Builder createTopicMethod() { return methods.createTopicMethod; } @@ -247,7 +251,7 @@ public ApiCallableBuilder createTopicMethod() { * * */ - public BundlableApiCallableBuilder publishMethod() { + public final ApiCallable.BundlableBuilder publishMethod() { return methods.publishMethod; } @@ -257,7 +261,7 @@ public BundlableApiCallableBuilder publishMetho * * */ - public ApiCallableBuilder getTopicMethod() { + public final ApiCallable.Builder getTopicMethod() { return methods.getTopicMethod; } @@ -267,7 +271,7 @@ public ApiCallableBuilder getTopicMethod() { * * */ - public PageStreamingApiCallableBuilder + public final ApiCallable.PageStreamingBuilder listTopicsMethod() { return methods.listTopicsMethod; } @@ -278,7 +282,7 @@ public ApiCallableBuilder getTopicMethod() { * * */ - public PageStreamingApiCallableBuilder< + public final ApiCallable.PageStreamingBuilder< ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> listTopicSubscriptionsMethod() { return methods.listTopicSubscriptionsMethod; @@ -290,7 +294,7 @@ public ApiCallableBuilder getTopicMethod() { * * */ - public ApiCallableBuilder deleteTopicMethod() { + public final ApiCallable.Builder deleteTopicMethod() { return methods.deleteTopicMethod; } diff --git a/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberApi.java b/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberApi.java index d53dca7f8885..3040af41efd8 100644 --- a/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberApi.java +++ b/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberApi.java @@ -65,10 +65,6 @@ */ @javax.annotation.Generated("by GAPIC") public class SubscriberApi implements AutoCloseable { - // ======== - // Members - // ======== - private final ManagedChannel channel; private final List closeables = new ArrayList<>(); @@ -84,98 +80,80 @@ public class SubscriberApi implements AutoCloseable { private final ApiCallable pullCallable; private final ApiCallable modifyPushConfigCallable; - public static class ResourceNames { - - // ======================= - // ResourceNames Constants - // ======================= - - /** - * A PathTemplate representing the fully-qualified path to represent - * a project resource. - * - * - * - */ - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.create("projects/{project}"); - - /** - * A PathTemplate representing the fully-qualified path to represent - * a subscription resource. - * - * - * - */ - private static final PathTemplate SUBSCRIPTION_PATH_TEMPLATE = - PathTemplate.create("projects/{project}/subscriptions/{subscription}"); - - private ResourceNames() {} - - // ============================== - // Resource Name Helper Functions - // ============================== - - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * - * - */ - public static final String formatProjectPath(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } + /** + * A PathTemplate representing the fully-qualified path to represent + * a project resource. + * + * + * + */ + private static final PathTemplate PROJECT_PATH_TEMPLATE = + PathTemplate.create("projects/{project}"); - /** - * Formats a string containing the fully-qualified path to represent - * a subscription resource. - * - * - * - */ - public static final String formatSubscriptionPath(String project, String subscription) { - return SUBSCRIPTION_PATH_TEMPLATE.instantiate( - "project", project, "subscription", subscription); - } + /** + * A PathTemplate representing the fully-qualified path to represent + * a subscription resource. + * + * + * + */ + private static final PathTemplate SUBSCRIPTION_PATH_TEMPLATE = + PathTemplate.create("projects/{project}/subscriptions/{subscription}"); - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * - * - */ - public static final String parseProjectFromProjectPath(String projectPath) { - return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project"); - } + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * + * + */ + public static final String formatProjectName(String project) { + return PROJECT_PATH_TEMPLATE.instantiate("project", project); + } - /** - * Parses the project from the given fully-qualified path which - * represents a subscription resource. - * - * - * - */ - public static final String parseProjectFromSubscriptionPath(String subscriptionPath) { - return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionPath).get("project"); - } + /** + * Formats a string containing the fully-qualified path to represent + * a subscription resource. + * + * + * + */ + public static final String formatSubscriptionName(String project, String subscription) { + return SUBSCRIPTION_PATH_TEMPLATE.instantiate("project", project, "subscription", subscription); + } - /** - * Parses the subscription from the given fully-qualified path which - * represents a subscription resource. - * - * - * - */ - public static final String parseSubscriptionFromSubscriptionPath(String subscriptionPath) { - return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionPath).get("subscription"); - } + /** + * Parses the project from the given fully-qualified path which + * represents a project resource. + * + * + * + */ + public static final String parseProjectFromProjectName(String projectName) { + return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a subscription resource. + * + * + * + */ + public static final String parseProjectFromSubscriptionName(String subscriptionName) { + return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionName).get("project"); } - // =============== - // Factory Methods - // =============== + /** + * Parses the subscription from the given fully-qualified path which + * represents a subscription resource. + * + * + * + */ + public static final String parseSubscriptionFromSubscriptionName(String subscriptionName) { + return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionName).get("subscription"); + } /** * Constructs an instance of SubscriberApi with default settings. @@ -183,7 +161,7 @@ public static final String parseSubscriptionFromSubscriptionPath(String subscrip * * */ - public static SubscriberApi create() throws IOException { + public static final SubscriberApi create() throws IOException { return create(SubscriberSettings.create()); } @@ -195,7 +173,7 @@ public static SubscriberApi create() throws IOException { * * */ - public static SubscriberApi create(SubscriberSettings settings) throws IOException { + public static final SubscriberApi create(SubscriberSettings settings) throws IOException { return new SubscriberApi(settings); } @@ -221,19 +199,17 @@ protected SubscriberApi(SubscriberSettings settings) throws IOException { this.pullCallable = settings.pullMethod().build(settings); this.modifyPushConfigCallable = settings.modifyPushConfigMethod().build(settings); - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - channel.shutdown(); - } - }); + if (settings.shouldAutoCloseChannel()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + channel.shutdown(); + } + }); + } } - // ============= - // Service Calls - // ============= - // ----- createSubscription ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -277,7 +253,7 @@ public void close() throws IOException { * * If this parameter is not set, the default value of 10 seconds is used. */ - public Subscription createSubscription( + public final Subscription createSubscription( String name, String topic, PushConfig pushConfig, int ackDeadlineSeconds) { Subscription request = Subscription.newBuilder() @@ -320,7 +296,7 @@ public Subscription createSubscription(Subscription request) { * * */ - public ApiCallable createSubscriptionCallable() { + public final ApiCallable createSubscriptionCallable() { return createSubscriptionCallable; } @@ -338,7 +314,7 @@ public ApiCallable createSubscriptionCallable() { * * @param subscription The name of the subscription to get. */ - public Subscription getSubscription(String subscription) { + public final Subscription getSubscription(String subscription) { GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder().setSubscription(subscription).build(); @@ -371,7 +347,7 @@ private Subscription getSubscription(GetSubscriptionRequest request) { * * */ - public ApiCallable getSubscriptionCallable() { + public final ApiCallable getSubscriptionCallable() { return getSubscriptionCallable; } @@ -387,7 +363,7 @@ public ApiCallable getSubscriptionCallable * * */ - public Iterable listSubscriptions(String project) { + public final Iterable listSubscriptions(String project) { ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder().setProject(project).build(); return listSubscriptions(request); @@ -405,7 +381,7 @@ public Iterable listSubscriptions(String project) { * * @param request The request object containing all of the parameters for the API call. */ - public Iterable listSubscriptions(ListSubscriptionsRequest request) { + public final Iterable listSubscriptions(ListSubscriptionsRequest request) { return listSubscriptionsIterableCallable().call(request); } @@ -419,7 +395,7 @@ public Iterable listSubscriptions(ListSubscriptionsRequest request * * */ - public ApiCallable> + public final ApiCallable> listSubscriptionsIterableCallable() { return listSubscriptionsIterableCallable; } @@ -434,7 +410,7 @@ public Iterable listSubscriptions(ListSubscriptionsRequest request * * */ - public ApiCallable + public final ApiCallable listSubscriptionsCallable() { return listSubscriptionsCallable; } @@ -454,7 +430,7 @@ public Iterable listSubscriptions(ListSubscriptionsRequest request * * @param subscription The subscription to delete. */ - public void deleteSubscription(String subscription) { + public final void deleteSubscription(String subscription) { DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder().setSubscription(subscription).build(); @@ -489,7 +465,7 @@ private void deleteSubscription(DeleteSubscriptionRequest request) { * * */ - public ApiCallable deleteSubscriptionCallable() { + public final ApiCallable deleteSubscriptionCallable() { return deleteSubscriptionCallable; } @@ -513,7 +489,8 @@ public ApiCallable deleteSubscriptionCallable( * was made. Specifying zero may immediately make the message available for * another pull request. */ - public void modifyAckDeadline(String subscription, List ackIds, int ackDeadlineSeconds) { + public final void modifyAckDeadline( + String subscription, List ackIds, int ackDeadlineSeconds) { ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder() .setSubscription(subscription) @@ -550,7 +527,7 @@ public void modifyAckDeadline(ModifyAckDeadlineRequest request) { * * */ - public ApiCallable modifyAckDeadlineCallable() { + public final ApiCallable modifyAckDeadlineCallable() { return modifyAckDeadlineCallable; } @@ -573,7 +550,7 @@ public ApiCallable modifyAckDeadlineCallable() * @param ackIds The acknowledgment ID for the messages being acknowledged that was returned * by the Pub/Sub system in the `Pull` response. Must not be empty. */ - public void acknowledge(String subscription, List ackIds) { + public final void acknowledge(String subscription, List ackIds) { AcknowledgeRequest request = AcknowledgeRequest.newBuilder().setSubscription(subscription).addAllAckIds(ackIds).build(); @@ -612,7 +589,7 @@ public void acknowledge(AcknowledgeRequest request) { * * */ - public ApiCallable acknowledgeCallable() { + public final ApiCallable acknowledgeCallable() { return acknowledgeCallable; } @@ -636,7 +613,7 @@ public ApiCallable acknowledgeCallable() { * @param maxMessages The maximum number of messages returned for this request. The Pub/Sub * system may return fewer than the number specified. */ - public PullResponse pull(String subscription, boolean returnImmediately, int maxMessages) { + public final PullResponse pull(String subscription, boolean returnImmediately, int maxMessages) { PullRequest request = PullRequest.newBuilder() .setSubscription(subscription) @@ -673,7 +650,7 @@ public PullResponse pull(PullRequest request) { * * */ - public ApiCallable pullCallable() { + public final ApiCallable pullCallable() { return pullCallable; } @@ -699,7 +676,7 @@ public ApiCallable pullCallable() { * messages to be pulled and acknowledged - effectively pausing * the subscription if `Pull` is not called. */ - public void modifyPushConfig(String subscription, PushConfig pushConfig) { + public final void modifyPushConfig(String subscription, PushConfig pushConfig) { ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder() .setSubscription(subscription) @@ -739,14 +716,10 @@ public void modifyPushConfig(ModifyPushConfigRequest request) { * * */ - public ApiCallable modifyPushConfigCallable() { + public final ApiCallable modifyPushConfigCallable() { return modifyPushConfigCallable; } - // ======== - // Cleanup - // ======== - /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. @@ -755,7 +728,7 @@ public ApiCallable modifyPushConfigCallable() { * */ @Override - public void close() throws Exception { + public final void close() throws Exception { for (AutoCloseable closeable : closeables) { closeable.close(); } diff --git a/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberSettings.java b/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberSettings.java index d9da44aa81f7..e0204a4171f8 100644 --- a/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberSettings.java +++ b/gcloud-java-pubsub/baseline/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberSettings.java @@ -37,8 +37,9 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetryParams; import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder; +import com.google.api.gax.grpc.ApiCallable; +import com.google.api.gax.grpc.ApiCallable.Builder; +import com.google.api.gax.grpc.ApiCallable.PageStreamingBuilder; import com.google.api.gax.grpc.PageStreamingDescriptor; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.common.collect.ImmutableList; @@ -59,6 +60,7 @@ import com.google.pubsub.v1.SubscriberGrpc; import com.google.pubsub.v1.Subscription; import io.grpc.Status; +import org.joda.time.Duration; // Manually-added imports: add custom (non-generated) imports after this point. @@ -66,10 +68,6 @@ @javax.annotation.Generated("by GAPIC") public class SubscriberSettings extends ServiceApiSettings { - // ========= - // Constants - // ========= - /** * The default address of the service. * @@ -117,17 +115,17 @@ public class SubscriberSettings extends ServiceApiSettings { RetryParams.newBuilder() .setRetryBackoff( BackoffParams.newBuilder() - .setInitialDelayMillis(100L) + .setInitialDelay(Duration.millis(100L)) .setDelayMultiplier(1.2) - .setMaxDelayMillis(1000L) + .setMaxDelay(Duration.millis(1000L)) .build()) .setTimeoutBackoff( BackoffParams.newBuilder() - .setInitialDelayMillis(300L) - .setDelayMultiplier(1.3) - .setMaxDelayMillis(3000L) + .setInitialDelay(Duration.millis(2000L)) + .setDelayMultiplier(1.5) + .setMaxDelay(Duration.millis(30000L)) .build()) - .setTotalTimeout(30000L) + .setTotalTimeout(Duration.millis(45000L)) .build(); definitions.put("default", params); RETRY_PARAM_DEFINITIONS = definitions.build(); @@ -136,52 +134,50 @@ public class SubscriberSettings extends ServiceApiSettings { private final MethodBuilders methods; private static class MethodBuilders { - private final ApiCallableBuilder createSubscriptionMethod; - private final ApiCallableBuilder getSubscriptionMethod; - private final PageStreamingApiCallableBuilder< + private final ApiCallable.Builder createSubscriptionMethod; + private final ApiCallable.Builder getSubscriptionMethod; + private final ApiCallable.PageStreamingBuilder< ListSubscriptionsRequest, ListSubscriptionsResponse, Subscription> listSubscriptionsMethod; - private final ApiCallableBuilder deleteSubscriptionMethod; - private final ApiCallableBuilder modifyAckDeadlineMethod; - private final ApiCallableBuilder acknowledgeMethod; - private final ApiCallableBuilder pullMethod; - private final ApiCallableBuilder modifyPushConfigMethod; + private final ApiCallable.Builder deleteSubscriptionMethod; + private final ApiCallable.Builder modifyAckDeadlineMethod; + private final ApiCallable.Builder acknowledgeMethod; + private final ApiCallable.Builder pullMethod; + private final ApiCallable.Builder modifyPushConfigMethod; private final ImmutableList allMethods; public MethodBuilders() { - createSubscriptionMethod = - new ApiCallableBuilder<>(SubscriberGrpc.METHOD_CREATE_SUBSCRIPTION); + createSubscriptionMethod = new Builder<>(SubscriberGrpc.METHOD_CREATE_SUBSCRIPTION); createSubscriptionMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); createSubscriptionMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - getSubscriptionMethod = new ApiCallableBuilder<>(SubscriberGrpc.METHOD_GET_SUBSCRIPTION); + getSubscriptionMethod = new Builder<>(SubscriberGrpc.METHOD_GET_SUBSCRIPTION); getSubscriptionMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); getSubscriptionMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); listSubscriptionsMethod = - new PageStreamingApiCallableBuilder<>( + new PageStreamingBuilder<>( SubscriberGrpc.METHOD_LIST_SUBSCRIPTIONS, LIST_SUBSCRIPTIONS_PAGE_STR_DESC); listSubscriptionsMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); listSubscriptionsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - deleteSubscriptionMethod = - new ApiCallableBuilder<>(SubscriberGrpc.METHOD_DELETE_SUBSCRIPTION); + deleteSubscriptionMethod = new Builder<>(SubscriberGrpc.METHOD_DELETE_SUBSCRIPTION); deleteSubscriptionMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); deleteSubscriptionMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - modifyAckDeadlineMethod = new ApiCallableBuilder<>(SubscriberGrpc.METHOD_MODIFY_ACK_DEADLINE); + modifyAckDeadlineMethod = new Builder<>(SubscriberGrpc.METHOD_MODIFY_ACK_DEADLINE); modifyAckDeadlineMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); modifyAckDeadlineMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - acknowledgeMethod = new ApiCallableBuilder<>(SubscriberGrpc.METHOD_ACKNOWLEDGE); + acknowledgeMethod = new Builder<>(SubscriberGrpc.METHOD_ACKNOWLEDGE); acknowledgeMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); acknowledgeMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - pullMethod = new ApiCallableBuilder<>(SubscriberGrpc.METHOD_PULL); + pullMethod = new Builder<>(SubscriberGrpc.METHOD_PULL); pullMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); pullMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - modifyPushConfigMethod = new ApiCallableBuilder<>(SubscriberGrpc.METHOD_MODIFY_PUSH_CONFIG); + modifyPushConfigMethod = new Builder<>(SubscriberGrpc.METHOD_MODIFY_PUSH_CONFIG); modifyPushConfigMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); modifyPushConfigMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); @@ -200,10 +196,6 @@ public MethodBuilders() { } } - // =============== - // Factory Methods - // =============== - /** * Constructs an instance of SubscriberSettings with default settings. * @@ -240,7 +232,7 @@ protected SubscriberSettings(MethodBuilders methods) { * * */ - public ApiCallableBuilder createSubscriptionMethod() { + public final ApiCallable.Builder createSubscriptionMethod() { return methods.createSubscriptionMethod; } @@ -250,7 +242,7 @@ public ApiCallableBuilder createSubscriptionMethod() * * */ - public ApiCallableBuilder getSubscriptionMethod() { + public final ApiCallable.Builder getSubscriptionMethod() { return methods.getSubscriptionMethod; } @@ -260,7 +252,7 @@ public ApiCallableBuilder getSubscriptionM * * */ - public PageStreamingApiCallableBuilder< + public final ApiCallable.PageStreamingBuilder< ListSubscriptionsRequest, ListSubscriptionsResponse, Subscription> listSubscriptionsMethod() { return methods.listSubscriptionsMethod; @@ -272,7 +264,7 @@ public ApiCallableBuilder getSubscriptionM * * */ - public ApiCallableBuilder deleteSubscriptionMethod() { + public final ApiCallable.Builder deleteSubscriptionMethod() { return methods.deleteSubscriptionMethod; } @@ -282,7 +274,7 @@ public ApiCallableBuilder deleteSubscriptionMe * * */ - public ApiCallableBuilder modifyAckDeadlineMethod() { + public final ApiCallable.Builder modifyAckDeadlineMethod() { return methods.modifyAckDeadlineMethod; } @@ -292,7 +284,7 @@ public ApiCallableBuilder modifyAckDeadlineMeth * * */ - public ApiCallableBuilder acknowledgeMethod() { + public final ApiCallable.Builder acknowledgeMethod() { return methods.acknowledgeMethod; } @@ -302,7 +294,7 @@ public ApiCallableBuilder acknowledgeMethod() { * * */ - public ApiCallableBuilder pullMethod() { + public final ApiCallable.Builder pullMethod() { return methods.pullMethod; } @@ -312,7 +304,7 @@ public ApiCallableBuilder pullMethod() { * * */ - public ApiCallableBuilder modifyPushConfigMethod() { + public final ApiCallable.Builder modifyPushConfigMethod() { return methods.modifyPushConfigMethod; } diff --git a/gcloud-java-pubsub/pom.xml b/gcloud-java-pubsub/pom.xml index 2bd755f63a8c..2e3885288f0d 100644 --- a/gcloud-java-pubsub/pom.xml +++ b/gcloud-java-pubsub/pom.xml @@ -1,17 +1,14 @@ 4.0.0 + com.google.gcloud + 0.1.5 gcloud-java-pubsub jar GCloud Java Pub/Sub Java idiomatic client for Google Cloud Pub/Sub. - - com.google.gcloud - gcloud-java-pom - 0.1.4-SNAPSHOT - gcloud-java-pubsub @@ -19,12 +16,12 @@ com.google.api gax - 0.0.5 + 0.0.6 com.google.api.grpc grpc-pubsub-v1 - 0.0.0 + 0.0.1 io.grpc @@ -89,6 +86,19 @@ + + maven-compiler-plugin + + + + 3.1 + + 1.7 + 1.7 + UTF-8 + -Xlint:unchecked + + diff --git a/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherApi.java b/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherApi.java index fa6da27a72bd..8394e5ae74ed 100644 --- a/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherApi.java +++ b/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherApi.java @@ -66,10 +66,6 @@ */ @javax.annotation.Generated("by GAPIC") public class PublisherApi implements AutoCloseable { - // ======== - // Members - // ======== - private final ManagedChannel channel; private final List closeables = new ArrayList<>(); @@ -84,97 +80,80 @@ public class PublisherApi implements AutoCloseable { listTopicSubscriptionsIterableCallable; private final ApiCallable deleteTopicCallable; - public static class ResourceNames { - - // ======================= - // ResourceNames Constants - // ======================= - - /** - * A PathTemplate representing the fully-qualified path to represent - * a project resource. - * - * - * - */ - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.create("projects/{project}"); - - /** - * A PathTemplate representing the fully-qualified path to represent - * a topic resource. - * - * - * - */ - private static final PathTemplate TOPIC_PATH_TEMPLATE = - PathTemplate.create("projects/{project}/topics/{topic}"); - - private ResourceNames() {} - - // ============================== - // Resource Name Helper Functions - // ============================== - - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * - * - */ - public static final String formatProjectPath(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } + /** + * A PathTemplate representing the fully-qualified path to represent + * a project resource. + * + * + * + */ + private static final PathTemplate PROJECT_PATH_TEMPLATE = + PathTemplate.create("projects/{project}"); - /** - * Formats a string containing the fully-qualified path to represent - * a topic resource. - * - * - * - */ - public static final String formatTopicPath(String project, String topic) { - return TOPIC_PATH_TEMPLATE.instantiate("project", project, "topic", topic); - } + /** + * A PathTemplate representing the fully-qualified path to represent + * a topic resource. + * + * + * + */ + private static final PathTemplate TOPIC_PATH_TEMPLATE = + PathTemplate.create("projects/{project}/topics/{topic}"); - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * - * - */ - public static final String parseProjectFromProjectPath(String projectPath) { - return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project"); - } + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * + * + */ + public static final String formatProjectName(String project) { + return PROJECT_PATH_TEMPLATE.instantiate("project", project); + } - /** - * Parses the project from the given fully-qualified path which - * represents a topic resource. - * - * - * - */ - public static final String parseProjectFromTopicPath(String topicPath) { - return TOPIC_PATH_TEMPLATE.parse(topicPath).get("project"); - } + /** + * Formats a string containing the fully-qualified path to represent + * a topic resource. + * + * + * + */ + public static final String formatTopicName(String project, String topic) { + return TOPIC_PATH_TEMPLATE.instantiate("project", project, "topic", topic); + } - /** - * Parses the topic from the given fully-qualified path which - * represents a topic resource. - * - * - * - */ - public static final String parseTopicFromTopicPath(String topicPath) { - return TOPIC_PATH_TEMPLATE.parse(topicPath).get("topic"); - } + /** + * Parses the project from the given fully-qualified path which + * represents a project resource. + * + * + * + */ + public static final String parseProjectFromProjectName(String projectName) { + return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a topic resource. + * + * + * + */ + public static final String parseProjectFromTopicName(String topicName) { + return TOPIC_PATH_TEMPLATE.parse(topicName).get("project"); } - // =============== - // Factory Methods - // =============== + /** + * Parses the topic from the given fully-qualified path which + * represents a topic resource. + * + * + * + */ + public static final String parseTopicFromTopicName(String topicName) { + return TOPIC_PATH_TEMPLATE.parse(topicName).get("topic"); + } /** * Constructs an instance of PublisherApi with default settings. @@ -182,7 +161,7 @@ public static final String parseTopicFromTopicPath(String topicPath) { * * */ - public static PublisherApi create() throws IOException { + public static final PublisherApi create() throws IOException { return create(PublisherSettings.create()); } @@ -194,7 +173,7 @@ public static PublisherApi create() throws IOException { * * */ - public static PublisherApi create(PublisherSettings settings) throws IOException { + public static final PublisherApi create(PublisherSettings settings) throws IOException { return new PublisherApi(settings); } @@ -226,19 +205,17 @@ protected PublisherApi(PublisherSettings settings) throws IOException { settings.listTopicSubscriptionsMethod().buildPageStreaming(settings); this.deleteTopicCallable = settings.deleteTopicMethod().build(settings); - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - channel.shutdown(); - } - }); + if (settings.shouldAutoCloseChannel()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + channel.shutdown(); + } + }); + } } - // ============= - // Service Calls - // ============= - // ----- createTopic ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -255,7 +232,7 @@ public void close() throws IOException { * signs (`%`). It must be between 3 and 255 characters in length, and it * must not start with `"goog"`. */ - public Topic createTopic(String name) { + public final Topic createTopic(String name) { Topic request = Topic.newBuilder().setName(name).build(); return createTopic(request); @@ -281,7 +258,7 @@ private Topic createTopic(Topic request) { * * */ - public ApiCallable createTopicCallable() { + public final ApiCallable createTopicCallable() { return createTopicCallable; } @@ -299,7 +276,7 @@ public ApiCallable createTopicCallable() { * @param topic The messages in the request will be published on this topic. * @param messages The messages to publish. */ - public PublishResponse publish(String topic, List messages) { + public final PublishResponse publish(String topic, List messages) { PublishRequest request = PublishRequest.newBuilder().setTopic(topic).addAllMessages(messages).build(); @@ -330,7 +307,7 @@ public PublishResponse publish(PublishRequest request) { * * */ - public ApiCallable publishCallable() { + public final ApiCallable publishCallable() { return publishCallable; } @@ -345,7 +322,7 @@ public ApiCallable publishCallable() { * * @param topic The name of the topic to get. */ - public Topic getTopic(String topic) { + public final Topic getTopic(String topic) { GetTopicRequest request = GetTopicRequest.newBuilder().setTopic(topic).build(); return getTopic(request); @@ -371,7 +348,7 @@ private Topic getTopic(GetTopicRequest request) { * * */ - public ApiCallable getTopicCallable() { + public final ApiCallable getTopicCallable() { return getTopicCallable; } @@ -384,7 +361,7 @@ public ApiCallable getTopicCallable() { * * */ - public Iterable listTopics(String project) { + public final Iterable listTopics(String project) { ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(project).build(); return listTopics(request); } @@ -398,7 +375,7 @@ public Iterable listTopics(String project) { * * @param request The request object containing all of the parameters for the API call. */ - public Iterable listTopics(ListTopicsRequest request) { + public final Iterable listTopics(ListTopicsRequest request) { return listTopicsIterableCallable().call(request); } @@ -409,7 +386,7 @@ public Iterable listTopics(ListTopicsRequest request) { * * */ - public ApiCallable> listTopicsIterableCallable() { + public final ApiCallable> listTopicsIterableCallable() { return listTopicsIterableCallable; } @@ -420,7 +397,7 @@ public ApiCallable> listTopicsIterableCallabl * * */ - public ApiCallable listTopicsCallable() { + public final ApiCallable listTopicsCallable() { return listTopicsCallable; } @@ -433,7 +410,7 @@ public ApiCallable listTopicsCallable() { * * */ - public Iterable listTopicSubscriptions(String topic) { + public final Iterable listTopicSubscriptions(String topic) { ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder().setTopic(topic).build(); return listTopicSubscriptions(request); @@ -448,7 +425,7 @@ public Iterable listTopicSubscriptions(String topic) { * * @param request The request object containing all of the parameters for the API call. */ - public Iterable listTopicSubscriptions(ListTopicSubscriptionsRequest request) { + public final Iterable listTopicSubscriptions(ListTopicSubscriptionsRequest request) { return listTopicSubscriptionsIterableCallable().call(request); } @@ -459,7 +436,7 @@ public Iterable listTopicSubscriptions(ListTopicSubscriptionsRequest req * * */ - public ApiCallable> + public final ApiCallable> listTopicSubscriptionsIterableCallable() { return listTopicSubscriptionsIterableCallable; } @@ -471,7 +448,7 @@ public Iterable listTopicSubscriptions(ListTopicSubscriptionsRequest req * * */ - public ApiCallable + public final ApiCallable listTopicSubscriptionsCallable() { return listTopicSubscriptionsCallable; } @@ -491,7 +468,7 @@ public Iterable listTopicSubscriptions(ListTopicSubscriptionsRequest req * * @param topic Name of the topic to delete. */ - public void deleteTopic(String topic) { + public final void deleteTopic(String topic) { DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopic(topic).build(); deleteTopic(request); @@ -525,14 +502,10 @@ private void deleteTopic(DeleteTopicRequest request) { * * */ - public ApiCallable deleteTopicCallable() { + public final ApiCallable deleteTopicCallable() { return deleteTopicCallable; } - // ======== - // Cleanup - // ======== - /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. @@ -541,7 +514,7 @@ public ApiCallable deleteTopicCallable() { * */ @Override - public void close() throws Exception { + public final void close() throws Exception { for (AutoCloseable closeable : closeables) { closeable.close(); } diff --git a/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherSettings.java b/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherSettings.java index 11566404546f..8b3d434b8e49 100644 --- a/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherSettings.java +++ b/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/PublisherSettings.java @@ -37,10 +37,12 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetryParams; import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.BundlableApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder; +import com.google.api.gax.grpc.ApiCallable; +import com.google.api.gax.grpc.ApiCallable.Builder; +import com.google.api.gax.grpc.ApiCallable.BundlableBuilder; +import com.google.api.gax.grpc.ApiCallable.PageStreamingBuilder; import com.google.api.gax.grpc.BundlingDescriptor; +import com.google.api.gax.grpc.BundlingSettings; import com.google.api.gax.grpc.PageStreamingDescriptor; import com.google.api.gax.grpc.RequestIssuer; import com.google.api.gax.grpc.ServiceApiSettings; @@ -65,6 +67,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.joda.time.Duration; // Manually-added imports: add custom (non-generated) imports after this point. @@ -72,10 +75,6 @@ @javax.annotation.Generated("by GAPIC") public class PublisherSettings extends ServiceApiSettings { - // ========= - // Constants - // ========= - /** * The default address of the service. * @@ -123,17 +122,17 @@ public class PublisherSettings extends ServiceApiSettings { RetryParams.newBuilder() .setRetryBackoff( BackoffParams.newBuilder() - .setInitialDelayMillis(100L) + .setInitialDelay(Duration.millis(100L)) .setDelayMultiplier(1.2) - .setMaxDelayMillis(1000L) + .setMaxDelay(Duration.millis(1000L)) .build()) .setTimeoutBackoff( BackoffParams.newBuilder() - .setInitialDelayMillis(300L) - .setDelayMultiplier(1.3) - .setMaxDelayMillis(3000L) + .setInitialDelay(Duration.millis(2000L)) + .setDelayMultiplier(1.5) + .setMaxDelay(Duration.millis(30000L)) .build()) - .setTotalTimeout(30000L) + .setTotalTimeout(Duration.millis(45000L)) .build(); definitions.put("default", params); RETRY_PARAM_DEFINITIONS = definitions.build(); @@ -142,45 +141,54 @@ public class PublisherSettings extends ServiceApiSettings { private final MethodBuilders methods; private static class MethodBuilders { - private final ApiCallableBuilder createTopicMethod; - private final BundlableApiCallableBuilder publishMethod; - private final ApiCallableBuilder getTopicMethod; - private final PageStreamingApiCallableBuilder + private final ApiCallable.Builder createTopicMethod; + private final ApiCallable.BundlableBuilder publishMethod; + private final ApiCallable.Builder getTopicMethod; + private final ApiCallable.PageStreamingBuilder listTopicsMethod; - private final PageStreamingApiCallableBuilder< + private final ApiCallable.PageStreamingBuilder< ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> listTopicSubscriptionsMethod; - private final ApiCallableBuilder deleteTopicMethod; + private final ApiCallable.Builder deleteTopicMethod; private final ImmutableList allMethods; public MethodBuilders() { - createTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_CREATE_TOPIC); + createTopicMethod = new Builder<>(PublisherGrpc.METHOD_CREATE_TOPIC); createTopicMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); createTopicMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); + BundlingSettings publishBundlingSettings = + BundlingSettings.newBuilder() + .setElementCountThreshold(800) + .setElementCountLimit(1000) + .setRequestByteThreshold(8388608) + .setRequestByteLimit(10485760) + .setDelayThreshold(Duration.millis(100)) + .setBlockingCallCountThreshold(1) + .build(); publishMethod = - new BundlableApiCallableBuilder<>(PublisherGrpc.METHOD_PUBLISH, PUBLISH_BUNDLING_DESC); + new BundlableBuilder<>( + PublisherGrpc.METHOD_PUBLISH, PUBLISH_BUNDLING_DESC, publishBundlingSettings); publishMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); publishMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - getTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_GET_TOPIC); + getTopicMethod = new Builder<>(PublisherGrpc.METHOD_GET_TOPIC); getTopicMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); getTopicMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); listTopicsMethod = - new PageStreamingApiCallableBuilder<>( - PublisherGrpc.METHOD_LIST_TOPICS, LIST_TOPICS_PAGE_STR_DESC); + new PageStreamingBuilder<>(PublisherGrpc.METHOD_LIST_TOPICS, LIST_TOPICS_PAGE_STR_DESC); listTopicsMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); listTopicsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); listTopicSubscriptionsMethod = - new PageStreamingApiCallableBuilder<>( + new PageStreamingBuilder<>( PublisherGrpc.METHOD_LIST_TOPIC_SUBSCRIPTIONS, LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_DESC); listTopicSubscriptionsMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); listTopicSubscriptionsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - deleteTopicMethod = new ApiCallableBuilder<>(PublisherGrpc.METHOD_DELETE_TOPIC); + deleteTopicMethod = new Builder<>(PublisherGrpc.METHOD_DELETE_TOPIC); deleteTopicMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); deleteTopicMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); @@ -197,10 +205,6 @@ public MethodBuilders() { } } - // =============== - // Factory Methods - // =============== - /** * Constructs an instance of PublisherSettings with default settings. * @@ -237,7 +241,7 @@ protected PublisherSettings(MethodBuilders methods) { * * */ - public ApiCallableBuilder createTopicMethod() { + public final ApiCallable.Builder createTopicMethod() { return methods.createTopicMethod; } @@ -247,7 +251,7 @@ public ApiCallableBuilder createTopicMethod() { * * */ - public BundlableApiCallableBuilder publishMethod() { + public final ApiCallable.BundlableBuilder publishMethod() { return methods.publishMethod; } @@ -257,7 +261,7 @@ public BundlableApiCallableBuilder publishMetho * * */ - public ApiCallableBuilder getTopicMethod() { + public final ApiCallable.Builder getTopicMethod() { return methods.getTopicMethod; } @@ -267,7 +271,7 @@ public ApiCallableBuilder getTopicMethod() { * * */ - public PageStreamingApiCallableBuilder + public final ApiCallable.PageStreamingBuilder listTopicsMethod() { return methods.listTopicsMethod; } @@ -278,7 +282,7 @@ public ApiCallableBuilder getTopicMethod() { * * */ - public PageStreamingApiCallableBuilder< + public final ApiCallable.PageStreamingBuilder< ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> listTopicSubscriptionsMethod() { return methods.listTopicSubscriptionsMethod; @@ -290,7 +294,7 @@ public ApiCallableBuilder getTopicMethod() { * * */ - public ApiCallableBuilder deleteTopicMethod() { + public final ApiCallable.Builder deleteTopicMethod() { return methods.deleteTopicMethod; } diff --git a/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberApi.java b/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberApi.java index d53dca7f8885..3040af41efd8 100644 --- a/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberApi.java +++ b/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberApi.java @@ -65,10 +65,6 @@ */ @javax.annotation.Generated("by GAPIC") public class SubscriberApi implements AutoCloseable { - // ======== - // Members - // ======== - private final ManagedChannel channel; private final List closeables = new ArrayList<>(); @@ -84,98 +80,80 @@ public class SubscriberApi implements AutoCloseable { private final ApiCallable pullCallable; private final ApiCallable modifyPushConfigCallable; - public static class ResourceNames { - - // ======================= - // ResourceNames Constants - // ======================= - - /** - * A PathTemplate representing the fully-qualified path to represent - * a project resource. - * - * - * - */ - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.create("projects/{project}"); - - /** - * A PathTemplate representing the fully-qualified path to represent - * a subscription resource. - * - * - * - */ - private static final PathTemplate SUBSCRIPTION_PATH_TEMPLATE = - PathTemplate.create("projects/{project}/subscriptions/{subscription}"); - - private ResourceNames() {} - - // ============================== - // Resource Name Helper Functions - // ============================== - - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * - * - */ - public static final String formatProjectPath(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } + /** + * A PathTemplate representing the fully-qualified path to represent + * a project resource. + * + * + * + */ + private static final PathTemplate PROJECT_PATH_TEMPLATE = + PathTemplate.create("projects/{project}"); - /** - * Formats a string containing the fully-qualified path to represent - * a subscription resource. - * - * - * - */ - public static final String formatSubscriptionPath(String project, String subscription) { - return SUBSCRIPTION_PATH_TEMPLATE.instantiate( - "project", project, "subscription", subscription); - } + /** + * A PathTemplate representing the fully-qualified path to represent + * a subscription resource. + * + * + * + */ + private static final PathTemplate SUBSCRIPTION_PATH_TEMPLATE = + PathTemplate.create("projects/{project}/subscriptions/{subscription}"); - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * - * - */ - public static final String parseProjectFromProjectPath(String projectPath) { - return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project"); - } + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * + * + */ + public static final String formatProjectName(String project) { + return PROJECT_PATH_TEMPLATE.instantiate("project", project); + } - /** - * Parses the project from the given fully-qualified path which - * represents a subscription resource. - * - * - * - */ - public static final String parseProjectFromSubscriptionPath(String subscriptionPath) { - return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionPath).get("project"); - } + /** + * Formats a string containing the fully-qualified path to represent + * a subscription resource. + * + * + * + */ + public static final String formatSubscriptionName(String project, String subscription) { + return SUBSCRIPTION_PATH_TEMPLATE.instantiate("project", project, "subscription", subscription); + } - /** - * Parses the subscription from the given fully-qualified path which - * represents a subscription resource. - * - * - * - */ - public static final String parseSubscriptionFromSubscriptionPath(String subscriptionPath) { - return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionPath).get("subscription"); - } + /** + * Parses the project from the given fully-qualified path which + * represents a project resource. + * + * + * + */ + public static final String parseProjectFromProjectName(String projectName) { + return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a subscription resource. + * + * + * + */ + public static final String parseProjectFromSubscriptionName(String subscriptionName) { + return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionName).get("project"); } - // =============== - // Factory Methods - // =============== + /** + * Parses the subscription from the given fully-qualified path which + * represents a subscription resource. + * + * + * + */ + public static final String parseSubscriptionFromSubscriptionName(String subscriptionName) { + return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionName).get("subscription"); + } /** * Constructs an instance of SubscriberApi with default settings. @@ -183,7 +161,7 @@ public static final String parseSubscriptionFromSubscriptionPath(String subscrip * * */ - public static SubscriberApi create() throws IOException { + public static final SubscriberApi create() throws IOException { return create(SubscriberSettings.create()); } @@ -195,7 +173,7 @@ public static SubscriberApi create() throws IOException { * * */ - public static SubscriberApi create(SubscriberSettings settings) throws IOException { + public static final SubscriberApi create(SubscriberSettings settings) throws IOException { return new SubscriberApi(settings); } @@ -221,19 +199,17 @@ protected SubscriberApi(SubscriberSettings settings) throws IOException { this.pullCallable = settings.pullMethod().build(settings); this.modifyPushConfigCallable = settings.modifyPushConfigMethod().build(settings); - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - channel.shutdown(); - } - }); + if (settings.shouldAutoCloseChannel()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + channel.shutdown(); + } + }); + } } - // ============= - // Service Calls - // ============= - // ----- createSubscription ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -277,7 +253,7 @@ public void close() throws IOException { * * If this parameter is not set, the default value of 10 seconds is used. */ - public Subscription createSubscription( + public final Subscription createSubscription( String name, String topic, PushConfig pushConfig, int ackDeadlineSeconds) { Subscription request = Subscription.newBuilder() @@ -320,7 +296,7 @@ public Subscription createSubscription(Subscription request) { * * */ - public ApiCallable createSubscriptionCallable() { + public final ApiCallable createSubscriptionCallable() { return createSubscriptionCallable; } @@ -338,7 +314,7 @@ public ApiCallable createSubscriptionCallable() { * * @param subscription The name of the subscription to get. */ - public Subscription getSubscription(String subscription) { + public final Subscription getSubscription(String subscription) { GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder().setSubscription(subscription).build(); @@ -371,7 +347,7 @@ private Subscription getSubscription(GetSubscriptionRequest request) { * * */ - public ApiCallable getSubscriptionCallable() { + public final ApiCallable getSubscriptionCallable() { return getSubscriptionCallable; } @@ -387,7 +363,7 @@ public ApiCallable getSubscriptionCallable * * */ - public Iterable listSubscriptions(String project) { + public final Iterable listSubscriptions(String project) { ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder().setProject(project).build(); return listSubscriptions(request); @@ -405,7 +381,7 @@ public Iterable listSubscriptions(String project) { * * @param request The request object containing all of the parameters for the API call. */ - public Iterable listSubscriptions(ListSubscriptionsRequest request) { + public final Iterable listSubscriptions(ListSubscriptionsRequest request) { return listSubscriptionsIterableCallable().call(request); } @@ -419,7 +395,7 @@ public Iterable listSubscriptions(ListSubscriptionsRequest request * * */ - public ApiCallable> + public final ApiCallable> listSubscriptionsIterableCallable() { return listSubscriptionsIterableCallable; } @@ -434,7 +410,7 @@ public Iterable listSubscriptions(ListSubscriptionsRequest request * * */ - public ApiCallable + public final ApiCallable listSubscriptionsCallable() { return listSubscriptionsCallable; } @@ -454,7 +430,7 @@ public Iterable listSubscriptions(ListSubscriptionsRequest request * * @param subscription The subscription to delete. */ - public void deleteSubscription(String subscription) { + public final void deleteSubscription(String subscription) { DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder().setSubscription(subscription).build(); @@ -489,7 +465,7 @@ private void deleteSubscription(DeleteSubscriptionRequest request) { * * */ - public ApiCallable deleteSubscriptionCallable() { + public final ApiCallable deleteSubscriptionCallable() { return deleteSubscriptionCallable; } @@ -513,7 +489,8 @@ public ApiCallable deleteSubscriptionCallable( * was made. Specifying zero may immediately make the message available for * another pull request. */ - public void modifyAckDeadline(String subscription, List ackIds, int ackDeadlineSeconds) { + public final void modifyAckDeadline( + String subscription, List ackIds, int ackDeadlineSeconds) { ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder() .setSubscription(subscription) @@ -550,7 +527,7 @@ public void modifyAckDeadline(ModifyAckDeadlineRequest request) { * * */ - public ApiCallable modifyAckDeadlineCallable() { + public final ApiCallable modifyAckDeadlineCallable() { return modifyAckDeadlineCallable; } @@ -573,7 +550,7 @@ public ApiCallable modifyAckDeadlineCallable() * @param ackIds The acknowledgment ID for the messages being acknowledged that was returned * by the Pub/Sub system in the `Pull` response. Must not be empty. */ - public void acknowledge(String subscription, List ackIds) { + public final void acknowledge(String subscription, List ackIds) { AcknowledgeRequest request = AcknowledgeRequest.newBuilder().setSubscription(subscription).addAllAckIds(ackIds).build(); @@ -612,7 +589,7 @@ public void acknowledge(AcknowledgeRequest request) { * * */ - public ApiCallable acknowledgeCallable() { + public final ApiCallable acknowledgeCallable() { return acknowledgeCallable; } @@ -636,7 +613,7 @@ public ApiCallable acknowledgeCallable() { * @param maxMessages The maximum number of messages returned for this request. The Pub/Sub * system may return fewer than the number specified. */ - public PullResponse pull(String subscription, boolean returnImmediately, int maxMessages) { + public final PullResponse pull(String subscription, boolean returnImmediately, int maxMessages) { PullRequest request = PullRequest.newBuilder() .setSubscription(subscription) @@ -673,7 +650,7 @@ public PullResponse pull(PullRequest request) { * * */ - public ApiCallable pullCallable() { + public final ApiCallable pullCallable() { return pullCallable; } @@ -699,7 +676,7 @@ public ApiCallable pullCallable() { * messages to be pulled and acknowledged - effectively pausing * the subscription if `Pull` is not called. */ - public void modifyPushConfig(String subscription, PushConfig pushConfig) { + public final void modifyPushConfig(String subscription, PushConfig pushConfig) { ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder() .setSubscription(subscription) @@ -739,14 +716,10 @@ public void modifyPushConfig(ModifyPushConfigRequest request) { * * */ - public ApiCallable modifyPushConfigCallable() { + public final ApiCallable modifyPushConfigCallable() { return modifyPushConfigCallable; } - // ======== - // Cleanup - // ======== - /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. @@ -755,7 +728,7 @@ public ApiCallable modifyPushConfigCallable() { * */ @Override - public void close() throws Exception { + public final void close() throws Exception { for (AutoCloseable closeable : closeables) { closeable.close(); } diff --git a/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberSettings.java b/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberSettings.java index d9da44aa81f7..e0204a4171f8 100644 --- a/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberSettings.java +++ b/gcloud-java-pubsub/src/main/java/com/google/gcloud/pubsub/spi/v1/SubscriberSettings.java @@ -37,8 +37,9 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetryParams; import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder; +import com.google.api.gax.grpc.ApiCallable; +import com.google.api.gax.grpc.ApiCallable.Builder; +import com.google.api.gax.grpc.ApiCallable.PageStreamingBuilder; import com.google.api.gax.grpc.PageStreamingDescriptor; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.common.collect.ImmutableList; @@ -59,6 +60,7 @@ import com.google.pubsub.v1.SubscriberGrpc; import com.google.pubsub.v1.Subscription; import io.grpc.Status; +import org.joda.time.Duration; // Manually-added imports: add custom (non-generated) imports after this point. @@ -66,10 +68,6 @@ @javax.annotation.Generated("by GAPIC") public class SubscriberSettings extends ServiceApiSettings { - // ========= - // Constants - // ========= - /** * The default address of the service. * @@ -117,17 +115,17 @@ public class SubscriberSettings extends ServiceApiSettings { RetryParams.newBuilder() .setRetryBackoff( BackoffParams.newBuilder() - .setInitialDelayMillis(100L) + .setInitialDelay(Duration.millis(100L)) .setDelayMultiplier(1.2) - .setMaxDelayMillis(1000L) + .setMaxDelay(Duration.millis(1000L)) .build()) .setTimeoutBackoff( BackoffParams.newBuilder() - .setInitialDelayMillis(300L) - .setDelayMultiplier(1.3) - .setMaxDelayMillis(3000L) + .setInitialDelay(Duration.millis(2000L)) + .setDelayMultiplier(1.5) + .setMaxDelay(Duration.millis(30000L)) .build()) - .setTotalTimeout(30000L) + .setTotalTimeout(Duration.millis(45000L)) .build(); definitions.put("default", params); RETRY_PARAM_DEFINITIONS = definitions.build(); @@ -136,52 +134,50 @@ public class SubscriberSettings extends ServiceApiSettings { private final MethodBuilders methods; private static class MethodBuilders { - private final ApiCallableBuilder createSubscriptionMethod; - private final ApiCallableBuilder getSubscriptionMethod; - private final PageStreamingApiCallableBuilder< + private final ApiCallable.Builder createSubscriptionMethod; + private final ApiCallable.Builder getSubscriptionMethod; + private final ApiCallable.PageStreamingBuilder< ListSubscriptionsRequest, ListSubscriptionsResponse, Subscription> listSubscriptionsMethod; - private final ApiCallableBuilder deleteSubscriptionMethod; - private final ApiCallableBuilder modifyAckDeadlineMethod; - private final ApiCallableBuilder acknowledgeMethod; - private final ApiCallableBuilder pullMethod; - private final ApiCallableBuilder modifyPushConfigMethod; + private final ApiCallable.Builder deleteSubscriptionMethod; + private final ApiCallable.Builder modifyAckDeadlineMethod; + private final ApiCallable.Builder acknowledgeMethod; + private final ApiCallable.Builder pullMethod; + private final ApiCallable.Builder modifyPushConfigMethod; private final ImmutableList allMethods; public MethodBuilders() { - createSubscriptionMethod = - new ApiCallableBuilder<>(SubscriberGrpc.METHOD_CREATE_SUBSCRIPTION); + createSubscriptionMethod = new Builder<>(SubscriberGrpc.METHOD_CREATE_SUBSCRIPTION); createSubscriptionMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); createSubscriptionMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - getSubscriptionMethod = new ApiCallableBuilder<>(SubscriberGrpc.METHOD_GET_SUBSCRIPTION); + getSubscriptionMethod = new Builder<>(SubscriberGrpc.METHOD_GET_SUBSCRIPTION); getSubscriptionMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); getSubscriptionMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); listSubscriptionsMethod = - new PageStreamingApiCallableBuilder<>( + new PageStreamingBuilder<>( SubscriberGrpc.METHOD_LIST_SUBSCRIPTIONS, LIST_SUBSCRIPTIONS_PAGE_STR_DESC); listSubscriptionsMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); listSubscriptionsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - deleteSubscriptionMethod = - new ApiCallableBuilder<>(SubscriberGrpc.METHOD_DELETE_SUBSCRIPTION); + deleteSubscriptionMethod = new Builder<>(SubscriberGrpc.METHOD_DELETE_SUBSCRIPTION); deleteSubscriptionMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); deleteSubscriptionMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - modifyAckDeadlineMethod = new ApiCallableBuilder<>(SubscriberGrpc.METHOD_MODIFY_ACK_DEADLINE); + modifyAckDeadlineMethod = new Builder<>(SubscriberGrpc.METHOD_MODIFY_ACK_DEADLINE); modifyAckDeadlineMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); modifyAckDeadlineMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - acknowledgeMethod = new ApiCallableBuilder<>(SubscriberGrpc.METHOD_ACKNOWLEDGE); + acknowledgeMethod = new Builder<>(SubscriberGrpc.METHOD_ACKNOWLEDGE); acknowledgeMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); acknowledgeMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - pullMethod = new ApiCallableBuilder<>(SubscriberGrpc.METHOD_PULL); + pullMethod = new Builder<>(SubscriberGrpc.METHOD_PULL); pullMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); pullMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - modifyPushConfigMethod = new ApiCallableBuilder<>(SubscriberGrpc.METHOD_MODIFY_PUSH_CONFIG); + modifyPushConfigMethod = new Builder<>(SubscriberGrpc.METHOD_MODIFY_PUSH_CONFIG); modifyPushConfigMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); modifyPushConfigMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); @@ -200,10 +196,6 @@ public MethodBuilders() { } } - // =============== - // Factory Methods - // =============== - /** * Constructs an instance of SubscriberSettings with default settings. * @@ -240,7 +232,7 @@ protected SubscriberSettings(MethodBuilders methods) { * * */ - public ApiCallableBuilder createSubscriptionMethod() { + public final ApiCallable.Builder createSubscriptionMethod() { return methods.createSubscriptionMethod; } @@ -250,7 +242,7 @@ public ApiCallableBuilder createSubscriptionMethod() * * */ - public ApiCallableBuilder getSubscriptionMethod() { + public final ApiCallable.Builder getSubscriptionMethod() { return methods.getSubscriptionMethod; } @@ -260,7 +252,7 @@ public ApiCallableBuilder getSubscriptionM * * */ - public PageStreamingApiCallableBuilder< + public final ApiCallable.PageStreamingBuilder< ListSubscriptionsRequest, ListSubscriptionsResponse, Subscription> listSubscriptionsMethod() { return methods.listSubscriptionsMethod; @@ -272,7 +264,7 @@ public ApiCallableBuilder getSubscriptionM * * */ - public ApiCallableBuilder deleteSubscriptionMethod() { + public final ApiCallable.Builder deleteSubscriptionMethod() { return methods.deleteSubscriptionMethod; } @@ -282,7 +274,7 @@ public ApiCallableBuilder deleteSubscriptionMe * * */ - public ApiCallableBuilder modifyAckDeadlineMethod() { + public final ApiCallable.Builder modifyAckDeadlineMethod() { return methods.modifyAckDeadlineMethod; } @@ -292,7 +284,7 @@ public ApiCallableBuilder modifyAckDeadlineMeth * * */ - public ApiCallableBuilder acknowledgeMethod() { + public final ApiCallable.Builder acknowledgeMethod() { return methods.acknowledgeMethod; } @@ -302,7 +294,7 @@ public ApiCallableBuilder acknowledgeMethod() { * * */ - public ApiCallableBuilder pullMethod() { + public final ApiCallable.Builder pullMethod() { return methods.pullMethod; } @@ -312,7 +304,7 @@ public ApiCallableBuilder pullMethod() { * * */ - public ApiCallableBuilder modifyPushConfigMethod() { + public final ApiCallable.Builder modifyPushConfigMethod() { return methods.modifyPushConfigMethod; } diff --git a/gcloud-java-pubsub/src/test/java/com/google/gcloud/pubsub/spi/v1/PublisherApiTest.java b/gcloud-java-pubsub/src/test/java/com/google/gcloud/pubsub/spi/v1/PublisherApiTest.java index c25ca51ee713..dac4be9ae8fc 100644 --- a/gcloud-java-pubsub/src/test/java/com/google/gcloud/pubsub/spi/v1/PublisherApiTest.java +++ b/gcloud-java-pubsub/src/test/java/com/google/gcloud/pubsub/spi/v1/PublisherApiTest.java @@ -14,8 +14,6 @@ package com.google.gcloud.pubsub.spi.v1; -import com.google.api.gax.core.BackoffParams; -import com.google.api.gax.core.RetryParams; import com.google.api.gax.grpc.BundlingSettings; import com.google.gcloud.pubsub.testing.LocalPubsubHelper; import com.google.protobuf.ByteString; @@ -24,13 +22,6 @@ import com.google.pubsub.v1.PushConfig; import com.google.pubsub.v1.Topic; -import io.grpc.ManagedChannel; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import org.joda.time.Duration; import org.junit.After; import org.junit.AfterClass; @@ -39,6 +30,13 @@ import org.junit.BeforeClass; import org.junit.Test; +import io.grpc.ManagedChannel; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public class PublisherApiTest { private static LocalPubsubHelper pubsubHelper; private PublisherApi publisherApi; @@ -60,26 +58,8 @@ public static void stopServer() throws IOException, InterruptedException { public void setUp() throws Exception { ManagedChannel channel = pubsubHelper.createChannel(); - RetryParams retryParams = - RetryParams.newBuilder() - .setRetryBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(1000L) - .setDelayMultiplier(1.2) - .setMaxDelayMillis(10000L) - .build()) - .setTimeoutBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(3000L) - .setDelayMultiplier(1.3) - .setMaxDelayMillis(30000L) - .build()) - .setTotalTimeout(30000L) - .build(); - PublisherSettings publisherSettings = PublisherSettings.create(); - publisherSettings.setRetryParamsOnAllMethods(retryParams); - publisherSettings.provideChannelWith(channel); + publisherSettings.provideChannelWith(channel, true); publisherApi = PublisherApi.create(publisherSettings); BundlingSettings bundlingSettings = @@ -89,14 +69,12 @@ public void setUp() throws Exception { .build(); PublisherSettings bundledPublisherSettings = PublisherSettings.create(); - bundledPublisherSettings.setRetryParamsOnAllMethods(retryParams); - bundledPublisherSettings.provideChannelWith(channel); + bundledPublisherSettings.provideChannelWith(channel, true); bundledPublisherSettings.publishMethod().setBundlingSettings(bundlingSettings); bundledPublisherApi = PublisherApi.create(bundledPublisherSettings); SubscriberSettings subscriberSettings = SubscriberSettings.create(); - subscriberSettings.setRetryParamsOnAllMethods(retryParams); - subscriberSettings.provideChannelWith(channel); + subscriberSettings.provideChannelWith(channel, true); subscriberApi = SubscriberApi.create(subscriberSettings); } @@ -116,18 +94,18 @@ public void tearDown() throws Exception { @Test public void testCreateTopic() throws Exception { - String topicName = PublisherApi.ResourceNames.formatTopicPath("my-project", "my-topic"); + String topicName = PublisherApi.formatTopicName("my-project", "my-topic"); Topic result = publisherApi.createTopic(topicName); Assert.assertEquals(topicName, result.getName()); } @Test public void testPublish() throws Exception { - String topicName = PublisherApi.ResourceNames.formatTopicPath("my-project", "publish-topic"); + String topicName = PublisherApi.formatTopicName("my-project", "publish-topic"); publisherApi.createTopic(topicName); String subscriberName = - SubscriberApi.ResourceNames.formatSubscriptionPath("my-project", "my-subscribe"); + SubscriberApi.formatSubscriptionName("my-project", "my-subscribe"); PushConfig config = PushConfig.getDefaultInstance(); subscriberApi.createSubscription(subscriberName, topicName, config, 5); @@ -143,11 +121,11 @@ public void testPublish() throws Exception { @Test public void testBundledPublish() throws Exception { - String topicName = PublisherApi.ResourceNames.formatTopicPath("my-project", "publish-topic"); + String topicName = PublisherApi.formatTopicName("my-project", "publish-topic"); bundledPublisherApi.createTopic(topicName); String subscriberName = - SubscriberApi.ResourceNames.formatSubscriptionPath("my-project", "my-subscribe"); + SubscriberApi.formatSubscriptionName("my-project", "my-subscribe"); PushConfig config = PushConfig.getDefaultInstance(); subscriberApi.createSubscription(subscriberName, topicName, config, 5); @@ -164,7 +142,7 @@ public void testBundledPublish() throws Exception { @Test public void testGetTopic() throws Exception { - String topicName = PublisherApi.ResourceNames.formatTopicPath("my-project", "fun-topic"); + String topicName = PublisherApi.formatTopicName("my-project", "fun-topic"); publisherApi.createTopic(topicName); Topic result = publisherApi.getTopic(topicName); Assert.assertNotNull(result); @@ -173,10 +151,10 @@ public void testGetTopic() throws Exception { @Test public void testListTopics() throws Exception { - String project1 = PublisherApi.ResourceNames.formatProjectPath("project.1"); - String topicName1 = PublisherApi.ResourceNames.formatTopicPath("project.1", "topic.1"); - String topicName2 = PublisherApi.ResourceNames.formatTopicPath("project.1", "topic.2"); - String topicName3 = PublisherApi.ResourceNames.formatTopicPath("project.2", "topic.3"); + String project1 = PublisherApi.formatProjectName("project.1"); + String topicName1 = PublisherApi.formatTopicName("project.1", "topic.1"); + String topicName2 = PublisherApi.formatTopicName("project.1", "topic.2"); + String topicName3 = PublisherApi.formatTopicName("project.2", "topic.3"); publisherApi.createTopic(topicName1); publisherApi.createTopic(topicName2); publisherApi.createTopic(topicName3); @@ -191,8 +169,8 @@ public void testListTopics() throws Exception { @Test public void testDeleteTopic() throws Exception { - String project = PublisherApi.ResourceNames.formatProjectPath("project.1"); - String topicName = PublisherApi.ResourceNames.formatTopicPath("my-project", "fun-topic"); + String project = PublisherApi.formatProjectName("project.1"); + String topicName = PublisherApi.formatTopicName("my-project", "fun-topic"); publisherApi.createTopic(topicName); publisherApi.deleteTopic(topicName); List topics = new ArrayList<>();