Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make pubsub publish and pull package-private #1544

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

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

private static final PathTemplate PROJECT_PATH_TEMPLATE =
PathTemplate.createWithoutUrlEncoding("projects/{project}");

private static final PathTemplate TOPIC_PATH_TEMPLATE =
PathTemplate.createWithoutUrlEncoding("projects/{project}/topics/{topic}");

/** Formats a string containing the fully-qualified path to represent a project resource. */
public static final String formatProjectName(String project) {
return PROJECT_PATH_TEMPLATE.instantiate("project", project);
}

/** Formats a string containing the fully-qualified path to represent a topic resource. */
public static final String formatTopicName(String project, String topic) {
return TOPIC_PATH_TEMPLATE.instantiate(
"project", project,
"topic", topic);
}

/** Parses the project from the given fully-qualified path which represents a project resource. */
public static final String parseProjectFromProjectName(String projectName) {
return PROJECT_PATH_TEMPLATE.parse(projectName).get("project");
}

/** Parses the project from the given fully-qualified path which represents a topic resource. */
public static final String parseProjectFromTopicName(String topicName) {
return TOPIC_PATH_TEMPLATE.parse(topicName).get("project");
}

/** Parses the topic from the given fully-qualified path which represents a topic resource. */
public static final String parseTopicFromTopicName(String topicName) {
return TOPIC_PATH_TEMPLATE.parse(topicName).get("topic");
}

/** Constructs an instance of PublisherClient with default settings. */
public static final PublisherClient create() throws IOException {
return create(PublisherSettings.defaultBuilder().build());
Expand Down Expand Up @@ -327,11 +295,13 @@ public final UnaryCallable<Topic, Topic> createTopicCallable() {
* }
* </code></pre>
*
* @param topic The messages in the request will be published on this topic.
* @param topic The messages in the request will be published on this topic. Format is
* `projects/{project}/topics/{topic}`.
* @param messages The messages to publish.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final PublishResponse publish(TopicName topic, List<PubsubMessage> messages) {
/* package-private */ final PublishResponse publish(
TopicName topic, List<PubsubMessage> messages) {

PublishRequest request =
PublishRequest.newBuilder().setTopicWithTopicName(topic).addAllMessages(messages).build();
Expand Down Expand Up @@ -395,7 +365,7 @@ public final PublishResponse publish(PublishRequest request) {
* }
* </code></pre>
*/
public final UnaryCallable<PublishRequest, PublishResponse> publishCallable() {
/* package-private */ final UnaryCallable<PublishRequest, PublishResponse> publishCallable() {
return publishCallable;
}

Expand All @@ -412,7 +382,7 @@ public final UnaryCallable<PublishRequest, PublishResponse> publishCallable() {
* }
* </code></pre>
*
* @param topic The name of the topic to get.
* @param topic The name of the topic to get. Format is `projects/{project}/topics/{topic}`.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final Topic getTopic(TopicName topic) {
Expand Down Expand Up @@ -481,7 +451,8 @@ public final UnaryCallable<GetTopicRequest, Topic> getTopicCallable() {
* }
* </code></pre>
*
* @param project The name of the cloud project that topics belong to.
* @param project The name of the cloud project that topics belong to. Format is
* `projects/{project}`.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final ListTopicsPagedResponse listTopics(ProjectName project) {
Expand Down Expand Up @@ -585,7 +556,8 @@ public final UnaryCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCall
* }
* </code></pre>
*
* @param topic The name of the topic that subscriptions are attached to.
* @param topic The name of the topic that subscriptions are attached to. Format is
* `projects/{project}/topics/{topic}`.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions(TopicName topic) {
Expand Down Expand Up @@ -693,7 +665,7 @@ public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions(
* }
* </code></pre>
*
* @param topic Name of the topic to delete.
* @param topic Name of the topic to delete. Format is `projects/{project}/topics/{topic}`.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final void deleteTopic(TopicName topic) {
Expand Down Expand Up @@ -762,7 +734,7 @@ public final UnaryCallable<DeleteTopicRequest, Empty> deleteTopicCallable() {
*
* <pre><code>
* try (PublisherClient publisherClient = PublisherClient.create()) {
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
* Policy policy = Policy.newBuilder().build();
* Policy response = publisherClient.setIamPolicy(formattedResource, policy);
* }
Expand All @@ -777,7 +749,7 @@ public final UnaryCallable<DeleteTopicRequest, Empty> deleteTopicCallable() {
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final Policy setIamPolicy(String resource, Policy policy) {
TOPIC_PATH_TEMPLATE.validate(resource, "setIamPolicy");

SetIamPolicyRequest request =
SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build();
return setIamPolicy(request);
Expand All @@ -791,7 +763,7 @@ public final Policy setIamPolicy(String resource, Policy policy) {
*
* <pre><code>
* try (PublisherClient publisherClient = PublisherClient.create()) {
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
* Policy policy = Policy.newBuilder().build();
* SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
* .setResource(formattedResource)
Expand All @@ -816,7 +788,7 @@ public final Policy setIamPolicy(SetIamPolicyRequest request) {
*
* <pre><code>
* try (PublisherClient publisherClient = PublisherClient.create()) {
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
* Policy policy = Policy.newBuilder().build();
* SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
* .setResource(formattedResource)
Expand All @@ -841,7 +813,7 @@ public final UnaryCallable<SetIamPolicyRequest, Policy> setIamPolicyCallable() {
*
* <pre><code>
* try (PublisherClient publisherClient = PublisherClient.create()) {
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
* Policy response = publisherClient.getIamPolicy(formattedResource);
* }
* </code></pre>
Expand All @@ -852,7 +824,7 @@ public final UnaryCallable<SetIamPolicyRequest, Policy> setIamPolicyCallable() {
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final Policy getIamPolicy(String resource) {
TOPIC_PATH_TEMPLATE.validate(resource, "getIamPolicy");

GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build();
return getIamPolicy(request);
}
Expand All @@ -866,7 +838,7 @@ public final Policy getIamPolicy(String resource) {
*
* <pre><code>
* try (PublisherClient publisherClient = PublisherClient.create()) {
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
* GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
* .setResource(formattedResource)
* .build();
Expand All @@ -890,7 +862,7 @@ private final Policy getIamPolicy(GetIamPolicyRequest request) {
*
* <pre><code>
* try (PublisherClient publisherClient = PublisherClient.create()) {
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
* GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
* .setResource(formattedResource)
* .build();
Expand All @@ -906,13 +878,14 @@ public final UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns permissions that a caller has on the specified resource.
* Returns permissions that a caller has on the specified resource. If the resource does not
* exist, this will return an empty set of permissions, not a NOT_FOUND error.
*
* <p>Sample code:
*
* <pre><code>
* try (PublisherClient publisherClient = PublisherClient.create()) {
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
* List&lt;String&gt; permissions = new ArrayList&lt;&gt;();
* TestIamPermissionsResponse response = publisherClient.testIamPermissions(formattedResource, permissions);
* }
Expand All @@ -928,7 +901,7 @@ public final UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
*/
public final TestIamPermissionsResponse testIamPermissions(
String resource, List<String> permissions) {
TOPIC_PATH_TEMPLATE.validate(resource, "testIamPermissions");

TestIamPermissionsRequest request =
TestIamPermissionsRequest.newBuilder()
.setResource(resource)
Expand All @@ -939,13 +912,14 @@ public final TestIamPermissionsResponse testIamPermissions(

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

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns permissions that a caller has on the specified resource.
* Returns permissions that a caller has on the specified resource. If the resource does not
* exist, this will return an empty set of permissions, not a NOT_FOUND error.
*
* <p>Sample code:
*
* <pre><code>
* try (PublisherClient publisherClient = PublisherClient.create()) {
* String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
* String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
* List&lt;String&gt; permissions = new ArrayList&lt;&gt;();
* TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
* .setResource(formattedResource)
Expand Down
Loading