diff --git a/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java b/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java index 36d576767efb..644d19188200 100644 --- a/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java +++ b/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java @@ -67,8 +67,8 @@ *
  * 
  * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
- *   String name = "";
- *   Topic callResult = publisherApi.createTopic(name);
+ *   String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ *   Topic response = publisherApi.createTopic(formattedName);
  * }
  * 
  * 
@@ -277,10 +277,18 @@ public void close() throws IOException { /** * Creates the given topic with the given name. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Topic response = publisherApi.createTopic(formattedName);
+   * }
+   * 
+ * * * * - * @param name The name of the topic. It must have the format + * @param formattedName The name of the topic. It must have the format * `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, * and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), * underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent @@ -288,9 +296,9 @@ public void close() throws IOException { * must not start with `"goog"`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Topic createTopic(String name) { - Topic request = Topic.newBuilder().setName(name).build(); - + public final Topic createTopic(String formattedName) { + TOPIC_PATH_TEMPLATE.validate(formattedName); + Topic request = Topic.newBuilder().setName(formattedName).build(); return createTopic(request); } @@ -298,6 +306,17 @@ public final Topic createTopic(String name) { /** * Creates the given topic with the given name. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Topic request = Topic.newBuilder()
+   *     .setName(formattedName)
+   *     .build();
+   *   Topic response = publisherApi.createTopic(request);
+   * }
+   * 
+ * * * * @@ -312,6 +331,19 @@ private Topic createTopic(Topic request) { /** * Creates the given topic with the given name. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Topic request = Topic.newBuilder()
+   *     .setName(formattedName)
+   *     .build();
+   *   ListenableFuture<Topic> future = publisherApi.createTopicCallable().futureCall(request);
+   *   // Do something
+   *   Topic response = future.get();
+   * }
+   * 
+ * * * */ @@ -327,17 +359,27 @@ public final ApiCallable createTopicCallable() { * does not exist. The message payload must not be empty; it must contain * either a non-empty data field, or at least one attribute. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   List<PubsubMessage> messages = new ArrayList<>();
+   *   PublishResponse response = publisherApi.publish(formattedTopic, messages);
+   * }
+   * 
+ * * * * - * @param topic The messages in the request will be published on this topic. + * @param formattedTopic The messages in the request will be published on this topic. * @param messages The messages to publish. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PublishResponse publish(String topic, List messages) { - PublishRequest request = - PublishRequest.newBuilder().setTopic(topic).addAllMessages(messages).build(); + public final PublishResponse publish(String formattedTopic, List messages) { + TOPIC_PATH_TEMPLATE.validate(formattedTopic); + PublishRequest request = + PublishRequest.newBuilder().setTopic(formattedTopic).addAllMessages(messages).build(); return publish(request); } @@ -347,6 +389,19 @@ public final PublishResponse publish(String topic, List messages) * does not exist. The message payload must not be empty; it must contain * either a non-empty data field, or at least one attribute. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   List<PubsubMessage> messages = new ArrayList<>();
+   *   PublishRequest request = PublishRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .addAllMessages(messages)
+   *     .build();
+   *   PublishResponse response = publisherApi.publish(request);
+   * }
+   * 
+ * * * * @@ -363,6 +418,21 @@ public PublishResponse publish(PublishRequest request) { * does not exist. The message payload must not be empty; it must contain * either a non-empty data field, or at least one attribute. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   List<PubsubMessage> messages = new ArrayList<>();
+   *   PublishRequest request = PublishRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .addAllMessages(messages)
+   *     .build();
+   *   ListenableFuture<PublishResponse> future = publisherApi.publishCallable().futureCall(request);
+   *   // Do something
+   *   PublishResponse response = future.get();
+   * }
+   * 
+ * * * */ @@ -376,15 +446,23 @@ public final ApiCallable publishCallable() { /** * Gets the configuration of a topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Topic response = publisherApi.getTopic(formattedTopic);
+   * }
+   * 
+ * * * * - * @param topic The name of the topic to get. + * @param formattedTopic The name of the topic to get. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Topic getTopic(String topic) { - GetTopicRequest request = GetTopicRequest.newBuilder().setTopic(topic).build(); - + public final Topic getTopic(String formattedTopic) { + TOPIC_PATH_TEMPLATE.validate(formattedTopic); + GetTopicRequest request = GetTopicRequest.newBuilder().setTopic(formattedTopic).build(); return getTopic(request); } @@ -392,6 +470,17 @@ public final Topic getTopic(String topic) { /** * Gets the configuration of a topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   GetTopicRequest request = GetTopicRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   Topic response = publisherApi.getTopic(request);
+   * }
+   * 
+ * * * * @@ -406,6 +495,19 @@ private Topic getTopic(GetTopicRequest request) { /** * Gets the configuration of a topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   GetTopicRequest request = GetTopicRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   ListenableFuture<Topic> future = publisherApi.getTopicCallable().futureCall(request);
+   *   // Do something
+   *   Topic response = future.get();
+   * }
+   * 
+ * * * */ @@ -419,14 +521,25 @@ public final ApiCallable getTopicCallable() { /** * Lists matching topics. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+   *   for (Topic elements : publisherApi.listTopics(formattedProject)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * - * @param project The name of the cloud project that topics belong to. + * @param formattedProject The name of the cloud project that topics belong to. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PageAccessor listTopics(String project) { - ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(project).build(); + public final PageAccessor listTopics(String formattedProject) { + PROJECT_PATH_TEMPLATE.validate(formattedProject); + ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(formattedProject).build(); return listTopics(request); } @@ -434,6 +547,19 @@ public final PageAccessor listTopics(String project) { /** * Lists matching topics. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+   *   ListTopicsRequest request = ListTopicsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   for (Topic elements : publisherApi.listTopics(request)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * @@ -448,6 +574,21 @@ public final PageAccessor listTopics(ListTopicsRequest request) { /** * Lists matching topics. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+   *   ListTopicsRequest request = ListTopicsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   ListenableFuture<PageAccessor<Topic>> future = publisherApi.listTopicsPagedCallable().futureCall(request);
+   *   // Do something
+   *   for (Topic elements : future.get()) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * */ @@ -459,6 +600,28 @@ public final ApiCallable> listTopicsPaged /** * Lists matching topics. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+   *   ListTopicsRequest request = ListTopicsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   while (true) {
+   *     ListTopicsResponse response = publisherApi.listTopicsCallable().call(request);
+   *     for (Topic elements : response.getTopicsList()) {
+   *       // doThingsWith(elements);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * 
+ * * * */ @@ -472,15 +635,26 @@ public final ApiCallable listTopicsCallab /** * Lists the name of the subscriptions for this topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   for (String elements : publisherApi.listTopicSubscriptions(formattedTopic)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * - * @param topic The name of the topic that subscriptions are attached to. + * @param formattedTopic The name of the topic that subscriptions are attached to. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PageAccessor listTopicSubscriptions(String topic) { + public final PageAccessor listTopicSubscriptions(String formattedTopic) { + TOPIC_PATH_TEMPLATE.validate(formattedTopic); ListTopicSubscriptionsRequest request = - ListTopicSubscriptionsRequest.newBuilder().setTopic(topic).build(); + ListTopicSubscriptionsRequest.newBuilder().setTopic(formattedTopic).build(); return listTopicSubscriptions(request); } @@ -488,6 +662,19 @@ public final PageAccessor listTopicSubscriptions(String topic) { /** * Lists the name of the subscriptions for this topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   for (String elements : publisherApi.listTopicSubscriptions(request)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * @@ -502,6 +689,21 @@ public final PageAccessor listTopicSubscriptions(ListTopicSubscriptionsR /** * Lists the name of the subscriptions for this topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   ListenableFuture<PageAccessor<String>> future = publisherApi.listTopicSubscriptionsPagedCallable().futureCall(request);
+   *   // Do something
+   *   for (String elements : future.get()) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * */ @@ -514,6 +716,28 @@ public final PageAccessor listTopicSubscriptions(ListTopicSubscriptionsR /** * Lists the name of the subscriptions for this topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   while (true) {
+   *     ListTopicSubscriptionsResponse response = publisherApi.listTopicSubscriptionsCallable().call(request);
+   *     for (String elements : response.getSubscriptionsList()) {
+   *       // doThingsWith(elements);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * 
+ * * * */ @@ -532,15 +756,23 @@ public final PageAccessor listTopicSubscriptions(ListTopicSubscriptionsR * configuration or subscriptions. Existing subscriptions to this topic are * not deleted, but their `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   publisherApi.deleteTopic(formattedTopic);
+   * }
+   * 
+ * * * * - * @param topic Name of the topic to delete. + * @param formattedTopic Name of the topic to delete. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void deleteTopic(String topic) { - DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopic(topic).build(); - + public final void deleteTopic(String formattedTopic) { + TOPIC_PATH_TEMPLATE.validate(formattedTopic); + DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopic(formattedTopic).build(); deleteTopic(request); } @@ -552,6 +784,17 @@ public final void deleteTopic(String topic) { * configuration or subscriptions. Existing subscriptions to this topic are * not deleted, but their `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   DeleteTopicRequest request = DeleteTopicRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   publisherApi.deleteTopic(request);
+   * }
+   * 
+ * * * * @@ -570,6 +813,19 @@ private void deleteTopic(DeleteTopicRequest request) { * configuration or subscriptions. Existing subscriptions to this topic are * not deleted, but their `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   DeleteTopicRequest request = DeleteTopicRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   ListenableFuture<Void> future = publisherApi.deleteTopicCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ * * * */ diff --git a/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java b/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java index dd6275bcd9d0..7fd76395b8e7 100644 --- a/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java +++ b/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java @@ -68,11 +68,11 @@ *
  * 
  * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
- *   String name = "";
- *   String topic = "";
+ *   String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ *   String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
  *   PushConfig pushConfig = PushConfig.newBuilder().build();
  *   int ackDeadlineSeconds = 0;
- *   Subscription callResult = subscriberApi.createSubscription(name, topic, pushConfig, ackDeadlineSeconds);
+ *   Subscription response = subscriberApi.createSubscription(formattedName, formattedTopic, pushConfig, ackDeadlineSeconds);
  * }
  * 
  * 
@@ -321,16 +321,27 @@ public void close() throws IOException { * If the name is not provided in the request, the server will assign a random * name for this subscription on the same project as the topic. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   PushConfig pushConfig = PushConfig.newBuilder().build();
+   *   int ackDeadlineSeconds = 0;
+   *   Subscription response = subscriberApi.createSubscription(formattedName, formattedTopic, pushConfig, ackDeadlineSeconds);
+   * }
+   * 
+ * * * * - * @param name The name of the subscription. It must have the format + * @param formattedName The name of the subscription. It must have the format * `"projects/{project}/subscriptions/{subscription}"`. `{subscription}` must * start with a letter, and contain only letters (`[A-Za-z]`), numbers * (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), tildes (`~`), * plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters * in length, and it must not start with `"goog"`. - * @param topic The name of the topic from which this subscription is receiving messages. + * @param formattedTopic The name of the topic from which this subscription is receiving messages. * @param pushConfig If push delivery is used with this subscription, this field is * used to configure it. An empty `pushConfig` signifies that the subscriber * will pull and ack messages using API methods. @@ -355,15 +366,17 @@ public void close() throws IOException { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Subscription createSubscription( - String name, String topic, PushConfig pushConfig, int ackDeadlineSeconds) { + String formattedName, String formattedTopic, PushConfig pushConfig, int ackDeadlineSeconds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedName); + TOPIC_PATH_TEMPLATE.validate(formattedTopic); + Subscription request = Subscription.newBuilder() - .setName(name) - .setTopic(topic) + .setName(formattedName) + .setTopic(formattedTopic) .setPushConfig(pushConfig) .setAckDeadlineSeconds(ackDeadlineSeconds) .build(); - return createSubscription(request); } @@ -376,6 +389,19 @@ public final Subscription createSubscription( * If the name is not provided in the request, the server will assign a random * name for this subscription on the same project as the topic. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Subscription request = Subscription.newBuilder()
+   *     .setName(formattedName)
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   Subscription response = subscriberApi.createSubscription(request);
+   * }
+   * 
+ * * * * @@ -395,6 +421,21 @@ public Subscription createSubscription(Subscription request) { * If the name is not provided in the request, the server will assign a random * name for this subscription on the same project as the topic. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Subscription request = Subscription.newBuilder()
+   *     .setName(formattedName)
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   ListenableFuture<Subscription> future = subscriberApi.createSubscriptionCallable().futureCall(request);
+   *   // Do something
+   *   Subscription response = future.get();
+   * }
+   * 
+ * * * */ @@ -411,16 +452,24 @@ public final ApiCallable createSubscriptionCallable( * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   Subscription response = subscriberApi.getSubscription(formattedSubscription);
+   * }
+   * 
+ * * * * - * @param subscription The name of the subscription to get. + * @param formattedSubscription The name of the subscription to get. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Subscription getSubscription(String subscription) { + public final Subscription getSubscription(String formattedSubscription) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); GetSubscriptionRequest request = - GetSubscriptionRequest.newBuilder().setSubscription(subscription).build(); - + GetSubscriptionRequest.newBuilder().setSubscription(formattedSubscription).build(); return getSubscription(request); } @@ -431,6 +480,17 @@ public final Subscription getSubscription(String subscription) { * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .build();
+   *   Subscription response = subscriberApi.getSubscription(request);
+   * }
+   * 
+ * * * * @@ -448,6 +508,19 @@ private Subscription getSubscription(GetSubscriptionRequest request) { * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .build();
+   *   ListenableFuture<Subscription> future = subscriberApi.getSubscriptionCallable().futureCall(request);
+   *   // Do something
+   *   Subscription response = future.get();
+   * }
+   * 
+ * * * */ @@ -464,15 +537,26 @@ public final ApiCallable getSubscriptionCa * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+   *   for (Subscription elements : subscriberApi.listSubscriptions(formattedProject)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * - * @param project The name of the cloud project that subscriptions belong to. + * @param formattedProject The name of the cloud project that subscriptions belong to. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PageAccessor listSubscriptions(String project) { + public final PageAccessor listSubscriptions(String formattedProject) { + PROJECT_PATH_TEMPLATE.validate(formattedProject); ListSubscriptionsRequest request = - ListSubscriptionsRequest.newBuilder().setProject(project).build(); + ListSubscriptionsRequest.newBuilder().setProject(formattedProject).build(); return listSubscriptions(request); } @@ -483,6 +567,19 @@ public final PageAccessor listSubscriptions(String project) { * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+   *   ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   for (Subscription elements : subscriberApi.listSubscriptions(request)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * @@ -500,6 +597,21 @@ public final PageAccessor listSubscriptions(ListSubscriptionsReque * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+   *   ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   ListenableFuture<PageAccessor<Subscription>> future = subscriberApi.listSubscriptionsPagedCallable().futureCall(request);
+   *   // Do something
+   *   for (Subscription elements : future.get()) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * */ @@ -515,6 +627,28 @@ public final PageAccessor listSubscriptions(ListSubscriptionsReque * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+   *   ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   while (true) {
+   *     ListSubscriptionsResponse response = subscriberApi.listSubscriptionsCallable().call(request);
+   *     for (Subscription elements : response.getSubscriptionsList()) {
+   *       // doThingsWith(elements);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * 
+ * * * */ @@ -533,16 +667,24 @@ public final PageAccessor listSubscriptions(ListSubscriptionsReque * the same name, but the new one has no association with the old * subscription, or its topic unless the same topic is specified. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   subscriberApi.deleteSubscription(formattedSubscription);
+   * }
+   * 
+ * * * * - * @param subscription The subscription to delete. + * @param formattedSubscription The subscription to delete. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void deleteSubscription(String subscription) { + public final void deleteSubscription(String formattedSubscription) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); DeleteSubscriptionRequest request = - DeleteSubscriptionRequest.newBuilder().setSubscription(subscription).build(); - + DeleteSubscriptionRequest.newBuilder().setSubscription(formattedSubscription).build(); deleteSubscription(request); } @@ -554,6 +696,17 @@ public final void deleteSubscription(String subscription) { * the same name, but the new one has no association with the old * subscription, or its topic unless the same topic is specified. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .build();
+   *   subscriberApi.deleteSubscription(request);
+   * }
+   * 
+ * * * * @@ -572,6 +725,19 @@ private void deleteSubscription(DeleteSubscriptionRequest request) { * the same name, but the new one has no association with the old * subscription, or its topic unless the same topic is specified. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .build();
+   *   ListenableFuture<Void> future = subscriberApi.deleteSubscriptionCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ * * * */ @@ -588,10 +754,20 @@ public final ApiCallable deleteSubscriptionCal * subscriber, or to make the message available for redelivery if the * processing was interrupted. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   int ackDeadlineSeconds = 0;
+   *   subscriberApi.modifyAckDeadline(formattedSubscription, ackIds, ackDeadlineSeconds);
+   * }
+   * 
+ * * * * - * @param subscription The name of the subscription. + * @param formattedSubscription The name of the subscription. * @param ackIds List of acknowledgment IDs. * @param ackDeadlineSeconds The new ack deadline with respect to the time this request was sent to * the Pub/Sub system. Must be >= 0. For example, if the value is 10, the new @@ -601,14 +777,15 @@ public final ApiCallable deleteSubscriptionCal * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void modifyAckDeadline( - String subscription, List ackIds, int ackDeadlineSeconds) { + String formattedSubscription, List ackIds, int ackDeadlineSeconds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); + ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder() - .setSubscription(subscription) + .setSubscription(formattedSubscription) .addAllAckIds(ackIds) .setAckDeadlineSeconds(ackDeadlineSeconds) .build(); - modifyAckDeadline(request); } @@ -619,6 +796,21 @@ public final void modifyAckDeadline( * subscriber, or to make the message available for redelivery if the * processing was interrupted. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   int ackDeadlineSeconds = 0;
+   *   ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .addAllAckIds(ackIds)
+   *     .setAckDeadlineSeconds(ackDeadlineSeconds)
+   *     .build();
+   *   subscriberApi.modifyAckDeadline(request);
+   * }
+   * 
+ * * * * @@ -636,6 +828,23 @@ public void modifyAckDeadline(ModifyAckDeadlineRequest request) { * subscriber, or to make the message available for redelivery if the * processing was interrupted. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   int ackDeadlineSeconds = 0;
+   *   ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .addAllAckIds(ackIds)
+   *     .setAckDeadlineSeconds(ackDeadlineSeconds)
+   *     .build();
+   *   ListenableFuture<Void> future = subscriberApi.modifyAckDeadlineCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ * * * */ @@ -655,18 +864,31 @@ public final ApiCallable modifyAckDeadlineCalla * but such a message may be redelivered later. Acknowledging a message more * than once will not result in an error. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   subscriberApi.acknowledge(formattedSubscription, ackIds);
+   * }
+   * 
+ * * * * - * @param subscription The subscription whose message is being acknowledged. + * @param formattedSubscription The subscription whose message is being acknowledged. * @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. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void acknowledge(String subscription, List ackIds) { - AcknowledgeRequest request = - AcknowledgeRequest.newBuilder().setSubscription(subscription).addAllAckIds(ackIds).build(); + public final void acknowledge(String formattedSubscription, List ackIds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); + AcknowledgeRequest request = + AcknowledgeRequest.newBuilder() + .setSubscription(formattedSubscription) + .addAllAckIds(ackIds) + .build(); acknowledge(request); } @@ -680,6 +902,19 @@ public final void acknowledge(String subscription, List ackIds) { * but such a message may be redelivered later. Acknowledging a message more * than once will not result in an error. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   AcknowledgeRequest request = AcknowledgeRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .addAllAckIds(ackIds)
+   *     .build();
+   *   subscriberApi.acknowledge(request);
+   * }
+   * 
+ * * * * @@ -700,6 +935,21 @@ public void acknowledge(AcknowledgeRequest request) { * but such a message may be redelivered later. Acknowledging a message more * than once will not result in an error. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   AcknowledgeRequest request = AcknowledgeRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .addAllAckIds(ackIds)
+   *     .build();
+   *   ListenableFuture<Void> future = subscriberApi.acknowledgeCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ * * * */ @@ -716,10 +966,20 @@ public final ApiCallable acknowledgeCallable() { * there are too many concurrent pull requests pending for the given * subscription. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   boolean returnImmediately = false;
+   *   int maxMessages = 0;
+   *   PullResponse response = subscriberApi.pull(formattedSubscription, returnImmediately, maxMessages);
+   * }
+   * 
+ * * * * - * @param subscription The subscription from which messages should be pulled. + * @param formattedSubscription The subscription from which messages should be pulled. * @param returnImmediately If this is specified as true the system will respond immediately even if * it is not able to return a message in the `Pull` response. Otherwise the * system is allowed to wait until at least one message is available rather @@ -728,14 +988,16 @@ public final ApiCallable acknowledgeCallable() { * system may return fewer than the number specified. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PullResponse pull(String subscription, boolean returnImmediately, int maxMessages) { + public final PullResponse pull( + String formattedSubscription, boolean returnImmediately, int maxMessages) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); + PullRequest request = PullRequest.newBuilder() - .setSubscription(subscription) + .setSubscription(formattedSubscription) .setReturnImmediately(returnImmediately) .setMaxMessages(maxMessages) .build(); - return pull(request); } @@ -746,6 +1008,19 @@ public final PullResponse pull(String subscription, boolean returnImmediately, i * there are too many concurrent pull requests pending for the given * subscription. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   int maxMessages = 0;
+   *   PullRequest request = PullRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .setMaxMessages(maxMessages)
+   *     .build();
+   *   PullResponse response = subscriberApi.pull(request);
+   * }
+   * 
+ * * * * @@ -763,6 +1038,21 @@ public PullResponse pull(PullRequest request) { * there are too many concurrent pull requests pending for the given * subscription. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   int maxMessages = 0;
+   *   PullRequest request = PullRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .setMaxMessages(maxMessages)
+   *     .build();
+   *   ListenableFuture<PullResponse> future = subscriberApi.pullCallable().futureCall(request);
+   *   // Do something
+   *   PullResponse response = future.get();
+   * }
+   * 
+ * * * */ @@ -781,10 +1071,19 @@ public final ApiCallable pullCallable() { * attributes of a push subscription. Messages will accumulate for delivery * continuously through the call regardless of changes to the `PushConfig`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   PushConfig pushConfig = PushConfig.newBuilder().build();
+   *   subscriberApi.modifyPushConfig(formattedSubscription, pushConfig);
+   * }
+   * 
+ * * * * - * @param subscription The name of the subscription. + * @param formattedSubscription The name of the subscription. * @param pushConfig The push configuration for future deliveries. * * An empty `pushConfig` indicates that the Pub/Sub system should @@ -793,13 +1092,14 @@ public final ApiCallable pullCallable() { * the subscription if `Pull` is not called. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void modifyPushConfig(String subscription, PushConfig pushConfig) { + public final void modifyPushConfig(String formattedSubscription, PushConfig pushConfig) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); + ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder() - .setSubscription(subscription) + .setSubscription(formattedSubscription) .setPushConfig(pushConfig) .build(); - modifyPushConfig(request); } @@ -812,6 +1112,19 @@ public final void modifyPushConfig(String subscription, PushConfig pushConfig) { * attributes of a push subscription. Messages will accumulate for delivery * continuously through the call regardless of changes to the `PushConfig`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   PushConfig pushConfig = PushConfig.newBuilder().build();
+   *   ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .setPushConfig(pushConfig)
+   *     .build();
+   *   subscriberApi.modifyPushConfig(request);
+   * }
+   * 
+ * * * * @@ -831,6 +1144,21 @@ public void modifyPushConfig(ModifyPushConfigRequest request) { * attributes of a push subscription. Messages will accumulate for delivery * continuously through the call regardless of changes to the `PushConfig`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   PushConfig pushConfig = PushConfig.newBuilder().build();
+   *   ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .setPushConfig(pushConfig)
+   *     .build();
+   *   ListenableFuture<Void> future = subscriberApi.modifyPushConfigCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ * * * */ diff --git a/gcloud-java-pubsub/pom.xml b/gcloud-java-pubsub/pom.xml index f9b9b6533f78..77902a588260 100644 --- a/gcloud-java-pubsub/pom.xml +++ b/gcloud-java-pubsub/pom.xml @@ -25,7 +25,7 @@ com.google.api gax - 0.0.12 + 0.0.13 com.google.api.grpc diff --git a/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java b/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java index 36d576767efb..644d19188200 100644 --- a/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java +++ b/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java @@ -67,8 +67,8 @@ *
  * 
  * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
- *   String name = "";
- *   Topic callResult = publisherApi.createTopic(name);
+ *   String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ *   Topic response = publisherApi.createTopic(formattedName);
  * }
  * 
  * 
@@ -277,10 +277,18 @@ public void close() throws IOException { /** * Creates the given topic with the given name. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Topic response = publisherApi.createTopic(formattedName);
+   * }
+   * 
+ * * * * - * @param name The name of the topic. It must have the format + * @param formattedName The name of the topic. It must have the format * `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, * and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), * underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent @@ -288,9 +296,9 @@ public void close() throws IOException { * must not start with `"goog"`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Topic createTopic(String name) { - Topic request = Topic.newBuilder().setName(name).build(); - + public final Topic createTopic(String formattedName) { + TOPIC_PATH_TEMPLATE.validate(formattedName); + Topic request = Topic.newBuilder().setName(formattedName).build(); return createTopic(request); } @@ -298,6 +306,17 @@ public final Topic createTopic(String name) { /** * Creates the given topic with the given name. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Topic request = Topic.newBuilder()
+   *     .setName(formattedName)
+   *     .build();
+   *   Topic response = publisherApi.createTopic(request);
+   * }
+   * 
+ * * * * @@ -312,6 +331,19 @@ private Topic createTopic(Topic request) { /** * Creates the given topic with the given name. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Topic request = Topic.newBuilder()
+   *     .setName(formattedName)
+   *     .build();
+   *   ListenableFuture<Topic> future = publisherApi.createTopicCallable().futureCall(request);
+   *   // Do something
+   *   Topic response = future.get();
+   * }
+   * 
+ * * * */ @@ -327,17 +359,27 @@ public final ApiCallable createTopicCallable() { * does not exist. The message payload must not be empty; it must contain * either a non-empty data field, or at least one attribute. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   List<PubsubMessage> messages = new ArrayList<>();
+   *   PublishResponse response = publisherApi.publish(formattedTopic, messages);
+   * }
+   * 
+ * * * * - * @param topic The messages in the request will be published on this topic. + * @param formattedTopic The messages in the request will be published on this topic. * @param messages The messages to publish. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PublishResponse publish(String topic, List messages) { - PublishRequest request = - PublishRequest.newBuilder().setTopic(topic).addAllMessages(messages).build(); + public final PublishResponse publish(String formattedTopic, List messages) { + TOPIC_PATH_TEMPLATE.validate(formattedTopic); + PublishRequest request = + PublishRequest.newBuilder().setTopic(formattedTopic).addAllMessages(messages).build(); return publish(request); } @@ -347,6 +389,19 @@ public final PublishResponse publish(String topic, List messages) * does not exist. The message payload must not be empty; it must contain * either a non-empty data field, or at least one attribute. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   List<PubsubMessage> messages = new ArrayList<>();
+   *   PublishRequest request = PublishRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .addAllMessages(messages)
+   *     .build();
+   *   PublishResponse response = publisherApi.publish(request);
+   * }
+   * 
+ * * * * @@ -363,6 +418,21 @@ public PublishResponse publish(PublishRequest request) { * does not exist. The message payload must not be empty; it must contain * either a non-empty data field, or at least one attribute. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   List<PubsubMessage> messages = new ArrayList<>();
+   *   PublishRequest request = PublishRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .addAllMessages(messages)
+   *     .build();
+   *   ListenableFuture<PublishResponse> future = publisherApi.publishCallable().futureCall(request);
+   *   // Do something
+   *   PublishResponse response = future.get();
+   * }
+   * 
+ * * * */ @@ -376,15 +446,23 @@ public final ApiCallable publishCallable() { /** * Gets the configuration of a topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Topic response = publisherApi.getTopic(formattedTopic);
+   * }
+   * 
+ * * * * - * @param topic The name of the topic to get. + * @param formattedTopic The name of the topic to get. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Topic getTopic(String topic) { - GetTopicRequest request = GetTopicRequest.newBuilder().setTopic(topic).build(); - + public final Topic getTopic(String formattedTopic) { + TOPIC_PATH_TEMPLATE.validate(formattedTopic); + GetTopicRequest request = GetTopicRequest.newBuilder().setTopic(formattedTopic).build(); return getTopic(request); } @@ -392,6 +470,17 @@ public final Topic getTopic(String topic) { /** * Gets the configuration of a topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   GetTopicRequest request = GetTopicRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   Topic response = publisherApi.getTopic(request);
+   * }
+   * 
+ * * * * @@ -406,6 +495,19 @@ private Topic getTopic(GetTopicRequest request) { /** * Gets the configuration of a topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   GetTopicRequest request = GetTopicRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   ListenableFuture<Topic> future = publisherApi.getTopicCallable().futureCall(request);
+   *   // Do something
+   *   Topic response = future.get();
+   * }
+   * 
+ * * * */ @@ -419,14 +521,25 @@ public final ApiCallable getTopicCallable() { /** * Lists matching topics. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+   *   for (Topic elements : publisherApi.listTopics(formattedProject)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * - * @param project The name of the cloud project that topics belong to. + * @param formattedProject The name of the cloud project that topics belong to. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PageAccessor listTopics(String project) { - ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(project).build(); + public final PageAccessor listTopics(String formattedProject) { + PROJECT_PATH_TEMPLATE.validate(formattedProject); + ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(formattedProject).build(); return listTopics(request); } @@ -434,6 +547,19 @@ public final PageAccessor listTopics(String project) { /** * Lists matching topics. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+   *   ListTopicsRequest request = ListTopicsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   for (Topic elements : publisherApi.listTopics(request)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * @@ -448,6 +574,21 @@ public final PageAccessor listTopics(ListTopicsRequest request) { /** * Lists matching topics. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+   *   ListTopicsRequest request = ListTopicsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   ListenableFuture<PageAccessor<Topic>> future = publisherApi.listTopicsPagedCallable().futureCall(request);
+   *   // Do something
+   *   for (Topic elements : future.get()) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * */ @@ -459,6 +600,28 @@ public final ApiCallable> listTopicsPaged /** * Lists matching topics. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+   *   ListTopicsRequest request = ListTopicsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   while (true) {
+   *     ListTopicsResponse response = publisherApi.listTopicsCallable().call(request);
+   *     for (Topic elements : response.getTopicsList()) {
+   *       // doThingsWith(elements);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * 
+ * * * */ @@ -472,15 +635,26 @@ public final ApiCallable listTopicsCallab /** * Lists the name of the subscriptions for this topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   for (String elements : publisherApi.listTopicSubscriptions(formattedTopic)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * - * @param topic The name of the topic that subscriptions are attached to. + * @param formattedTopic The name of the topic that subscriptions are attached to. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PageAccessor listTopicSubscriptions(String topic) { + public final PageAccessor listTopicSubscriptions(String formattedTopic) { + TOPIC_PATH_TEMPLATE.validate(formattedTopic); ListTopicSubscriptionsRequest request = - ListTopicSubscriptionsRequest.newBuilder().setTopic(topic).build(); + ListTopicSubscriptionsRequest.newBuilder().setTopic(formattedTopic).build(); return listTopicSubscriptions(request); } @@ -488,6 +662,19 @@ public final PageAccessor listTopicSubscriptions(String topic) { /** * Lists the name of the subscriptions for this topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   for (String elements : publisherApi.listTopicSubscriptions(request)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * @@ -502,6 +689,21 @@ public final PageAccessor listTopicSubscriptions(ListTopicSubscriptionsR /** * Lists the name of the subscriptions for this topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   ListenableFuture<PageAccessor<String>> future = publisherApi.listTopicSubscriptionsPagedCallable().futureCall(request);
+   *   // Do something
+   *   for (String elements : future.get()) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * */ @@ -514,6 +716,28 @@ public final PageAccessor listTopicSubscriptions(ListTopicSubscriptionsR /** * Lists the name of the subscriptions for this topic. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   while (true) {
+   *     ListTopicSubscriptionsResponse response = publisherApi.listTopicSubscriptionsCallable().call(request);
+   *     for (String elements : response.getSubscriptionsList()) {
+   *       // doThingsWith(elements);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * 
+ * * * */ @@ -532,15 +756,23 @@ public final PageAccessor listTopicSubscriptions(ListTopicSubscriptionsR * configuration or subscriptions. Existing subscriptions to this topic are * not deleted, but their `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   publisherApi.deleteTopic(formattedTopic);
+   * }
+   * 
+ * * * * - * @param topic Name of the topic to delete. + * @param formattedTopic Name of the topic to delete. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void deleteTopic(String topic) { - DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopic(topic).build(); - + public final void deleteTopic(String formattedTopic) { + TOPIC_PATH_TEMPLATE.validate(formattedTopic); + DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopic(formattedTopic).build(); deleteTopic(request); } @@ -552,6 +784,17 @@ public final void deleteTopic(String topic) { * configuration or subscriptions. Existing subscriptions to this topic are * not deleted, but their `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   DeleteTopicRequest request = DeleteTopicRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   publisherApi.deleteTopic(request);
+   * }
+   * 
+ * * * * @@ -570,6 +813,19 @@ private void deleteTopic(DeleteTopicRequest request) { * configuration or subscriptions. Existing subscriptions to this topic are * not deleted, but their `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+   *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   DeleteTopicRequest request = DeleteTopicRequest.newBuilder()
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   ListenableFuture<Void> future = publisherApi.deleteTopicCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ * * * */ diff --git a/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java b/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java index dd6275bcd9d0..7fd76395b8e7 100644 --- a/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java +++ b/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java @@ -68,11 +68,11 @@ *
  * 
  * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
- *   String name = "";
- *   String topic = "";
+ *   String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ *   String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
  *   PushConfig pushConfig = PushConfig.newBuilder().build();
  *   int ackDeadlineSeconds = 0;
- *   Subscription callResult = subscriberApi.createSubscription(name, topic, pushConfig, ackDeadlineSeconds);
+ *   Subscription response = subscriberApi.createSubscription(formattedName, formattedTopic, pushConfig, ackDeadlineSeconds);
  * }
  * 
  * 
@@ -321,16 +321,27 @@ public void close() throws IOException { * If the name is not provided in the request, the server will assign a random * name for this subscription on the same project as the topic. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   PushConfig pushConfig = PushConfig.newBuilder().build();
+   *   int ackDeadlineSeconds = 0;
+   *   Subscription response = subscriberApi.createSubscription(formattedName, formattedTopic, pushConfig, ackDeadlineSeconds);
+   * }
+   * 
+ * * * * - * @param name The name of the subscription. It must have the format + * @param formattedName The name of the subscription. It must have the format * `"projects/{project}/subscriptions/{subscription}"`. `{subscription}` must * start with a letter, and contain only letters (`[A-Za-z]`), numbers * (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), tildes (`~`), * plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters * in length, and it must not start with `"goog"`. - * @param topic The name of the topic from which this subscription is receiving messages. + * @param formattedTopic The name of the topic from which this subscription is receiving messages. * @param pushConfig If push delivery is used with this subscription, this field is * used to configure it. An empty `pushConfig` signifies that the subscriber * will pull and ack messages using API methods. @@ -355,15 +366,17 @@ public void close() throws IOException { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Subscription createSubscription( - String name, String topic, PushConfig pushConfig, int ackDeadlineSeconds) { + String formattedName, String formattedTopic, PushConfig pushConfig, int ackDeadlineSeconds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedName); + TOPIC_PATH_TEMPLATE.validate(formattedTopic); + Subscription request = Subscription.newBuilder() - .setName(name) - .setTopic(topic) + .setName(formattedName) + .setTopic(formattedTopic) .setPushConfig(pushConfig) .setAckDeadlineSeconds(ackDeadlineSeconds) .build(); - return createSubscription(request); } @@ -376,6 +389,19 @@ public final Subscription createSubscription( * If the name is not provided in the request, the server will assign a random * name for this subscription on the same project as the topic. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Subscription request = Subscription.newBuilder()
+   *     .setName(formattedName)
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   Subscription response = subscriberApi.createSubscription(request);
+   * }
+   * 
+ * * * * @@ -395,6 +421,21 @@ public Subscription createSubscription(Subscription request) { * If the name is not provided in the request, the server will assign a random * name for this subscription on the same project as the topic. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   Subscription request = Subscription.newBuilder()
+   *     .setName(formattedName)
+   *     .setTopic(formattedTopic)
+   *     .build();
+   *   ListenableFuture<Subscription> future = subscriberApi.createSubscriptionCallable().futureCall(request);
+   *   // Do something
+   *   Subscription response = future.get();
+   * }
+   * 
+ * * * */ @@ -411,16 +452,24 @@ public final ApiCallable createSubscriptionCallable( * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   Subscription response = subscriberApi.getSubscription(formattedSubscription);
+   * }
+   * 
+ * * * * - * @param subscription The name of the subscription to get. + * @param formattedSubscription The name of the subscription to get. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Subscription getSubscription(String subscription) { + public final Subscription getSubscription(String formattedSubscription) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); GetSubscriptionRequest request = - GetSubscriptionRequest.newBuilder().setSubscription(subscription).build(); - + GetSubscriptionRequest.newBuilder().setSubscription(formattedSubscription).build(); return getSubscription(request); } @@ -431,6 +480,17 @@ public final Subscription getSubscription(String subscription) { * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .build();
+   *   Subscription response = subscriberApi.getSubscription(request);
+   * }
+   * 
+ * * * * @@ -448,6 +508,19 @@ private Subscription getSubscription(GetSubscriptionRequest request) { * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .build();
+   *   ListenableFuture<Subscription> future = subscriberApi.getSubscriptionCallable().futureCall(request);
+   *   // Do something
+   *   Subscription response = future.get();
+   * }
+   * 
+ * * * */ @@ -464,15 +537,26 @@ public final ApiCallable getSubscriptionCa * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+   *   for (Subscription elements : subscriberApi.listSubscriptions(formattedProject)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * - * @param project The name of the cloud project that subscriptions belong to. + * @param formattedProject The name of the cloud project that subscriptions belong to. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PageAccessor listSubscriptions(String project) { + public final PageAccessor listSubscriptions(String formattedProject) { + PROJECT_PATH_TEMPLATE.validate(formattedProject); ListSubscriptionsRequest request = - ListSubscriptionsRequest.newBuilder().setProject(project).build(); + ListSubscriptionsRequest.newBuilder().setProject(formattedProject).build(); return listSubscriptions(request); } @@ -483,6 +567,19 @@ public final PageAccessor listSubscriptions(String project) { * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+   *   ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   for (Subscription elements : subscriberApi.listSubscriptions(request)) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * * @@ -500,6 +597,21 @@ public final PageAccessor listSubscriptions(ListSubscriptionsReque * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+   *   ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   ListenableFuture<PageAccessor<Subscription>> future = subscriberApi.listSubscriptionsPagedCallable().futureCall(request);
+   *   // Do something
+   *   for (Subscription elements : future.get()) {
+   *     // doThingsWith(elements);
+   *   }
+   * }
+   * 
+ * * * */ @@ -515,6 +627,28 @@ public final PageAccessor listSubscriptions(ListSubscriptionsReque * If the topic of a subscription has been deleted, the subscription itself is * not deleted, but the value of the `topic` field is set to `_deleted-topic_`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+   *   ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+   *     .setProject(formattedProject)
+   *     .build();
+   *   while (true) {
+   *     ListSubscriptionsResponse response = subscriberApi.listSubscriptionsCallable().call(request);
+   *     for (Subscription elements : response.getSubscriptionsList()) {
+   *       // doThingsWith(elements);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * 
+ * * * */ @@ -533,16 +667,24 @@ public final PageAccessor listSubscriptions(ListSubscriptionsReque * the same name, but the new one has no association with the old * subscription, or its topic unless the same topic is specified. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   subscriberApi.deleteSubscription(formattedSubscription);
+   * }
+   * 
+ * * * * - * @param subscription The subscription to delete. + * @param formattedSubscription The subscription to delete. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void deleteSubscription(String subscription) { + public final void deleteSubscription(String formattedSubscription) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); DeleteSubscriptionRequest request = - DeleteSubscriptionRequest.newBuilder().setSubscription(subscription).build(); - + DeleteSubscriptionRequest.newBuilder().setSubscription(formattedSubscription).build(); deleteSubscription(request); } @@ -554,6 +696,17 @@ public final void deleteSubscription(String subscription) { * the same name, but the new one has no association with the old * subscription, or its topic unless the same topic is specified. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .build();
+   *   subscriberApi.deleteSubscription(request);
+   * }
+   * 
+ * * * * @@ -572,6 +725,19 @@ private void deleteSubscription(DeleteSubscriptionRequest request) { * the same name, but the new one has no association with the old * subscription, or its topic unless the same topic is specified. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .build();
+   *   ListenableFuture<Void> future = subscriberApi.deleteSubscriptionCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ * * * */ @@ -588,10 +754,20 @@ public final ApiCallable deleteSubscriptionCal * subscriber, or to make the message available for redelivery if the * processing was interrupted. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   int ackDeadlineSeconds = 0;
+   *   subscriberApi.modifyAckDeadline(formattedSubscription, ackIds, ackDeadlineSeconds);
+   * }
+   * 
+ * * * * - * @param subscription The name of the subscription. + * @param formattedSubscription The name of the subscription. * @param ackIds List of acknowledgment IDs. * @param ackDeadlineSeconds The new ack deadline with respect to the time this request was sent to * the Pub/Sub system. Must be >= 0. For example, if the value is 10, the new @@ -601,14 +777,15 @@ public final ApiCallable deleteSubscriptionCal * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void modifyAckDeadline( - String subscription, List ackIds, int ackDeadlineSeconds) { + String formattedSubscription, List ackIds, int ackDeadlineSeconds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); + ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder() - .setSubscription(subscription) + .setSubscription(formattedSubscription) .addAllAckIds(ackIds) .setAckDeadlineSeconds(ackDeadlineSeconds) .build(); - modifyAckDeadline(request); } @@ -619,6 +796,21 @@ public final void modifyAckDeadline( * subscriber, or to make the message available for redelivery if the * processing was interrupted. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   int ackDeadlineSeconds = 0;
+   *   ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .addAllAckIds(ackIds)
+   *     .setAckDeadlineSeconds(ackDeadlineSeconds)
+   *     .build();
+   *   subscriberApi.modifyAckDeadline(request);
+   * }
+   * 
+ * * * * @@ -636,6 +828,23 @@ public void modifyAckDeadline(ModifyAckDeadlineRequest request) { * subscriber, or to make the message available for redelivery if the * processing was interrupted. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   int ackDeadlineSeconds = 0;
+   *   ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .addAllAckIds(ackIds)
+   *     .setAckDeadlineSeconds(ackDeadlineSeconds)
+   *     .build();
+   *   ListenableFuture<Void> future = subscriberApi.modifyAckDeadlineCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ * * * */ @@ -655,18 +864,31 @@ public final ApiCallable modifyAckDeadlineCalla * but such a message may be redelivered later. Acknowledging a message more * than once will not result in an error. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   subscriberApi.acknowledge(formattedSubscription, ackIds);
+   * }
+   * 
+ * * * * - * @param subscription The subscription whose message is being acknowledged. + * @param formattedSubscription The subscription whose message is being acknowledged. * @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. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void acknowledge(String subscription, List ackIds) { - AcknowledgeRequest request = - AcknowledgeRequest.newBuilder().setSubscription(subscription).addAllAckIds(ackIds).build(); + public final void acknowledge(String formattedSubscription, List ackIds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); + AcknowledgeRequest request = + AcknowledgeRequest.newBuilder() + .setSubscription(formattedSubscription) + .addAllAckIds(ackIds) + .build(); acknowledge(request); } @@ -680,6 +902,19 @@ public final void acknowledge(String subscription, List ackIds) { * but such a message may be redelivered later. Acknowledging a message more * than once will not result in an error. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   AcknowledgeRequest request = AcknowledgeRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .addAllAckIds(ackIds)
+   *     .build();
+   *   subscriberApi.acknowledge(request);
+   * }
+   * 
+ * * * * @@ -700,6 +935,21 @@ public void acknowledge(AcknowledgeRequest request) { * but such a message may be redelivered later. Acknowledging a message more * than once will not result in an error. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   List<String> ackIds = new ArrayList<>();
+   *   AcknowledgeRequest request = AcknowledgeRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .addAllAckIds(ackIds)
+   *     .build();
+   *   ListenableFuture<Void> future = subscriberApi.acknowledgeCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ * * * */ @@ -716,10 +966,20 @@ public final ApiCallable acknowledgeCallable() { * there are too many concurrent pull requests pending for the given * subscription. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   boolean returnImmediately = false;
+   *   int maxMessages = 0;
+   *   PullResponse response = subscriberApi.pull(formattedSubscription, returnImmediately, maxMessages);
+   * }
+   * 
+ * * * * - * @param subscription The subscription from which messages should be pulled. + * @param formattedSubscription The subscription from which messages should be pulled. * @param returnImmediately If this is specified as true the system will respond immediately even if * it is not able to return a message in the `Pull` response. Otherwise the * system is allowed to wait until at least one message is available rather @@ -728,14 +988,16 @@ public final ApiCallable acknowledgeCallable() { * system may return fewer than the number specified. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PullResponse pull(String subscription, boolean returnImmediately, int maxMessages) { + public final PullResponse pull( + String formattedSubscription, boolean returnImmediately, int maxMessages) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); + PullRequest request = PullRequest.newBuilder() - .setSubscription(subscription) + .setSubscription(formattedSubscription) .setReturnImmediately(returnImmediately) .setMaxMessages(maxMessages) .build(); - return pull(request); } @@ -746,6 +1008,19 @@ public final PullResponse pull(String subscription, boolean returnImmediately, i * there are too many concurrent pull requests pending for the given * subscription. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   int maxMessages = 0;
+   *   PullRequest request = PullRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .setMaxMessages(maxMessages)
+   *     .build();
+   *   PullResponse response = subscriberApi.pull(request);
+   * }
+   * 
+ * * * * @@ -763,6 +1038,21 @@ public PullResponse pull(PullRequest request) { * there are too many concurrent pull requests pending for the given * subscription. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   int maxMessages = 0;
+   *   PullRequest request = PullRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .setMaxMessages(maxMessages)
+   *     .build();
+   *   ListenableFuture<PullResponse> future = subscriberApi.pullCallable().futureCall(request);
+   *   // Do something
+   *   PullResponse response = future.get();
+   * }
+   * 
+ * * * */ @@ -781,10 +1071,19 @@ public final ApiCallable pullCallable() { * attributes of a push subscription. Messages will accumulate for delivery * continuously through the call regardless of changes to the `PushConfig`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   PushConfig pushConfig = PushConfig.newBuilder().build();
+   *   subscriberApi.modifyPushConfig(formattedSubscription, pushConfig);
+   * }
+   * 
+ * * * * - * @param subscription The name of the subscription. + * @param formattedSubscription The name of the subscription. * @param pushConfig The push configuration for future deliveries. * * An empty `pushConfig` indicates that the Pub/Sub system should @@ -793,13 +1092,14 @@ public final ApiCallable pullCallable() { * the subscription if `Pull` is not called. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void modifyPushConfig(String subscription, PushConfig pushConfig) { + public final void modifyPushConfig(String formattedSubscription, PushConfig pushConfig) { + SUBSCRIPTION_PATH_TEMPLATE.validate(formattedSubscription); + ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder() - .setSubscription(subscription) + .setSubscription(formattedSubscription) .setPushConfig(pushConfig) .build(); - modifyPushConfig(request); } @@ -812,6 +1112,19 @@ public final void modifyPushConfig(String subscription, PushConfig pushConfig) { * attributes of a push subscription. Messages will accumulate for delivery * continuously through the call regardless of changes to the `PushConfig`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   PushConfig pushConfig = PushConfig.newBuilder().build();
+   *   ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .setPushConfig(pushConfig)
+   *     .build();
+   *   subscriberApi.modifyPushConfig(request);
+   * }
+   * 
+ * * * * @@ -831,6 +1144,21 @@ public void modifyPushConfig(ModifyPushConfigRequest request) { * attributes of a push subscription. Messages will accumulate for delivery * continuously through the call regardless of changes to the `PushConfig`. * + * Sample code: + *

+   * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+   *   String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   PushConfig pushConfig = PushConfig.newBuilder().build();
+   *   ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder()
+   *     .setSubscription(formattedSubscription)
+   *     .setPushConfig(pushConfig)
+   *     .build();
+   *   ListenableFuture<Void> future = subscriberApi.modifyPushConfigCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ * * * */