Skip to content

Commit 1f68932

Browse files
authored
make pubsub publish and pull package-private (#1544)
1 parent 5ee13e7 commit 1f68932

File tree

7 files changed

+299
-183
lines changed

7 files changed

+299
-183
lines changed

google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherClient.java

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import com.google.api.gax.grpc.ChannelAndExecutor;
2222
import com.google.api.gax.grpc.UnaryCallable;
23-
import com.google.api.gax.protobuf.PathTemplate;
2423
import com.google.iam.v1.GetIamPolicyRequest;
2524
import com.google.iam.v1.Policy;
2625
import com.google.iam.v1.SetIamPolicyRequest;
@@ -53,6 +52,8 @@
5352
* Service Description: The service that an application uses to manipulate topics, and to send
5453
* messages to a topic.
5554
*
55+
* <p>To publish messages to a topic, see the Publisher class.
56+
*
5657
* <p>This class provides the ability to make remote calls to the backing service through method
5758
* calls that map to API methods. Sample code to get started:
5859
*
@@ -127,39 +128,6 @@ public class PublisherClient implements AutoCloseable {
127128
private final UnaryCallable<TestIamPermissionsRequest, TestIamPermissionsResponse>
128129
testIamPermissionsCallable;
129130

130-
private static final PathTemplate PROJECT_PATH_TEMPLATE =
131-
PathTemplate.createWithoutUrlEncoding("projects/{project}");
132-
133-
private static final PathTemplate TOPIC_PATH_TEMPLATE =
134-
PathTemplate.createWithoutUrlEncoding("projects/{project}/topics/{topic}");
135-
136-
/** Formats a string containing the fully-qualified path to represent a project resource. */
137-
public static final String formatProjectName(String project) {
138-
return PROJECT_PATH_TEMPLATE.instantiate("project", project);
139-
}
140-
141-
/** Formats a string containing the fully-qualified path to represent a topic resource. */
142-
public static final String formatTopicName(String project, String topic) {
143-
return TOPIC_PATH_TEMPLATE.instantiate(
144-
"project", project,
145-
"topic", topic);
146-
}
147-
148-
/** Parses the project from the given fully-qualified path which represents a project resource. */
149-
public static final String parseProjectFromProjectName(String projectName) {
150-
return PROJECT_PATH_TEMPLATE.parse(projectName).get("project");
151-
}
152-
153-
/** Parses the project from the given fully-qualified path which represents a topic resource. */
154-
public static final String parseProjectFromTopicName(String topicName) {
155-
return TOPIC_PATH_TEMPLATE.parse(topicName).get("project");
156-
}
157-
158-
/** Parses the topic from the given fully-qualified path which represents a topic resource. */
159-
public static final String parseTopicFromTopicName(String topicName) {
160-
return TOPIC_PATH_TEMPLATE.parse(topicName).get("topic");
161-
}
162-
163131
/** Constructs an instance of PublisherClient with default settings. */
164132
public static final PublisherClient create() throws IOException {
165133
return create(PublisherSettings.defaultBuilder().build());
@@ -327,11 +295,13 @@ public final UnaryCallable<Topic, Topic> createTopicCallable() {
327295
* }
328296
* </code></pre>
329297
*
330-
* @param topic The messages in the request will be published on this topic.
298+
* @param topic The messages in the request will be published on this topic. Format is
299+
* `projects/{project}/topics/{topic}`.
331300
* @param messages The messages to publish.
332301
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
333302
*/
334-
public final PublishResponse publish(TopicName topic, List<PubsubMessage> messages) {
303+
/* package-private */ final PublishResponse publish(
304+
TopicName topic, List<PubsubMessage> messages) {
335305

336306
PublishRequest request =
337307
PublishRequest.newBuilder().setTopicWithTopicName(topic).addAllMessages(messages).build();
@@ -395,7 +365,7 @@ public final PublishResponse publish(PublishRequest request) {
395365
* }
396366
* </code></pre>
397367
*/
398-
public final UnaryCallable<PublishRequest, PublishResponse> publishCallable() {
368+
/* package-private */ final UnaryCallable<PublishRequest, PublishResponse> publishCallable() {
399369
return publishCallable;
400370
}
401371

@@ -412,7 +382,7 @@ public final UnaryCallable<PublishRequest, PublishResponse> publishCallable() {
412382
* }
413383
* </code></pre>
414384
*
415-
* @param topic The name of the topic to get.
385+
* @param topic The name of the topic to get. Format is `projects/{project}/topics/{topic}`.
416386
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
417387
*/
418388
public final Topic getTopic(TopicName topic) {
@@ -481,7 +451,8 @@ public final UnaryCallable<GetTopicRequest, Topic> getTopicCallable() {
481451
* }
482452
* </code></pre>
483453
*
484-
* @param project The name of the cloud project that topics belong to.
454+
* @param project The name of the cloud project that topics belong to. Format is
455+
* `projects/{project}`.
485456
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
486457
*/
487458
public final ListTopicsPagedResponse listTopics(ProjectName project) {
@@ -585,7 +556,8 @@ public final UnaryCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCall
585556
* }
586557
* </code></pre>
587558
*
588-
* @param topic The name of the topic that subscriptions are attached to.
559+
* @param topic The name of the topic that subscriptions are attached to. Format is
560+
* `projects/{project}/topics/{topic}`.
589561
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
590562
*/
591563
public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions(TopicName topic) {
@@ -693,7 +665,7 @@ public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions(
693665
* }
694666
* </code></pre>
695667
*
696-
* @param topic Name of the topic to delete.
668+
* @param topic Name of the topic to delete. Format is `projects/{project}/topics/{topic}`.
697669
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
698670
*/
699671
public final void deleteTopic(TopicName topic) {
@@ -762,7 +734,7 @@ public final UnaryCallable<DeleteTopicRequest, Empty> deleteTopicCallable() {
762734
*
763735
* <pre><code>
764736
* try (PublisherClient publisherClient = PublisherClient.create()) {
765-
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
737+
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
766738
* Policy policy = Policy.newBuilder().build();
767739
* Policy response = publisherClient.setIamPolicy(formattedResource, policy);
768740
* }
@@ -777,7 +749,7 @@ public final UnaryCallable<DeleteTopicRequest, Empty> deleteTopicCallable() {
777749
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
778750
*/
779751
public final Policy setIamPolicy(String resource, Policy policy) {
780-
TOPIC_PATH_TEMPLATE.validate(resource, "setIamPolicy");
752+
781753
SetIamPolicyRequest request =
782754
SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build();
783755
return setIamPolicy(request);
@@ -791,7 +763,7 @@ public final Policy setIamPolicy(String resource, Policy policy) {
791763
*
792764
* <pre><code>
793765
* try (PublisherClient publisherClient = PublisherClient.create()) {
794-
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
766+
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
795767
* Policy policy = Policy.newBuilder().build();
796768
* SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
797769
* .setResource(formattedResource)
@@ -816,7 +788,7 @@ public final Policy setIamPolicy(SetIamPolicyRequest request) {
816788
*
817789
* <pre><code>
818790
* try (PublisherClient publisherClient = PublisherClient.create()) {
819-
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
791+
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
820792
* Policy policy = Policy.newBuilder().build();
821793
* SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
822794
* .setResource(formattedResource)
@@ -841,7 +813,7 @@ public final UnaryCallable<SetIamPolicyRequest, Policy> setIamPolicyCallable() {
841813
*
842814
* <pre><code>
843815
* try (PublisherClient publisherClient = PublisherClient.create()) {
844-
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
816+
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
845817
* Policy response = publisherClient.getIamPolicy(formattedResource);
846818
* }
847819
* </code></pre>
@@ -852,7 +824,7 @@ public final UnaryCallable<SetIamPolicyRequest, Policy> setIamPolicyCallable() {
852824
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
853825
*/
854826
public final Policy getIamPolicy(String resource) {
855-
TOPIC_PATH_TEMPLATE.validate(resource, "getIamPolicy");
827+
856828
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build();
857829
return getIamPolicy(request);
858830
}
@@ -866,7 +838,7 @@ public final Policy getIamPolicy(String resource) {
866838
*
867839
* <pre><code>
868840
* try (PublisherClient publisherClient = PublisherClient.create()) {
869-
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
841+
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
870842
* GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
871843
* .setResource(formattedResource)
872844
* .build();
@@ -890,7 +862,7 @@ private final Policy getIamPolicy(GetIamPolicyRequest request) {
890862
*
891863
* <pre><code>
892864
* try (PublisherClient publisherClient = PublisherClient.create()) {
893-
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
865+
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
894866
* GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
895867
* .setResource(formattedResource)
896868
* .build();
@@ -906,13 +878,14 @@ public final UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
906878

907879
// AUTO-GENERATED DOCUMENTATION AND METHOD
908880
/**
909-
* Returns permissions that a caller has on the specified resource.
881+
* Returns permissions that a caller has on the specified resource. If the resource does not
882+
* exist, this will return an empty set of permissions, not a NOT_FOUND error.
910883
*
911884
* <p>Sample code:
912885
*
913886
* <pre><code>
914887
* try (PublisherClient publisherClient = PublisherClient.create()) {
915-
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
888+
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
916889
* List&lt;String&gt; permissions = new ArrayList&lt;&gt;();
917890
* TestIamPermissionsResponse response = publisherClient.testIamPermissions(formattedResource, permissions);
918891
* }
@@ -928,7 +901,7 @@ public final UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
928901
*/
929902
public final TestIamPermissionsResponse testIamPermissions(
930903
String resource, List<String> permissions) {
931-
TOPIC_PATH_TEMPLATE.validate(resource, "testIamPermissions");
904+
932905
TestIamPermissionsRequest request =
933906
TestIamPermissionsRequest.newBuilder()
934907
.setResource(resource)
@@ -939,13 +912,14 @@ public final TestIamPermissionsResponse testIamPermissions(
939912

940913
// AUTO-GENERATED DOCUMENTATION AND METHOD
941914
/**
942-
* Returns permissions that a caller has on the specified resource.
915+
* Returns permissions that a caller has on the specified resource. If the resource does not
916+
* exist, this will return an empty set of permissions, not a NOT_FOUND error.
943917
*
944918
* <p>Sample code:
945919
*
946920
* <pre><code>
947921
* try (PublisherClient publisherClient = PublisherClient.create()) {
948-
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
922+
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
949923
* List&lt;String&gt; permissions = new ArrayList&lt;&gt;();
950924
* TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
951925
* .setResource(formattedResource)
@@ -964,13 +938,14 @@ public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsReq
964938

965939
// AUTO-GENERATED DOCUMENTATION AND METHOD
966940
/**
967-
* Returns permissions that a caller has on the specified resource.
941+
* Returns permissions that a caller has on the specified resource. If the resource does not
942+
* exist, this will return an empty set of permissions, not a NOT_FOUND error.
968943
*
969944
* <p>Sample code:
970945
*
971946
* <pre><code>
972947
* try (PublisherClient publisherClient = PublisherClient.create()) {
973-
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
948+
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
974949
* List&lt;String&gt; permissions = new ArrayList&lt;&gt;();
975950
* TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
976951
* .setResource(formattedResource)

0 commit comments

Comments
 (0)