{"action":"created","comment":{"url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/comments/75887455","id":75887455,"diff_hunk":"@@ -0,0 +1,150 @@\n+/**\n+ * Copyright 2016 The OpenZipkin Authors\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except\n+ * in compliance 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 distributed under the License\n+ * is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\n+ * or implied. See the License for the specific language governing permissions and limitations under\n+ * the License.\n+ */\n+package zipkin.reporter.internal;\n+\n+import com.google.auto.value.AutoValue;\n+import java.util.Collections;\n+import java.util.LinkedList;\n+import java.util.List;\n+import java.util.concurrent.locks.Condition;\n+import java.util.concurrent.locks.ReentrantLock;\n+import zipkin.internal.Nullable;\n+\n+/** Special queue that can measure the size of entries as they are added. */\n+public final class BoundedQueue<E> {\n+\n+  public interface ByteCounter<E> {\n+    /** Returns the count of bytes in the element. */\n+    int byteCount(E element);\n+  }\n+\n+  final int maxBatchSize;\n+\n+  final ReentrantLock lock = new ReentrantLock(false);\n+  final Condition available = lock.newCondition();\n+\n+  @Nullable final ByteCounter<E> byteCounter;\n+  final int maxByteCount; // only honored when byteCounter is set\n+\n+  final Object[] items;\n+  int count;\n+  int writeIndex;\n+  int readIndex;\n+\n+  public static <E> BoundedQueue<E> create(int size, int maxBatchSize) {\n+    return new BoundedQueue<>(size, maxBatchSize, null, Integer.MAX_VALUE);\n+  }\n+\n+  public static <E> BoundedQueue<E> create(int size, ByteCounter<E> byteCounter, int maxByteCount) {\n+    return new BoundedQueue<>(size, Integer.MAX_VALUE, byteCounter, maxByteCount);\n+  }\n+\n+  @AutoValue\n+  static abstract class ElementWithByteCount<E> {\n+    static <E> ElementWithByteCount<E> create(E element, int byteCount) {\n+      return new AutoValue_BoundedQueue_ElementWithByteCount<>(element, byteCount);\n+    }\n+\n+    abstract E element();\n+\n+    abstract int byteCount();\n+  }\n+\n+  BoundedQueue(int size, int maxBatchSize, ByteCounter<E> byteCounter, int maxByteCount) {\n+    this.items = new Object[size]; // cannot instantiate a generic type\n+    this.maxBatchSize = maxBatchSize;\n+    this.byteCounter = byteCounter;\n+    this.maxByteCount = maxByteCount;\n+  }\n+\n+  /** Returns true if the element could be added or false if the queue is full */\n+  public boolean offer(E element) {\n+    Object toAdd = element;\n+    if (byteCounter != null) {\n+      int byteCount = byteCounter.byteCount(element);","path":"core/src/main/java/zipkin/reporter/internal/BoundedQueue.java","position":75,"original_position":75,"commit_id":"a4fd2cf9406f13fe83d31a3fce7603fff0e39fb6","original_commit_id":"a4fd2cf9406f13fe83d31a3fce7603fff0e39fb6","user":{"login":"felixbarny","id":2163464,"avatar_url":"https://avatars.githubusercontent.com/u/2163464?v=3","gravatar_id":"","url":"https://api.github.com/users/felixbarny","html_url":"https://github.com/felixbarny","followers_url":"https://api.github.com/users/felixbarny/followers","following_url":"https://api.github.com/users/felixbarny/following{/other_user}","gists_url":"https://api.github.com/users/felixbarny/gists{/gist_id}","starred_url":"https://api.github.com/users/felixbarny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felixbarny/subscriptions","organizations_url":"https://api.github.com/users/felixbarny/orgs","repos_url":"https://api.github.com/users/felixbarny/repos","events_url":"https://api.github.com/users/felixbarny/events{/privacy}","received_events_url":"https://api.github.com/users/felixbarny/received_events","type":"User","site_admin":false},"body":"Does that mean spans have to be serialized twice? Once to get the size and once more to actually send them over the wire?","created_at":"2016-08-23T15:14:12Z","updated_at":"2016-08-23T15:14:12Z","html_url":"https://github.com/openzipkin/zipkin-reporter-java/pull/7#discussion_r75887455","pull_request_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/comments/75887455"},"html":{"href":"https://github.com/openzipkin/zipkin-reporter-java/pull/7#discussion_r75887455"},"pull_request":{"href":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/7","id":82101288,"html_url":"https://github.com/openzipkin/zipkin-reporter-java/pull/7","diff_url":"https://github.com/openzipkin/zipkin-reporter-java/pull/7.diff","patch_url":"https://github.com/openzipkin/zipkin-reporter-java/pull/7.patch","issue_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/issues/7","number":7,"state":"open","locked":false,"title":"WORK IN PROGRESS: Reporter","user":{"login":"adriancole","id":64215,"avatar_url":"https://avatars.githubusercontent.com/u/64215?v=3","gravatar_id":"","url":"https://api.github.com/users/adriancole","html_url":"https://github.com/adriancole","followers_url":"https://api.github.com/users/adriancole/followers","following_url":"https://api.github.com/users/adriancole/following{/other_user}","gists_url":"https://api.github.com/users/adriancole/gists{/gist_id}","starred_url":"https://api.github.com/users/adriancole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adriancole/subscriptions","organizations_url":"https://api.github.com/users/adriancole/orgs","repos_url":"https://api.github.com/users/adriancole/repos","events_url":"https://api.github.com/users/adriancole/events{/privacy}","received_events_url":"https://api.github.com/users/adriancole/received_events","type":"User","site_admin":false},"body":"This includes a Reporter which is very similar to the following:\r\n* Finagle's DeadlineSpanMap\r\n* zipkin-finagle's SpanRecorder\r\n* zipkin-js's Recorder\r\n* Brave's SpanCollector\r\n* HTrace's ZipkinSpanReceiver\r\n* Wingtips' ZipkinSpanSender\r\n* Sleuth's ZipkinSpanReporter\r\n* Jaeger's Reporter\r\n\r\nand.. probably many others.","created_at":"2016-08-21T09:34:55Z","updated_at":"2016-08-23T15:14:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ee975fa59c52e10800461862db4786ce185c92cb","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/7/commits","review_comments_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/7/comments","review_comment_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/issues/7/comments","statuses_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/statuses/a4fd2cf9406f13fe83d31a3fce7603fff0e39fb6","head":{"label":"openzipkin:reporter","ref":"reporter","sha":"a4fd2cf9406f13fe83d31a3fce7603fff0e39fb6","user":{"login":"openzipkin","id":11860887,"avatar_url":"https://avatars.githubusercontent.com/u/11860887?v=3","gravatar_id":"","url":"https://api.github.com/users/openzipkin","html_url":"https://github.com/openzipkin","followers_url":"https://api.github.com/users/openzipkin/followers","following_url":"https://api.github.com/users/openzipkin/following{/other_user}","gists_url":"https://api.github.com/users/openzipkin/gists{/gist_id}","starred_url":"https://api.github.com/users/openzipkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openzipkin/subscriptions","organizations_url":"https://api.github.com/users/openzipkin/orgs","repos_url":"https://api.github.com/users/openzipkin/repos","events_url":"https://api.github.com/users/openzipkin/events{/privacy}","received_events_url":"https://api.github.com/users/openzipkin/received_events","type":"Organization","site_admin":false},"repo":{"id":65356302,"name":"zipkin-reporter-java","full_name":"openzipkin/zipkin-reporter-java","owner":{"login":"openzipkin","id":11860887,"avatar_url":"https://avatars.githubusercontent.com/u/11860887?v=3","gravatar_id":"","url":"https://api.github.com/users/openzipkin","html_url":"https://github.com/openzipkin","followers_url":"https://api.github.com/users/openzipkin/followers","following_url":"https://api.github.com/users/openzipkin/following{/other_user}","gists_url":"https://api.github.com/users/openzipkin/gists{/gist_id}","starred_url":"https://api.github.com/users/openzipkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openzipkin/subscriptions","organizations_url":"https://api.github.com/users/openzipkin/orgs","repos_url":"https://api.github.com/users/openzipkin/repos","events_url":"https://api.github.com/users/openzipkin/events{/privacy}","received_events_url":"https://api.github.com/users/openzipkin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openzipkin/zipkin-reporter-java","description":"Shared library for reporting zipkin spans on transports such as http or kafka","fork":false,"url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java","forks_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/forks","keys_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/teams","hooks_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/hooks","issue_events_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/issues/events{/number}","events_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/events","assignees_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/assignees{/user}","branches_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/branches{/branch}","tags_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/tags","blobs_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/statuses/{sha}","languages_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/languages","stargazers_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/stargazers","contributors_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/contributors","subscribers_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/subscribers","subscription_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/subscription","commits_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/contents/{+path}","compare_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/merges","archive_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/downloads","issues_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/issues{/number}","pulls_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls{/number}","milestones_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/milestones{/number}","notifications_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/labels{/name}","releases_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/releases{/id}","deployments_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/deployments","created_at":"2016-08-10T06:26:54Z","updated_at":"2016-08-15T05:41:33Z","pushed_at":"2016-08-23T14:36:26Z","git_url":"git://github.com/openzipkin/zipkin-reporter-java.git","ssh_url":"git@github.com:openzipkin/zipkin-reporter-java.git","clone_url":"https://github.com/openzipkin/zipkin-reporter-java.git","svn_url":"https://github.com/openzipkin/zipkin-reporter-java","homepage":null,"size":128,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"openzipkin:master","ref":"master","sha":"5a477de29a357854a851aa0744fc1ee8d0de7877","user":{"login":"openzipkin","id":11860887,"avatar_url":"https://avatars.githubusercontent.com/u/11860887?v=3","gravatar_id":"","url":"https://api.github.com/users/openzipkin","html_url":"https://github.com/openzipkin","followers_url":"https://api.github.com/users/openzipkin/followers","following_url":"https://api.github.com/users/openzipkin/following{/other_user}","gists_url":"https://api.github.com/users/openzipkin/gists{/gist_id}","starred_url":"https://api.github.com/users/openzipkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openzipkin/subscriptions","organizations_url":"https://api.github.com/users/openzipkin/orgs","repos_url":"https://api.github.com/users/openzipkin/repos","events_url":"https://api.github.com/users/openzipkin/events{/privacy}","received_events_url":"https://api.github.com/users/openzipkin/received_events","type":"Organization","site_admin":false},"repo":{"id":65356302,"name":"zipkin-reporter-java","full_name":"openzipkin/zipkin-reporter-java","owner":{"login":"openzipkin","id":11860887,"avatar_url":"https://avatars.githubusercontent.com/u/11860887?v=3","gravatar_id":"","url":"https://api.github.com/users/openzipkin","html_url":"https://github.com/openzipkin","followers_url":"https://api.github.com/users/openzipkin/followers","following_url":"https://api.github.com/users/openzipkin/following{/other_user}","gists_url":"https://api.github.com/users/openzipkin/gists{/gist_id}","starred_url":"https://api.github.com/users/openzipkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openzipkin/subscriptions","organizations_url":"https://api.github.com/users/openzipkin/orgs","repos_url":"https://api.github.com/users/openzipkin/repos","events_url":"https://api.github.com/users/openzipkin/events{/privacy}","received_events_url":"https://api.github.com/users/openzipkin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openzipkin/zipkin-reporter-java","description":"Shared library for reporting zipkin spans on transports such as http or kafka","fork":false,"url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java","forks_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/forks","keys_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/teams","hooks_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/hooks","issue_events_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/issues/events{/number}","events_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/events","assignees_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/assignees{/user}","branches_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/branches{/branch}","tags_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/tags","blobs_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/statuses/{sha}","languages_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/languages","stargazers_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/stargazers","contributors_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/contributors","subscribers_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/subscribers","subscription_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/subscription","commits_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/contents/{+path}","compare_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/merges","archive_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/downloads","issues_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/issues{/number}","pulls_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls{/number}","milestones_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/milestones{/number}","notifications_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/labels{/name}","releases_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/releases{/id}","deployments_url":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/deployments","created_at":"2016-08-10T06:26:54Z","updated_at":"2016-08-15T05:41:33Z","pushed_at":"2016-08-23T14:36:26Z","git_url":"git://github.com/openzipkin/zipkin-reporter-java.git","ssh_url":"git@github.com:openzipkin/zipkin-reporter-java.git","clone_url":"https://github.com/openzipkin/zipkin-reporter-java.git","svn_url":"https://github.com/openzipkin/zipkin-reporter-java","homepage":null,"size":128,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/7"},"html":{"href":"https://github.com/openzipkin/zipkin-reporter-java/pull/7"},"issue":{"href":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/issues/7"},"comments":{"href":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/openzipkin/zipkin-reporter-java/statuses/a4fd2cf9406f13fe83d31a3fce7603fff0e39fb6"}}}}
{"actor":{"display_login":"felixbarny"}}