{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-beam/pulls/comments/76347981","id":76347981,"diff_hunk":"@@ -0,0 +1,139 @@\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+package org.apache.beam.sdk.util;\n+\n+import static com.google.common.base.Preconditions.checkArgument;\n+\n+import com.google.api.client.util.BackOff;\n+import org.joda.time.Duration;\n+\n+\n+/**\n+ * A {@link BackOff} for which the retry algorithm is customizable.\n+ */\n+public final class FlexibleBackoff implements BackOff {\n+  private static final double DEFAULT_EXPONENT = 1.5;\n+  private static final double DEFAULT_RANDOMIZATION_FACTOR = 0.5;\n+  private static final Duration DEFAULT_MIN_BACKOFF = Duration.standardSeconds(1);\n+  private static final Duration DEFAULT_MAX_BACKOFF = Duration.standardDays(1000);\n+  private static final int DEFAULT_MAX_ATTEMPTS = Integer.MAX_VALUE;\n+  private static final Duration DEFAULT_MAX_CUM_BACKOFF = Duration.standardDays(1000);\n+  // Customization of this backoff.\n+  private final double exponent;\n+  private final Duration initialBackoff;\n+  private final Duration maxBackoff;\n+  private final Duration maxCumulativeBackoff;\n+  private final int maxAttempts;\n+  // Current state\n+  private Duration currentCumulativeBackoff;\n+  private int currentAttempt;\n+\n+  public static FlexibleBackoff of() {\n+    return new FlexibleBackoff(\n+        DEFAULT_EXPONENT,\n+        DEFAULT_MIN_BACKOFF, DEFAULT_MAX_BACKOFF, DEFAULT_MAX_CUM_BACKOFF,\n+        DEFAULT_MAX_ATTEMPTS);\n+  }\n+\n+  public FlexibleBackoff withExponent(double exponent) {\n+    checkArgument(exponent > 0, \"exponent %s must be greater than 0\", exponent);\n+    return new FlexibleBackoff(\n+        exponent, initialBackoff, maxBackoff, maxCumulativeBackoff, maxAttempts);\n+  }\n+\n+  public FlexibleBackoff withInitialBackoff(Duration initialBackoff) {\n+    checkArgument(\n+        initialBackoff.getMillis() > 0,\n+        \"initialBackoff %s must be at least 1 millisecond\",\n+        initialBackoff);\n+    return new FlexibleBackoff(\n+        exponent, initialBackoff, maxBackoff, maxCumulativeBackoff, maxAttempts);\n+  }\n+\n+  public FlexibleBackoff withMaxBackoff(Duration maxBackoff) {\n+    checkArgument(\n+        maxBackoff.getMillis() > 0,\n+        \"maxBackoff %s must be at least 1 millisecond\",\n+        maxBackoff);\n+    return new FlexibleBackoff(\n+        exponent, initialBackoff, maxBackoff, maxCumulativeBackoff, maxAttempts);\n+  }\n+\n+  public FlexibleBackoff withMaxCumulativeBackoff(Duration maxCumulativeBackoff) {\n+    checkArgument(maxCumulativeBackoff.isLongerThan(Duration.ZERO),\n+        \"maxCumulativeBackoff %s must be at least 1 millisecond\", maxCumulativeBackoff);\n+    return new FlexibleBackoff(\n+        exponent, initialBackoff, maxBackoff, maxCumulativeBackoff, maxAttempts);\n+  }\n+\n+  public FlexibleBackoff withMaxAttempts(int maxAttempts) {\n+    checkArgument(maxAttempts >= 1, \"maxAttempts %s must be at least 1\", maxAttempts);\n+    return new FlexibleBackoff(\n+        exponent, initialBackoff, maxBackoff, maxCumulativeBackoff, maxAttempts);\n+  }\n+\n+  @Override\n+  public void reset() {\n+    currentAttempt = 0;\n+    currentCumulativeBackoff = Duration.ZERO;\n+  }\n+\n+  @Override\n+  public long nextBackOffMillis() {\n+    // Maximum number of attempts reached.\n+    if (currentAttempt >= maxAttempts) {\n+      return BackOff.STOP;\n+    }\n+    // Maximum cumulative backoff reached.\n+    if (currentCumulativeBackoff.equals(maxCumulativeBackoff)) {","path":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/FlexibleBackoff.java","position":null,"original_position":103,"commit_id":"0bb7527b08557c3669d3a9cc64f09123cc9e012b","original_commit_id":"1f4cb03bdf1c7623952f720776660f40beeeed9b","user":{"login":"dhalperi","id":526415,"avatar_url":"https://avatars.githubusercontent.com/u/526415?v=3","gravatar_id":"","url":"https://api.github.com/users/dhalperi","html_url":"https://github.com/dhalperi","followers_url":"https://api.github.com/users/dhalperi/followers","following_url":"https://api.github.com/users/dhalperi/following{/other_user}","gists_url":"https://api.github.com/users/dhalperi/gists{/gist_id}","starred_url":"https://api.github.com/users/dhalperi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhalperi/subscriptions","organizations_url":"https://api.github.com/users/dhalperi/orgs","repos_url":"https://api.github.com/users/dhalperi/repos","events_url":"https://api.github.com/users/dhalperi/events{/privacy}","received_events_url":"https://api.github.com/users/dhalperi/received_events","type":"User","site_admin":false},"body":"switched to `.compareTo() >= 0` to mimic `>=` as in the above `if`.","created_at":"2016-08-26T00:20:10Z","updated_at":"2016-08-26T00:20:10Z","html_url":"https://github.com/apache/incubator-beam/pull/888#discussion_r76347981","pull_request_url":"https://api.github.com/repos/apache/incubator-beam/pulls/888","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/comments/76347981"},"html":{"href":"https://github.com/apache/incubator-beam/pull/888#discussion_r76347981"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/888"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-beam/pulls/888","id":82805485,"html_url":"https://github.com/apache/incubator-beam/pull/888","diff_url":"https://github.com/apache/incubator-beam/pull/888.diff","patch_url":"https://github.com/apache/incubator-beam/pull/888.patch","issue_url":"https://api.github.com/repos/apache/incubator-beam/issues/888","number":888,"state":"open","locked":false,"title":"[Draft] Cleaner backoff utilities in Beam","user":{"login":"dhalperi","id":526415,"avatar_url":"https://avatars.githubusercontent.com/u/526415?v=3","gravatar_id":"","url":"https://api.github.com/users/dhalperi","html_url":"https://github.com/dhalperi","followers_url":"https://api.github.com/users/dhalperi/followers","following_url":"https://api.github.com/users/dhalperi/following{/other_user}","gists_url":"https://api.github.com/users/dhalperi/gists{/gist_id}","starred_url":"https://api.github.com/users/dhalperi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhalperi/subscriptions","organizations_url":"https://api.github.com/users/dhalperi/orgs","repos_url":"https://api.github.com/users/dhalperi/repos","events_url":"https://api.github.com/users/dhalperi/events{/privacy}","received_events_url":"https://api.github.com/users/dhalperi/received_events","type":"User","site_admin":false},"body":"We have 3 different backoff classes, which don't really have that much different functionality. Add a single, flexible backoff implementation that can be used to replace all three classes. Additionally, this new backoff actually supports more functionality than any of the other three did -- you can limit retries, cap the exponential growth of an individual backoff, and cap the cumulative time spent in backoff; prior implementations did not allow all 3.\r\n\r\nThis also makes the parameters self-obvious (`Duration`, not number-that-is-also-millis) where appropriate.\r\n\r\nThis initial PR should have no functional changes.\r\n\r\nTODO:\r\n- [ ] javadoc on FlexibleBackof\r\n- [ ] is there a better name than \"FlexibleBackoff\"\r\n\r\n?","created_at":"2016-08-25T22:38:36Z","updated_at":"2016-08-26T00:20:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f46e372abea0e724777b2801dce0837c73d76da","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-beam/pulls/888/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-beam/pulls/888/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/888/comments","statuses_url":"https://api.github.com/repos/apache/incubator-beam/statuses/0bb7527b08557c3669d3a9cc64f09123cc9e012b","head":{"label":"dhalperi:cleaner-backoff","ref":"cleaner-backoff","sha":"0bb7527b08557c3669d3a9cc64f09123cc9e012b","user":{"login":"dhalperi","id":526415,"avatar_url":"https://avatars.githubusercontent.com/u/526415?v=3","gravatar_id":"","url":"https://api.github.com/users/dhalperi","html_url":"https://github.com/dhalperi","followers_url":"https://api.github.com/users/dhalperi/followers","following_url":"https://api.github.com/users/dhalperi/following{/other_user}","gists_url":"https://api.github.com/users/dhalperi/gists{/gist_id}","starred_url":"https://api.github.com/users/dhalperi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhalperi/subscriptions","organizations_url":"https://api.github.com/users/dhalperi/orgs","repos_url":"https://api.github.com/users/dhalperi/repos","events_url":"https://api.github.com/users/dhalperi/events{/privacy}","received_events_url":"https://api.github.com/users/dhalperi/received_events","type":"User","site_admin":false},"repo":{"id":53068408,"name":"incubator-beam","full_name":"dhalperi/incubator-beam","owner":{"login":"dhalperi","id":526415,"avatar_url":"https://avatars.githubusercontent.com/u/526415?v=3","gravatar_id":"","url":"https://api.github.com/users/dhalperi","html_url":"https://github.com/dhalperi","followers_url":"https://api.github.com/users/dhalperi/followers","following_url":"https://api.github.com/users/dhalperi/following{/other_user}","gists_url":"https://api.github.com/users/dhalperi/gists{/gist_id}","starred_url":"https://api.github.com/users/dhalperi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhalperi/subscriptions","organizations_url":"https://api.github.com/users/dhalperi/orgs","repos_url":"https://api.github.com/users/dhalperi/repos","events_url":"https://api.github.com/users/dhalperi/events{/privacy}","received_events_url":"https://api.github.com/users/dhalperi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dhalperi/incubator-beam","description":"Mirror of Apache Beam (Incubating)","fork":true,"url":"https://api.github.com/repos/dhalperi/incubator-beam","forks_url":"https://api.github.com/repos/dhalperi/incubator-beam/forks","keys_url":"https://api.github.com/repos/dhalperi/incubator-beam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dhalperi/incubator-beam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dhalperi/incubator-beam/teams","hooks_url":"https://api.github.com/repos/dhalperi/incubator-beam/hooks","issue_events_url":"https://api.github.com/repos/dhalperi/incubator-beam/issues/events{/number}","events_url":"https://api.github.com/repos/dhalperi/incubator-beam/events","assignees_url":"https://api.github.com/repos/dhalperi/incubator-beam/assignees{/user}","branches_url":"https://api.github.com/repos/dhalperi/incubator-beam/branches{/branch}","tags_url":"https://api.github.com/repos/dhalperi/incubator-beam/tags","blobs_url":"https://api.github.com/repos/dhalperi/incubator-beam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dhalperi/incubator-beam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dhalperi/incubator-beam/git/refs{/sha}","trees_url":"https://api.github.com/repos/dhalperi/incubator-beam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dhalperi/incubator-beam/statuses/{sha}","languages_url":"https://api.github.com/repos/dhalperi/incubator-beam/languages","stargazers_url":"https://api.github.com/repos/dhalperi/incubator-beam/stargazers","contributors_url":"https://api.github.com/repos/dhalperi/incubator-beam/contributors","subscribers_url":"https://api.github.com/repos/dhalperi/incubator-beam/subscribers","subscription_url":"https://api.github.com/repos/dhalperi/incubator-beam/subscription","commits_url":"https://api.github.com/repos/dhalperi/incubator-beam/commits{/sha}","git_commits_url":"https://api.github.com/repos/dhalperi/incubator-beam/git/commits{/sha}","comments_url":"https://api.github.com/repos/dhalperi/incubator-beam/comments{/number}","issue_comment_url":"https://api.github.com/repos/dhalperi/incubator-beam/issues/comments{/number}","contents_url":"https://api.github.com/repos/dhalperi/incubator-beam/contents/{+path}","compare_url":"https://api.github.com/repos/dhalperi/incubator-beam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dhalperi/incubator-beam/merges","archive_url":"https://api.github.com/repos/dhalperi/incubator-beam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dhalperi/incubator-beam/downloads","issues_url":"https://api.github.com/repos/dhalperi/incubator-beam/issues{/number}","pulls_url":"https://api.github.com/repos/dhalperi/incubator-beam/pulls{/number}","milestones_url":"https://api.github.com/repos/dhalperi/incubator-beam/milestones{/number}","notifications_url":"https://api.github.com/repos/dhalperi/incubator-beam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dhalperi/incubator-beam/labels{/name}","releases_url":"https://api.github.com/repos/dhalperi/incubator-beam/releases{/id}","deployments_url":"https://api.github.com/repos/dhalperi/incubator-beam/deployments","created_at":"2016-03-03T17:11:03Z","updated_at":"2016-03-03T17:11:05Z","pushed_at":"2016-08-26T00:19:45Z","git_url":"git://github.com/dhalperi/incubator-beam.git","ssh_url":"git@github.com:dhalperi/incubator-beam.git","clone_url":"https://github.com/dhalperi/incubator-beam.git","svn_url":"https://github.com/dhalperi/incubator-beam","homepage":null,"size":17269,"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":"9c9f4c9c96e45a6dc60af62a01aec10a0433f5f2","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-08-25T19:04:21Z","pushed_at":"2016-08-26T00:19:45Z","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":27314,"stargazers_count":318,"watchers_count":318,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":198,"mirror_url":"git://git.apache.org/incubator-beam.git","open_issues_count":50,"forks":198,"open_issues":50,"watchers":318,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/888"},"html":{"href":"https://github.com/apache/incubator-beam/pull/888"},"issue":{"href":"https://api.github.com/repos/apache/incubator-beam/issues/888"},"comments":{"href":"https://api.github.com/repos/apache/incubator-beam/issues/888/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/888/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/888/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-beam/statuses/0bb7527b08557c3669d3a9cc64f09123cc9e012b"}}}}
{"actor":{"display_login":"dhalperi"}}