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..7d8eb0f15e79 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,6 +277,14 @@ 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);
+   * }
+   * 
+ * * * * @@ -289,8 +297,8 @@ public void close() throws IOException { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Topic createTopic(String name) { + TOPIC_PATH_TEMPLATE.validate(name); Topic request = Topic.newBuilder().setName(name).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,6 +359,15 @@ 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);
+   * }
+   * 
+ * * * * @@ -335,9 +376,10 @@ public final ApiCallable createTopicCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final PublishResponse publish(String topic, List messages) { + TOPIC_PATH_TEMPLATE.validate(topic); + PublishRequest request = PublishRequest.newBuilder().setTopic(topic).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,6 +446,14 @@ 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);
+   * }
+   * 
+ * * * * @@ -383,8 +461,8 @@ public final ApiCallable publishCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Topic getTopic(String topic) { + TOPIC_PATH_TEMPLATE.validate(topic); GetTopicRequest request = GetTopicRequest.newBuilder().setTopic(topic).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,6 +521,16 @@ 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);
+   *   }
+   * }
+   * 
+ * * * * @@ -426,6 +538,7 @@ public final ApiCallable getTopicCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final PageAccessor listTopics(String project) { + PROJECT_PATH_TEMPLATE.validate(project); ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(project).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,6 +635,16 @@ 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);
+   *   }
+   * }
+   * 
+ * * * * @@ -479,6 +652,7 @@ public final ApiCallable listTopicsCallab * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final PageAccessor listTopicSubscriptions(String topic) { + TOPIC_PATH_TEMPLATE.validate(topic); ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder().setTopic(topic).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,6 +756,14 @@ 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);
+   * }
+   * 
+ * * * * @@ -539,8 +771,8 @@ public final PageAccessor listTopicSubscriptions(ListTopicSubscriptionsR * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void deleteTopic(String topic) { + TOPIC_PATH_TEMPLATE.validate(topic); DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopic(topic).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..bbb1bf629f8f 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,6 +321,17 @@ 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);
+   * }
+   * 
+ * * * * @@ -356,6 +367,9 @@ public void close() throws IOException { */ public final Subscription createSubscription( String name, String topic, PushConfig pushConfig, int ackDeadlineSeconds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(name); + TOPIC_PATH_TEMPLATE.validate(topic); + Subscription request = Subscription.newBuilder() .setName(name) @@ -363,7 +377,6 @@ public final Subscription createSubscription( .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,6 +452,14 @@ 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);
+   * }
+   * 
+ * * * * @@ -418,9 +467,9 @@ public final ApiCallable createSubscriptionCallable( * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Subscription getSubscription(String subscription) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder().setSubscription(subscription).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,6 +537,16 @@ 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);
+   *   }
+   * }
+   * 
+ * * * * @@ -471,6 +554,7 @@ public final ApiCallable getSubscriptionCa * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final PageAccessor listSubscriptions(String project) { + PROJECT_PATH_TEMPLATE.validate(project); ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder().setProject(project).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,6 +667,14 @@ 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);
+   * }
+   * 
+ * * * * @@ -540,9 +682,9 @@ public final PageAccessor listSubscriptions(ListSubscriptionsReque * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void deleteSubscription(String subscription) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder().setSubscription(subscription).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,6 +754,16 @@ 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);
+   * }
+   * 
+ * * * * @@ -602,13 +778,14 @@ public final ApiCallable deleteSubscriptionCal */ public final void modifyAckDeadline( String subscription, List ackIds, int ackDeadlineSeconds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); + ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder() .setSubscription(subscription) .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,6 +864,15 @@ 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);
+   * }
+   * 
+ * * * * @@ -664,9 +882,10 @@ public final ApiCallable modifyAckDeadlineCalla * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void acknowledge(String subscription, List ackIds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); + AcknowledgeRequest request = AcknowledgeRequest.newBuilder().setSubscription(subscription).addAllAckIds(ackIds).build(); - acknowledge(request); } @@ -680,6 +899,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 +932,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,6 +963,16 @@ 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);
+   * }
+   * 
+ * * * * @@ -729,13 +986,14 @@ public final ApiCallable acknowledgeCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final PullResponse pull(String subscription, boolean returnImmediately, int maxMessages) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); + PullRequest request = PullRequest.newBuilder() .setSubscription(subscription) .setReturnImmediately(returnImmediately) .setMaxMessages(maxMessages) .build(); - return pull(request); } @@ -746,6 +1004,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 +1034,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,6 +1067,15 @@ 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);
+   * }
+   * 
+ * * * * @@ -794,12 +1089,13 @@ public final ApiCallable pullCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void modifyPushConfig(String subscription, PushConfig pushConfig) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); + ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder() .setSubscription(subscription) .setPushConfig(pushConfig) .build(); - modifyPushConfig(request); } @@ -812,6 +1108,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 +1140,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..7d8eb0f15e79 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,6 +277,14 @@ 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);
+   * }
+   * 
+ * * * * @@ -289,8 +297,8 @@ public void close() throws IOException { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Topic createTopic(String name) { + TOPIC_PATH_TEMPLATE.validate(name); Topic request = Topic.newBuilder().setName(name).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,6 +359,15 @@ 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);
+   * }
+   * 
+ * * * * @@ -335,9 +376,10 @@ public final ApiCallable createTopicCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final PublishResponse publish(String topic, List messages) { + TOPIC_PATH_TEMPLATE.validate(topic); + PublishRequest request = PublishRequest.newBuilder().setTopic(topic).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,6 +446,14 @@ 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);
+   * }
+   * 
+ * * * * @@ -383,8 +461,8 @@ public final ApiCallable publishCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Topic getTopic(String topic) { + TOPIC_PATH_TEMPLATE.validate(topic); GetTopicRequest request = GetTopicRequest.newBuilder().setTopic(topic).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,6 +521,16 @@ 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);
+   *   }
+   * }
+   * 
+ * * * * @@ -426,6 +538,7 @@ public final ApiCallable getTopicCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final PageAccessor listTopics(String project) { + PROJECT_PATH_TEMPLATE.validate(project); ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(project).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,6 +635,16 @@ 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);
+   *   }
+   * }
+   * 
+ * * * * @@ -479,6 +652,7 @@ public final ApiCallable listTopicsCallab * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final PageAccessor listTopicSubscriptions(String topic) { + TOPIC_PATH_TEMPLATE.validate(topic); ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder().setTopic(topic).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,6 +756,14 @@ 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);
+   * }
+   * 
+ * * * * @@ -539,8 +771,8 @@ public final PageAccessor listTopicSubscriptions(ListTopicSubscriptionsR * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void deleteTopic(String topic) { + TOPIC_PATH_TEMPLATE.validate(topic); DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopic(topic).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..bbb1bf629f8f 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,6 +321,17 @@ 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);
+   * }
+   * 
+ * * * * @@ -356,6 +367,9 @@ public void close() throws IOException { */ public final Subscription createSubscription( String name, String topic, PushConfig pushConfig, int ackDeadlineSeconds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(name); + TOPIC_PATH_TEMPLATE.validate(topic); + Subscription request = Subscription.newBuilder() .setName(name) @@ -363,7 +377,6 @@ public final Subscription createSubscription( .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,6 +452,14 @@ 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);
+   * }
+   * 
+ * * * * @@ -418,9 +467,9 @@ public final ApiCallable createSubscriptionCallable( * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Subscription getSubscription(String subscription) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder().setSubscription(subscription).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,6 +537,16 @@ 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);
+   *   }
+   * }
+   * 
+ * * * * @@ -471,6 +554,7 @@ public final ApiCallable getSubscriptionCa * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final PageAccessor listSubscriptions(String project) { + PROJECT_PATH_TEMPLATE.validate(project); ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder().setProject(project).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,6 +667,14 @@ 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);
+   * }
+   * 
+ * * * * @@ -540,9 +682,9 @@ public final PageAccessor listSubscriptions(ListSubscriptionsReque * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void deleteSubscription(String subscription) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder().setSubscription(subscription).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,6 +754,16 @@ 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);
+   * }
+   * 
+ * * * * @@ -602,13 +778,14 @@ public final ApiCallable deleteSubscriptionCal */ public final void modifyAckDeadline( String subscription, List ackIds, int ackDeadlineSeconds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); + ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder() .setSubscription(subscription) .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,6 +864,15 @@ 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);
+   * }
+   * 
+ * * * * @@ -664,9 +882,10 @@ public final ApiCallable modifyAckDeadlineCalla * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void acknowledge(String subscription, List ackIds) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); + AcknowledgeRequest request = AcknowledgeRequest.newBuilder().setSubscription(subscription).addAllAckIds(ackIds).build(); - acknowledge(request); } @@ -680,6 +899,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 +932,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,6 +963,16 @@ 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);
+   * }
+   * 
+ * * * * @@ -729,13 +986,14 @@ public final ApiCallable acknowledgeCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final PullResponse pull(String subscription, boolean returnImmediately, int maxMessages) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); + PullRequest request = PullRequest.newBuilder() .setSubscription(subscription) .setReturnImmediately(returnImmediately) .setMaxMessages(maxMessages) .build(); - return pull(request); } @@ -746,6 +1004,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 +1034,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,6 +1067,15 @@ 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);
+   * }
+   * 
+ * * * * @@ -794,12 +1089,13 @@ public final ApiCallable pullCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void modifyPushConfig(String subscription, PushConfig pushConfig) { + SUBSCRIPTION_PATH_TEMPLATE.validate(subscription); + ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder() .setSubscription(subscription) .setPushConfig(pushConfig) .build(); - modifyPushConfig(request); } @@ -812,6 +1108,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 +1140,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();
+   * }
+   * 
+ * * * */