{"action":"created","comment":{"url":"https://api.github.com/repos/twitter/heron/pulls/comments/90946616","pull_request_review_id":11460256,"id":90946616,"diff_hunk":"@@ -0,0 +1,247 @@\n+// Copyright 2016 Twitter. All rights reserved.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// 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+package com.twitter.heron.common.basics;\n+\n+/**\n+ * Class that encapsulates number of bytes, with helpers to handle units properly.\n+ */\n+public final class ByteAmount implements Comparable<ByteAmount> {\n+  private static final long MB = 1024L * 1024;\n+  private static final long GB = MB * 1024;\n+  private static final long MAX_MB = Math.round(Long.MAX_VALUE / MB);\n+  private static final long MAX_GB = Math.round(Long.MAX_VALUE / GB);\n+\n+  public static final ByteAmount ZERO = ByteAmount.fromBytes(0);\n+  private final long bytes;\n+\n+  private ByteAmount(long bytes) {\n+    this.bytes = bytes;\n+  }\n+\n+  /**\n+   * Creates a ByteAmount value in bytes.\n+   *\n+   * @param bytes value in bytes to represent\n+   * @return a ByteAmount object repressing the number of bytes passed\n+   */\n+  public static ByteAmount fromBytes(long bytes) {\n+    return new ByteAmount(bytes);\n+  }\n+\n+  /**\n+   * Creates a ByteAmount value in megabytes. If the megabytes value\n+   * is >= Long.MAX_VALUE / 1024 / 1024, the byte representation is capped at Long.MAX_VALUE.\n+   *\n+   * @param megabytes value in megabytes to represent\n+   * @return a ByteAmount object repressing the number of MBs passed\n+   */\n+  public static ByteAmount fromMegabytes(long megabytes) {\n+    if (megabytes >= MAX_MB) {\n+      return new ByteAmount(Long.MAX_VALUE);\n+    } else {\n+      return new ByteAmount(megabytes * MB);\n+    }\n+  }\n+\n+  /**\n+   * Creates a ByteAmount value in gigabytes. If the gigabytes value\n+   * is >= Long.MAX_VALUE / 1024 / 1024 / 1024, the byte representation is capped at Long.MAX_VALUE.\n+   *\n+   * @param gigabytes value in gigabytes to represent\n+   * @return a ByteAmount object repressing the number of GBs passed\n+   */\n+  public static ByteAmount fromGigabytes(long gigabytes) {\n+    if (gigabytes >= MAX_GB) {\n+      return new ByteAmount(Long.MAX_VALUE);\n+    } else {\n+      return new ByteAmount(gigabytes * GB);\n+    }\n+  }\n+\n+  /**\n+   * Returns the number of bytes associated with the ByteValue.\n+   * @return number of bytes\n+   */\n+  public long asBytes() {\n+    return bytes;\n+  }\n+\n+  /**\n+   * Converts the number of bytes to megabytes, rounding if there is a remainder. Because of loss\n+   * of precision due to rounding, it's strongly advised to only use this method when it is certain\n+   * that megabytes were using during the construction of the object via fromMegabytes. Only In that\n+   * scenario is there a guarantee that precision will not be lost when calling this method.\n+   * @return returns the ByteValue in MBs or 0 if the value is < (1024 * 1024) / 2\n+   */\n+  public long asMegabytes() {\n+    return Math.round((double) bytes / MB);\n+  }\n+\n+  /**\n+   * Converts the number of bytes to gigabytes, rounding if there is a remainder. Because of loss\n+   * of precision due to rounding, it's strongly advised to only use this method when it is certain\n+   * that gigabytes were using during the construction of the object via fromGigabytes. Only In that\n+   * scenario is there a guarantee that precision will not be lost when calling this method.\n+   * @return returns the ByteValue in GBs or 0 if the value is < (1024 * 1024 * 1024) / 2\n+   */\n+  public long asGigabytes() {\n+    return Math.round((double) bytes / GB);","path":"heron/common/src/java/com/twitter/heron/common/basics/ByteAmount.java","position":null,"original_position":99,"commit_id":"72c484f02f6c439b19856f176fad0a7d40b62986","original_commit_id":"14f79c713562f632bd215e8de63586f52c33de54","user":{"login":"billonahill","id":23758,"avatar_url":"https://avatars.githubusercontent.com/u/23758?v=3","gravatar_id":"","url":"https://api.github.com/users/billonahill","html_url":"https://github.com/billonahill","followers_url":"https://api.github.com/users/billonahill/followers","following_url":"https://api.github.com/users/billonahill/following{/other_user}","gists_url":"https://api.github.com/users/billonahill/gists{/gist_id}","starred_url":"https://api.github.com/users/billonahill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billonahill/subscriptions","organizations_url":"https://api.github.com/users/billonahill/orgs","repos_url":"https://api.github.com/users/billonahill/repos","events_url":"https://api.github.com/users/billonahill/events{/privacy}","received_events_url":"https://api.github.com/users/billonahill/received_events","type":"User","site_admin":false},"body":"Another thought is we could add an enum to the signature where the caller specifies how the rounding should occur: ceil, floor, round, or strict where we fail if there is a remainder. That way the caller has to acknowledge the potential for rounding and decide how rounding should be handled.","created_at":"2016-12-05T20:17:39Z","updated_at":"2016-12-05T20:17:39Z","html_url":"https://github.com/twitter/heron/pull/1586#discussion_r90946616","pull_request_url":"https://api.github.com/repos/twitter/heron/pulls/1586","_links":{"self":{"href":"https://api.github.com/repos/twitter/heron/pulls/comments/90946616"},"html":{"href":"https://github.com/twitter/heron/pull/1586#discussion_r90946616"},"pull_request":{"href":"https://api.github.com/repos/twitter/heron/pulls/1586"}}},"pull_request":{"url":"https://api.github.com/repos/twitter/heron/pulls/1586","id":95599207,"html_url":"https://github.com/twitter/heron/pull/1586","diff_url":"https://github.com/twitter/heron/pull/1586.diff","patch_url":"https://github.com/twitter/heron/pull/1586.patch","issue_url":"https://api.github.com/repos/twitter/heron/issues/1586","number":1586,"state":"open","locked":false,"title":"Adding new BytesAmount class for use by Resource","user":{"login":"billonahill","id":23758,"avatar_url":"https://avatars.githubusercontent.com/u/23758?v=3","gravatar_id":"","url":"https://api.github.com/users/billonahill","html_url":"https://github.com/billonahill","followers_url":"https://api.github.com/users/billonahill/followers","following_url":"https://api.github.com/users/billonahill/following{/other_user}","gists_url":"https://api.github.com/users/billonahill/gists{/gist_id}","starred_url":"https://api.github.com/users/billonahill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billonahill/subscriptions","organizations_url":"https://api.github.com/users/billonahill/orgs","repos_url":"https://api.github.com/users/billonahill/repos","events_url":"https://api.github.com/users/billonahill/events{/privacy}","received_events_url":"https://api.github.com/users/billonahill/received_events","type":"User","site_admin":false},"body":"Fixes #1576\r\n\r\nThe key classes to review are:\r\n```\r\nheron/common/src/java/com/twitter/heron/common/basics/ByteAmount.java\r\nheron/common/tests/java/com/twitter/heron/common/basics/ByteAmountTest.java\r\nheron/spi/src/java/com/twitter/heron/spi/packing/Resource.java\r\n```\r\nThe rest are the downstream refactors to replace `longs` with `ByteAmounts`. Also I removed the `Constants` class since it's no longer needed, since `MB` and `GB` are no longer used.\r\n\r\nPlease review and provide feedback on the design, naming, etc of the proposed `BytesAmount` class. \r\n\r\nPassing a long for bytes results in a lot of unit conversion math and is subject to hard to track bugs. If instead we create a class to represent bytes and their units, heron code will be more robust and byte math can be simplified into methods on the object.\r\n","created_at":"2016-11-28T23:43:59Z","updated_at":"2016-12-05T20:17:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f3eb31c2757989ee78dd8a0e65dd654a1766ec46","assignee":{"login":"billonahill","id":23758,"avatar_url":"https://avatars.githubusercontent.com/u/23758?v=3","gravatar_id":"","url":"https://api.github.com/users/billonahill","html_url":"https://github.com/billonahill","followers_url":"https://api.github.com/users/billonahill/followers","following_url":"https://api.github.com/users/billonahill/following{/other_user}","gists_url":"https://api.github.com/users/billonahill/gists{/gist_id}","starred_url":"https://api.github.com/users/billonahill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billonahill/subscriptions","organizations_url":"https://api.github.com/users/billonahill/orgs","repos_url":"https://api.github.com/users/billonahill/repos","events_url":"https://api.github.com/users/billonahill/events{/privacy}","received_events_url":"https://api.github.com/users/billonahill/received_events","type":"User","site_admin":false},"assignees":[{"login":"billonahill","id":23758,"avatar_url":"https://avatars.githubusercontent.com/u/23758?v=3","gravatar_id":"","url":"https://api.github.com/users/billonahill","html_url":"https://github.com/billonahill","followers_url":"https://api.github.com/users/billonahill/followers","following_url":"https://api.github.com/users/billonahill/following{/other_user}","gists_url":"https://api.github.com/users/billonahill/gists{/gist_id}","starred_url":"https://api.github.com/users/billonahill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billonahill/subscriptions","organizations_url":"https://api.github.com/users/billonahill/orgs","repos_url":"https://api.github.com/users/billonahill/repos","events_url":"https://api.github.com/users/billonahill/events{/privacy}","received_events_url":"https://api.github.com/users/billonahill/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/twitter/heron/milestones/11","html_url":"https://github.com/twitter/heron/milestones/0.14.6","labels_url":"https://api.github.com/repos/twitter/heron/milestones/11/labels","id":2152654,"number":11,"title":"0.14.6","description":"mempool usage problem","creator":{"login":"objmagic","id":3656079,"avatar_url":"https://avatars.githubusercontent.com/u/3656079?v=3","gravatar_id":"","url":"https://api.github.com/users/objmagic","html_url":"https://github.com/objmagic","followers_url":"https://api.github.com/users/objmagic/followers","following_url":"https://api.github.com/users/objmagic/following{/other_user}","gists_url":"https://api.github.com/users/objmagic/gists{/gist_id}","starred_url":"https://api.github.com/users/objmagic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/objmagic/subscriptions","organizations_url":"https://api.github.com/users/objmagic/orgs","repos_url":"https://api.github.com/users/objmagic/repos","events_url":"https://api.github.com/users/objmagic/events{/privacy}","received_events_url":"https://api.github.com/users/objmagic/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":7,"state":"open","created_at":"2016-11-22T22:59:35Z","updated_at":"2016-12-05T19:40:52Z","due_on":"2016-11-28T00:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/twitter/heron/pulls/1586/commits","review_comments_url":"https://api.github.com/repos/twitter/heron/pulls/1586/comments","review_comment_url":"https://api.github.com/repos/twitter/heron/pulls/comments{/number}","comments_url":"https://api.github.com/repos/twitter/heron/issues/1586/comments","statuses_url":"https://api.github.com/repos/twitter/heron/statuses/72c484f02f6c439b19856f176fad0a7d40b62986","head":{"label":"billonahill:billg/bytes_amount_class","ref":"billg/bytes_amount_class","sha":"72c484f02f6c439b19856f176fad0a7d40b62986","user":{"login":"billonahill","id":23758,"avatar_url":"https://avatars.githubusercontent.com/u/23758?v=3","gravatar_id":"","url":"https://api.github.com/users/billonahill","html_url":"https://github.com/billonahill","followers_url":"https://api.github.com/users/billonahill/followers","following_url":"https://api.github.com/users/billonahill/following{/other_user}","gists_url":"https://api.github.com/users/billonahill/gists{/gist_id}","starred_url":"https://api.github.com/users/billonahill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billonahill/subscriptions","organizations_url":"https://api.github.com/users/billonahill/orgs","repos_url":"https://api.github.com/users/billonahill/repos","events_url":"https://api.github.com/users/billonahill/events{/privacy}","received_events_url":"https://api.github.com/users/billonahill/received_events","type":"User","site_admin":false},"repo":{"id":59679434,"name":"heron","full_name":"billonahill/heron","owner":{"login":"billonahill","id":23758,"avatar_url":"https://avatars.githubusercontent.com/u/23758?v=3","gravatar_id":"","url":"https://api.github.com/users/billonahill","html_url":"https://github.com/billonahill","followers_url":"https://api.github.com/users/billonahill/followers","following_url":"https://api.github.com/users/billonahill/following{/other_user}","gists_url":"https://api.github.com/users/billonahill/gists{/gist_id}","starred_url":"https://api.github.com/users/billonahill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billonahill/subscriptions","organizations_url":"https://api.github.com/users/billonahill/orgs","repos_url":"https://api.github.com/users/billonahill/repos","events_url":"https://api.github.com/users/billonahill/events{/privacy}","received_events_url":"https://api.github.com/users/billonahill/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/billonahill/heron","description":"Heron is a realtime, distributed, fault-tolerant stream processing engine from Twitter","fork":true,"url":"https://api.github.com/repos/billonahill/heron","forks_url":"https://api.github.com/repos/billonahill/heron/forks","keys_url":"https://api.github.com/repos/billonahill/heron/keys{/key_id}","collaborators_url":"https://api.github.com/repos/billonahill/heron/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/billonahill/heron/teams","hooks_url":"https://api.github.com/repos/billonahill/heron/hooks","issue_events_url":"https://api.github.com/repos/billonahill/heron/issues/events{/number}","events_url":"https://api.github.com/repos/billonahill/heron/events","assignees_url":"https://api.github.com/repos/billonahill/heron/assignees{/user}","branches_url":"https://api.github.com/repos/billonahill/heron/branches{/branch}","tags_url":"https://api.github.com/repos/billonahill/heron/tags","blobs_url":"https://api.github.com/repos/billonahill/heron/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/billonahill/heron/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/billonahill/heron/git/refs{/sha}","trees_url":"https://api.github.com/repos/billonahill/heron/git/trees{/sha}","statuses_url":"https://api.github.com/repos/billonahill/heron/statuses/{sha}","languages_url":"https://api.github.com/repos/billonahill/heron/languages","stargazers_url":"https://api.github.com/repos/billonahill/heron/stargazers","contributors_url":"https://api.github.com/repos/billonahill/heron/contributors","subscribers_url":"https://api.github.com/repos/billonahill/heron/subscribers","subscription_url":"https://api.github.com/repos/billonahill/heron/subscription","commits_url":"https://api.github.com/repos/billonahill/heron/commits{/sha}","git_commits_url":"https://api.github.com/repos/billonahill/heron/git/commits{/sha}","comments_url":"https://api.github.com/repos/billonahill/heron/comments{/number}","issue_comment_url":"https://api.github.com/repos/billonahill/heron/issues/comments{/number}","contents_url":"https://api.github.com/repos/billonahill/heron/contents/{+path}","compare_url":"https://api.github.com/repos/billonahill/heron/compare/{base}...{head}","merges_url":"https://api.github.com/repos/billonahill/heron/merges","archive_url":"https://api.github.com/repos/billonahill/heron/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/billonahill/heron/downloads","issues_url":"https://api.github.com/repos/billonahill/heron/issues{/number}","pulls_url":"https://api.github.com/repos/billonahill/heron/pulls{/number}","milestones_url":"https://api.github.com/repos/billonahill/heron/milestones{/number}","notifications_url":"https://api.github.com/repos/billonahill/heron/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/billonahill/heron/labels{/name}","releases_url":"https://api.github.com/repos/billonahill/heron/releases{/id}","deployments_url":"https://api.github.com/repos/billonahill/heron/deployments","created_at":"2016-05-25T16:27:20Z","updated_at":"2016-10-26T17:22:23Z","pushed_at":"2016-12-05T20:10:19Z","git_url":"git://github.com/billonahill/heron.git","ssh_url":"git@github.com:billonahill/heron.git","clone_url":"https://github.com/billonahill/heron.git","svn_url":"https://github.com/billonahill/heron","homepage":"http://heronstreaming.io","size":114136,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"twitter:master","ref":"master","sha":"b37c8235e3d6ac764745b109cb17b231d71082b5","user":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=3","gravatar_id":"","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"repo":{"id":43158694,"name":"heron","full_name":"twitter/heron","owner":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=3","gravatar_id":"","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/twitter/heron","description":"Heron is a realtime, distributed, fault-tolerant stream processing engine from Twitter","fork":false,"url":"https://api.github.com/repos/twitter/heron","forks_url":"https://api.github.com/repos/twitter/heron/forks","keys_url":"https://api.github.com/repos/twitter/heron/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twitter/heron/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twitter/heron/teams","hooks_url":"https://api.github.com/repos/twitter/heron/hooks","issue_events_url":"https://api.github.com/repos/twitter/heron/issues/events{/number}","events_url":"https://api.github.com/repos/twitter/heron/events","assignees_url":"https://api.github.com/repos/twitter/heron/assignees{/user}","branches_url":"https://api.github.com/repos/twitter/heron/branches{/branch}","tags_url":"https://api.github.com/repos/twitter/heron/tags","blobs_url":"https://api.github.com/repos/twitter/heron/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twitter/heron/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twitter/heron/git/refs{/sha}","trees_url":"https://api.github.com/repos/twitter/heron/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twitter/heron/statuses/{sha}","languages_url":"https://api.github.com/repos/twitter/heron/languages","stargazers_url":"https://api.github.com/repos/twitter/heron/stargazers","contributors_url":"https://api.github.com/repos/twitter/heron/contributors","subscribers_url":"https://api.github.com/repos/twitter/heron/subscribers","subscription_url":"https://api.github.com/repos/twitter/heron/subscription","commits_url":"https://api.github.com/repos/twitter/heron/commits{/sha}","git_commits_url":"https://api.github.com/repos/twitter/heron/git/commits{/sha}","comments_url":"https://api.github.com/repos/twitter/heron/comments{/number}","issue_comment_url":"https://api.github.com/repos/twitter/heron/issues/comments{/number}","contents_url":"https://api.github.com/repos/twitter/heron/contents/{+path}","compare_url":"https://api.github.com/repos/twitter/heron/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twitter/heron/merges","archive_url":"https://api.github.com/repos/twitter/heron/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twitter/heron/downloads","issues_url":"https://api.github.com/repos/twitter/heron/issues{/number}","pulls_url":"https://api.github.com/repos/twitter/heron/pulls{/number}","milestones_url":"https://api.github.com/repos/twitter/heron/milestones{/number}","notifications_url":"https://api.github.com/repos/twitter/heron/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twitter/heron/labels{/name}","releases_url":"https://api.github.com/repos/twitter/heron/releases{/id}","deployments_url":"https://api.github.com/repos/twitter/heron/deployments","created_at":"2015-09-25T16:09:24Z","updated_at":"2016-12-05T18:38:36Z","pushed_at":"2016-12-05T20:10:20Z","git_url":"git://github.com/twitter/heron.git","ssh_url":"git@github.com:twitter/heron.git","clone_url":"https://github.com/twitter/heron.git","svn_url":"https://github.com/twitter/heron","homepage":"http://heronstreaming.io","size":153390,"stargazers_count":2528,"watchers_count":2528,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":433,"mirror_url":null,"open_issues_count":214,"forks":433,"open_issues":214,"watchers":2528,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/twitter/heron/pulls/1586"},"html":{"href":"https://github.com/twitter/heron/pull/1586"},"issue":{"href":"https://api.github.com/repos/twitter/heron/issues/1586"},"comments":{"href":"https://api.github.com/repos/twitter/heron/issues/1586/comments"},"review_comments":{"href":"https://api.github.com/repos/twitter/heron/pulls/1586/comments"},"review_comment":{"href":"https://api.github.com/repos/twitter/heron/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/twitter/heron/pulls/1586/commits"},"statuses":{"href":"https://api.github.com/repos/twitter/heron/statuses/72c484f02f6c439b19856f176fad0a7d40b62986"}}}}
{"actor":{"display_login":"billonahill"}}