{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-beam/pulls/comments/58916001","id":58916001,"diff_hunk":"@@ -0,0 +1,176 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package com.google.cloud.dataflow.sdk.io;\n+\n+import java.io.IOException;\n+import java.util.Collection;\n+\n+/**\n+ * A helper interface for talking to pub/sub via an underlying transport.\n+ */\n+public interface PubsubClient extends AutoCloseable {\n+  /**\n+   * Gracefully close the underlying transport.\n+   */\n+  @Override\n+  void close();\n+\n+  /**\n+   * A message to be sent to pub/sub.\n+   */\n+  class OutgoingMessage {\n+    /**\n+     * Underlying (encoded) element.\n+     */\n+    public final byte[] elementBytes;\n+\n+    /**\n+     * Timestamp for element (ms since epoch).\n+     */\n+    public final long timestampMsSinceEpoch;\n+\n+    public OutgoingMessage(byte[] elementBytes, long timestampMsSinceEpoch) {\n+      this.elementBytes = elementBytes;\n+      this.timestampMsSinceEpoch = timestampMsSinceEpoch;\n+    }\n+  }\n+\n+  /**\n+   * A message received from pub/sub.\n+   */\n+  class IncomingMessage {\n+    /**\n+     * Underlying (encoded) element.\n+     */\n+    public final byte[] elementBytes;\n+\n+    /**\n+     * Timestamp for element (ms since epoch). Either pub/sub's processing time,\n+     * or the custom timestamp associated with the message.\n+     */\n+    public final long timestampMsSinceEpoch;\n+\n+    /**\n+     * Timestamp (in system time) at which we requested the message (ms since epoch).\n+     */\n+    public final long requestTimeMsSinceEpoch;\n+\n+    /**\n+     * Id to pass back to pub/sub to acknowledge receipt of this message.\n+     */\n+    public final String ackId;\n+\n+    /**\n+     * Id to pass to the runner to distinguish this message from all others.\n+     */\n+    public final byte[] recordId;\n+\n+    public IncomingMessage(\n+        byte[] elementBytes,\n+        long timestampMsSinceEpoch,\n+        long requestTimeMsSinceEpoch,\n+        String ackId,\n+        byte[] recordId) {\n+      this.elementBytes = elementBytes;\n+      this.timestampMsSinceEpoch = timestampMsSinceEpoch;\n+      this.requestTimeMsSinceEpoch = requestTimeMsSinceEpoch;\n+      this.ackId = ackId;\n+      this.recordId = recordId;\n+    }\n+  }\n+\n+  /**\n+   * Publish {@code outgoingMessages} to pub/sub {@code topic}. Return number of messages\n+   * published.\n+   *\n+   * @throws IOException\n+   */\n+  int publish(String topic, Iterable<OutgoingMessage> outgoingMessages) throws IOException;\n+\n+  /**\n+   * Request the next batch of up to {@code batchSize} messages from {@code subscription}.\n+   * Return the received messages, or empty collection if none were available. Does not\n+   * wait for messages to arrive. Returned messages will record heir request time\n+   * as {@code requestTimeMsSinceEpoch}.\n+   *\n+   * @throws IOException\n+   */\n+  Collection<IncomingMessage> pull(","path":"sdks/java/core/src/main/java/com/google/cloud/dataflow/sdk/io/PubsubClient.java","position":114,"original_position":114,"commit_id":"9fcdf11609837544c5cd6d821fbd8a41e72a564f","original_commit_id":"9fcdf11609837544c5cd6d821fbd8a41e72a564f","user":{"login":"mshields822","id":11642236,"avatar_url":"https://avatars.githubusercontent.com/u/11642236?v=3","gravatar_id":"","url":"https://api.github.com/users/mshields822","html_url":"https://github.com/mshields822","followers_url":"https://api.github.com/users/mshields822/followers","following_url":"https://api.github.com/users/mshields822/following{/other_user}","gists_url":"https://api.github.com/users/mshields822/gists{/gist_id}","starred_url":"https://api.github.com/users/mshields822/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mshields822/subscriptions","organizations_url":"https://api.github.com/users/mshields822/orgs","repos_url":"https://api.github.com/users/mshields822/repos","events_url":"https://api.github.com/users/mshields822/events{/privacy}","received_events_url":"https://api.github.com/users/mshields822/received_events","type":"User","site_admin":false},"body":"This class a) captures common bookkeeping between unbounded pubsub source/sink and benchmarking code in a way which avoids making any grpc or protoc details public b) provides a hook for (as yet unwritten) mocks. Feels like scope creep for it to go any further.\r\n","created_at":"2016-04-07T17:56:08Z","updated_at":"2016-04-07T17:56:08Z","html_url":"https://github.com/apache/incubator-beam/pull/120#discussion_r58916001","pull_request_url":"https://api.github.com/repos/apache/incubator-beam/pulls/120","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/comments/58916001"},"html":{"href":"https://github.com/apache/incubator-beam/pull/120#discussion_r58916001"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/120"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-beam/pulls/120","id":65237635,"html_url":"https://github.com/apache/incubator-beam/pull/120","diff_url":"https://github.com/apache/incubator-beam/pull/120.diff","patch_url":"https://github.com/apache/incubator-beam/pull/120.patch","issue_url":"https://api.github.com/repos/apache/incubator-beam/issues/120","number":120,"state":"open","locked":false,"title":"[BEAM-53] Pub/sub client with gRPC implementation","user":{"login":"mshields822","id":11642236,"avatar_url":"https://avatars.githubusercontent.com/u/11642236?v=3","gravatar_id":"","url":"https://api.github.com/users/mshields822","html_url":"https://github.com/mshields822","followers_url":"https://api.github.com/users/mshields822/followers","following_url":"https://api.github.com/users/mshields822/following{/other_user}","gists_url":"https://api.github.com/users/mshields822/gists{/gist_id}","starred_url":"https://api.github.com/users/mshields822/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mshields822/subscriptions","organizations_url":"https://api.github.com/users/mshields822/orgs","repos_url":"https://api.github.com/users/mshields822/repos","events_url":"https://api.github.com/users/mshields822/events{/privacy}","received_events_url":"https://api.github.com/users/mshields822/received_events","type":"User","site_admin":false},"body":"Support pub/sub via gRPC.\r\nWill later use for pure Java pub/sub source/sink.","created_at":"2016-04-05T01:15:52Z","updated_at":"2016-04-07T17:56:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e8c2e4d144fbae81b821334140d02531f78ea65a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-beam/pulls/120/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-beam/pulls/120/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-beam/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-beam/issues/120/comments","statuses_url":"https://api.github.com/repos/apache/incubator-beam/statuses/9fcdf11609837544c5cd6d821fbd8a41e72a564f","head":{"label":"mshields822:pubsub-grpc","ref":"pubsub-grpc","sha":"9fcdf11609837544c5cd6d821fbd8a41e72a564f","user":{"login":"mshields822","id":11642236,"avatar_url":"https://avatars.githubusercontent.com/u/11642236?v=3","gravatar_id":"","url":"https://api.github.com/users/mshields822","html_url":"https://github.com/mshields822","followers_url":"https://api.github.com/users/mshields822/followers","following_url":"https://api.github.com/users/mshields822/following{/other_user}","gists_url":"https://api.github.com/users/mshields822/gists{/gist_id}","starred_url":"https://api.github.com/users/mshields822/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mshields822/subscriptions","organizations_url":"https://api.github.com/users/mshields822/orgs","repos_url":"https://api.github.com/users/mshields822/repos","events_url":"https://api.github.com/users/mshields822/events{/privacy}","received_events_url":"https://api.github.com/users/mshields822/received_events","type":"User","site_admin":false},"repo":{"id":52641502,"name":"incubator-beam","full_name":"mshields822/incubator-beam","owner":{"login":"mshields822","id":11642236,"avatar_url":"https://avatars.githubusercontent.com/u/11642236?v=3","gravatar_id":"","url":"https://api.github.com/users/mshields822","html_url":"https://github.com/mshields822","followers_url":"https://api.github.com/users/mshields822/followers","following_url":"https://api.github.com/users/mshields822/following{/other_user}","gists_url":"https://api.github.com/users/mshields822/gists{/gist_id}","starred_url":"https://api.github.com/users/mshields822/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mshields822/subscriptions","organizations_url":"https://api.github.com/users/mshields822/orgs","repos_url":"https://api.github.com/users/mshields822/repos","events_url":"https://api.github.com/users/mshields822/events{/privacy}","received_events_url":"https://api.github.com/users/mshields822/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mshields822/incubator-beam","description":"Mirror of Apache Beam (Incubating)","fork":true,"url":"https://api.github.com/repos/mshields822/incubator-beam","forks_url":"https://api.github.com/repos/mshields822/incubator-beam/forks","keys_url":"https://api.github.com/repos/mshields822/incubator-beam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mshields822/incubator-beam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mshields822/incubator-beam/teams","hooks_url":"https://api.github.com/repos/mshields822/incubator-beam/hooks","issue_events_url":"https://api.github.com/repos/mshields822/incubator-beam/issues/events{/number}","events_url":"https://api.github.com/repos/mshields822/incubator-beam/events","assignees_url":"https://api.github.com/repos/mshields822/incubator-beam/assignees{/user}","branches_url":"https://api.github.com/repos/mshields822/incubator-beam/branches{/branch}","tags_url":"https://api.github.com/repos/mshields822/incubator-beam/tags","blobs_url":"https://api.github.com/repos/mshields822/incubator-beam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mshields822/incubator-beam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mshields822/incubator-beam/git/refs{/sha}","trees_url":"https://api.github.com/repos/mshields822/incubator-beam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mshields822/incubator-beam/statuses/{sha}","languages_url":"https://api.github.com/repos/mshields822/incubator-beam/languages","stargazers_url":"https://api.github.com/repos/mshields822/incubator-beam/stargazers","contributors_url":"https://api.github.com/repos/mshields822/incubator-beam/contributors","subscribers_url":"https://api.github.com/repos/mshields822/incubator-beam/subscribers","subscription_url":"https://api.github.com/repos/mshields822/incubator-beam/subscription","commits_url":"https://api.github.com/repos/mshields822/incubator-beam/commits{/sha}","git_commits_url":"https://api.github.com/repos/mshields822/incubator-beam/git/commits{/sha}","comments_url":"https://api.github.com/repos/mshields822/incubator-beam/comments{/number}","issue_comment_url":"https://api.github.com/repos/mshields822/incubator-beam/issues/comments{/number}","contents_url":"https://api.github.com/repos/mshields822/incubator-beam/contents/{+path}","compare_url":"https://api.github.com/repos/mshields822/incubator-beam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mshields822/incubator-beam/merges","archive_url":"https://api.github.com/repos/mshields822/incubator-beam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mshields822/incubator-beam/downloads","issues_url":"https://api.github.com/repos/mshields822/incubator-beam/issues{/number}","pulls_url":"https://api.github.com/repos/mshields822/incubator-beam/pulls{/number}","milestones_url":"https://api.github.com/repos/mshields822/incubator-beam/milestones{/number}","notifications_url":"https://api.github.com/repos/mshields822/incubator-beam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mshields822/incubator-beam/labels{/name}","releases_url":"https://api.github.com/repos/mshields822/incubator-beam/releases{/id}","deployments_url":"https://api.github.com/repos/mshields822/incubator-beam/deployments","created_at":"2016-02-27T00:22:15Z","updated_at":"2016-02-27T00:22:17Z","pushed_at":"2016-04-07T17:46:21Z","git_url":"git://github.com/mshields822/incubator-beam.git","ssh_url":"git@github.com:mshields822/incubator-beam.git","clone_url":"https://github.com/mshields822/incubator-beam.git","svn_url":"https://github.com/mshields822/incubator-beam","homepage":null,"size":11830,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"ccbf2b8025473d30121d1a5b17ba7118abefcb50","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":50904245,"name":"incubator-beam","full_name":"apache/incubator-beam","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-beam","description":"Mirror of Apache Beam (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-beam","forks_url":"https://api.github.com/repos/apache/incubator-beam/forks","keys_url":"https://api.github.com/repos/apache/incubator-beam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-beam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-beam/teams","hooks_url":"https://api.github.com/repos/apache/incubator-beam/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-beam/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-beam/events","assignees_url":"https://api.github.com/repos/apache/incubator-beam/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-beam/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-beam/tags","blobs_url":"https://api.github.com/repos/apache/incubator-beam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-beam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-beam/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-beam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-beam/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-beam/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-beam/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-beam/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-beam/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-beam/subscription","commits_url":"https://api.github.com/repos/apache/incubator-beam/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-beam/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-beam/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-beam/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-beam/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-beam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-beam/merges","archive_url":"https://api.github.com/repos/apache/incubator-beam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-beam/downloads","issues_url":"https://api.github.com/repos/apache/incubator-beam/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-beam/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-beam/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-beam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-beam/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-beam/releases{/id}","deployments_url":"https://api.github.com/repos/apache/incubator-beam/deployments","created_at":"2016-02-02T08:00:06Z","updated_at":"2016-04-07T11:31:39Z","pushed_at":"2016-04-07T17:43:22Z","git_url":"git://github.com/apache/incubator-beam.git","ssh_url":"git@github.com:apache/incubator-beam.git","clone_url":"https://github.com/apache/incubator-beam.git","svn_url":"https://github.com/apache/incubator-beam","homepage":null,"size":12347,"stargazers_count":118,"watchers_count":118,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":57,"mirror_url":"git://git.apache.org/incubator-beam.git","open_issues_count":23,"forks":57,"open_issues":23,"watchers":118,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/120"},"html":{"href":"https://github.com/apache/incubator-beam/pull/120"},"issue":{"href":"https://api.github.com/repos/apache/incubator-beam/issues/120"},"comments":{"href":"https://api.github.com/repos/apache/incubator-beam/issues/120/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/120/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/120/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-beam/statuses/9fcdf11609837544c5cd6d821fbd8a41e72a564f"}}}}