{"action":"created","comment":{"url":"https://api.github.com/repos/codice/ddf/pulls/comments/87459014","pull_request_review_id":8071739,"id":87459014,"diff_hunk":"@@ -0,0 +1,93 @@\n+/**\n+ * Copyright (c) Codice Foundation\n+ * <p/>\n+ * This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser\n+ * General Public License as published by the Free Software Foundation, either version 3 of the\n+ * License, or any later version.\n+ * <p/>\n+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\n+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details. A copy of the GNU Lesser General Public License\n+ * is distributed along with this program and can be found at\n+ * <http://www.gnu.org/licenses/lgpl.html>.\n+ */\n+package org.codice.ddf.platform.util;\n+\n+import java.util.function.Consumer;\n+\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+/**\n+ * The OperationRunner will execute an {@link Operation} and re-execute it if an exception is\n+ * thrown. This class only has static methods; the class cannot be instantiated.\n+ */\n+public class OperationRunner {\n+\n+    private static final Logger LOGGER = LoggerFactory.getLogger(OperationRunner.class);\n+\n+    private static final long SLEEP_FACTOR = 2;\n+\n+    private OperationRunner() {\n+        // prevent instances\n+    }\n+\n+    /**\n+     * This method will execute an {@link Operation} and retry if it throws an exception. If an\n+     * exception is thrown and retry attempts are still remaining, then {@code exceptionHandler}\n+     * will be called and the method will sleep. The sleep duration is doubled after each retry\n+     * attempt and is limited to {@code maxSleep}. If there are no retry attempts remaining, then\n+     * the exception will be rethrown.\n+     * <p>\n+     * The caller should be careful when selecting values for {@code maxAttempts},\n+     * {@code initialSleep} and {@code maxSleep} because this method could theoretically\n+     * run forever.\n+     *\n+     * @param maxAttempts      the maximum retry attempts\n+     * @param initialSleep     the number of milliseconds to sleep after the first failed attempt, limited to maxSleep\n+     * @param maxSleep         the maximum number of milliseconds to sleep after any failed attempt\n+     * @param operation        the operation to be executed\n+     * @param exceptionHandler handle exceptions between retry attempts\n+     * @throws Exception the final exception thrown by the operation\n+     */\n+    public static void runWithRetry(int maxAttempts, long initialSleep, long maxSleep,\n+            Operation operation, Consumer<Exception> exceptionHandler) throws Exception {\n+\n+        int attempt = 1;\n+        long sleep = Math.min(initialSleep, maxSleep);\n+\n+        while (true) {\n+            try {\n+                operation.run();\n+                return;\n+            } catch (Exception e) {\n+                if (attempt < maxAttempts) {\n+                    exceptionHandler.accept(e);\n+                    attempt++;\n+                    if (sleep(sleep)) {\n+                        return;\n+                    }\n+                    sleep = increaseSleep(maxSleep, sleep);\n+                } else {\n+                    throw e;\n+                }\n+            }\n+        }\n+    }\n+\n+    private static boolean sleep(long sleep) {","path":"platform/util/platform-util/src/main/java/org/codice/ddf/platform/util/OperationRunner.java","position":78,"original_position":78,"commit_id":"31a10a94b20574788509bc4655d102df474126a3","original_commit_id":"31a10a94b20574788509bc4655d102df474126a3","user":{"login":"coyotesqrl","id":1469860,"avatar_url":"https://avatars.githubusercontent.com/u/1469860?v=3","gravatar_id":"","url":"https://api.github.com/users/coyotesqrl","html_url":"https://github.com/coyotesqrl","followers_url":"https://api.github.com/users/coyotesqrl/followers","following_url":"https://api.github.com/users/coyotesqrl/following{/other_user}","gists_url":"https://api.github.com/users/coyotesqrl/gists{/gist_id}","starred_url":"https://api.github.com/users/coyotesqrl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coyotesqrl/subscriptions","organizations_url":"https://api.github.com/users/coyotesqrl/orgs","repos_url":"https://api.github.com/users/coyotesqrl/repos","events_url":"https://api.github.com/users/coyotesqrl/events{/privacy}","received_events_url":"https://api.github.com/users/coyotesqrl/received_events","type":"User","site_admin":false},"body":"Instead of using low-level functionality like this, why aren't you using a `ScheduledExecutorService` to handle your retry attempts?","created_at":"2016-11-10T18:44:48Z","updated_at":"2016-11-10T18:44:48Z","html_url":"https://github.com/codice/ddf/pull/1416#discussion_r87459014","pull_request_url":"https://api.github.com/repos/codice/ddf/pulls/1416","_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments/87459014"},"html":{"href":"https://github.com/codice/ddf/pull/1416#discussion_r87459014"},"pull_request":{"href":"https://api.github.com/repos/codice/ddf/pulls/1416"}}},"pull_request":{"url":"https://api.github.com/repos/codice/ddf/pulls/1416","id":93202966,"html_url":"https://github.com/codice/ddf/pull/1416","diff_url":"https://github.com/codice/ddf/pull/1416.diff","patch_url":"https://github.com/codice/ddf/pull/1416.patch","issue_url":"https://api.github.com/repos/codice/ddf/issues/1416","number":1416,"state":"open","locked":false,"title":"DDF-2588 Create a retry utility and update TFBOS to use it","user":{"login":"glenhein","id":17837152,"avatar_url":"https://avatars.githubusercontent.com/u/17837152?v=3","gravatar_id":"","url":"https://api.github.com/users/glenhein","html_url":"https://github.com/glenhein","followers_url":"https://api.github.com/users/glenhein/followers","following_url":"https://api.github.com/users/glenhein/following{/other_user}","gists_url":"https://api.github.com/users/glenhein/gists{/gist_id}","starred_url":"https://api.github.com/users/glenhein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glenhein/subscriptions","organizations_url":"https://api.github.com/users/glenhein/orgs","repos_url":"https://api.github.com/users/glenhein/repos","events_url":"https://api.github.com/users/glenhein/events{/privacy}","received_events_url":"https://api.github.com/users/glenhein/received_events","type":"User","site_admin":false},"body":"#### What does this PR do?\r\n\r\n* Create an retry utility that will re-execute an operation if that operation throws an exception\r\n* Update TemporaryFileBackedOutputStream to use the retry utility when resetting the underlying FileBackedOutputStream (google).\r\n\r\n#### Who is reviewing it (please choose AT LEAST two reviewers that need to approve the PR before it can get merged)?\r\n\r\n@bdeining \r\n@rzwiefel \r\n\r\n#### Select at least one member from relevant component team(s) from below (at least one component team member needs to approve the PR).\r\n[IO](https://github.com/orgs/codice/teams/IO)\r\n@coyotesqrl \r\n\r\n[Core APIs](https://github.com/orgs/codice/teams/core-apis)\r\n@dcruver \r\n\r\n#### Choose 2 committers to review/merge the PR (please choose ONLY two committers from below, delete the rest).\r\n@lessarderic\r\n@stustison\r\n#### How should this be tested? (List steps with links to updated documentation)\r\n\r\nTo directly test the retry code, run the unit tests in org.codice.ddf.platform.util.OperationRunnerTest.\r\n\r\nTo directly test TFBOS (and thus indirectly test the retry code), exercise any part of the system that uses TFBOS. For example, anything that calls InputTransformerProducer#generateMetacard.\r\n\r\n#### Any background context you want to provide?\r\n\r\nIt was discovered that in a windows vm, the TFBOS was unable to delete its temporary file, even though no other code should be locking/using the file. Adding a simple retry mechanism gave the  windows os time release the lock. \r\n\r\n#### What are the relevant tickets?\r\n[DFF-2588](https://codice.atlassian.net/browse/DDF-2588)\r\n#### Screenshots (if appropriate)\r\n#### Checklist:\r\n- [ ] Documentation Updated\r\n- [ ] Change Log Updated\r\n- [X] Update / Add Unit Tests\r\n- [ ] Update / Add Integration Tests\r\n\r\n","created_at":"2016-11-10T18:16:25Z","updated_at":"2016-11-10T18:47:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"83bbd876e11d541ff2885c6ca77f421657dac119","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/codice/ddf/pulls/1416/commits","review_comments_url":"https://api.github.com/repos/codice/ddf/pulls/1416/comments","review_comment_url":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codice/ddf/issues/1416/comments","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/31a10a94b20574788509bc4655d102df474126a3","head":{"label":"glenhein:DDF-2588","ref":"DDF-2588","sha":"31a10a94b20574788509bc4655d102df474126a3","user":{"login":"glenhein","id":17837152,"avatar_url":"https://avatars.githubusercontent.com/u/17837152?v=3","gravatar_id":"","url":"https://api.github.com/users/glenhein","html_url":"https://github.com/glenhein","followers_url":"https://api.github.com/users/glenhein/followers","following_url":"https://api.github.com/users/glenhein/following{/other_user}","gists_url":"https://api.github.com/users/glenhein/gists{/gist_id}","starred_url":"https://api.github.com/users/glenhein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glenhein/subscriptions","organizations_url":"https://api.github.com/users/glenhein/orgs","repos_url":"https://api.github.com/users/glenhein/repos","events_url":"https://api.github.com/users/glenhein/events{/privacy}","received_events_url":"https://api.github.com/users/glenhein/received_events","type":"User","site_admin":false},"repo":{"id":54487089,"name":"ddf","full_name":"glenhein/ddf","owner":{"login":"glenhein","id":17837152,"avatar_url":"https://avatars.githubusercontent.com/u/17837152?v=3","gravatar_id":"","url":"https://api.github.com/users/glenhein","html_url":"https://github.com/glenhein","followers_url":"https://api.github.com/users/glenhein/followers","following_url":"https://api.github.com/users/glenhein/following{/other_user}","gists_url":"https://api.github.com/users/glenhein/gists{/gist_id}","starred_url":"https://api.github.com/users/glenhein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glenhein/subscriptions","organizations_url":"https://api.github.com/users/glenhein/orgs","repos_url":"https://api.github.com/users/glenhein/repos","events_url":"https://api.github.com/users/glenhein/events{/privacy}","received_events_url":"https://api.github.com/users/glenhein/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/glenhein/ddf","description":"The Distributed Data Framework - Federated Open Geospatial Consortium (OGC) filter powered metadata catalog with SAML Web SSO secured container","fork":true,"url":"https://api.github.com/repos/glenhein/ddf","forks_url":"https://api.github.com/repos/glenhein/ddf/forks","keys_url":"https://api.github.com/repos/glenhein/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/glenhein/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/glenhein/ddf/teams","hooks_url":"https://api.github.com/repos/glenhein/ddf/hooks","issue_events_url":"https://api.github.com/repos/glenhein/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/glenhein/ddf/events","assignees_url":"https://api.github.com/repos/glenhein/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/glenhein/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/glenhein/ddf/tags","blobs_url":"https://api.github.com/repos/glenhein/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/glenhein/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/glenhein/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/glenhein/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/glenhein/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/glenhein/ddf/languages","stargazers_url":"https://api.github.com/repos/glenhein/ddf/stargazers","contributors_url":"https://api.github.com/repos/glenhein/ddf/contributors","subscribers_url":"https://api.github.com/repos/glenhein/ddf/subscribers","subscription_url":"https://api.github.com/repos/glenhein/ddf/subscription","commits_url":"https://api.github.com/repos/glenhein/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/glenhein/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/glenhein/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/glenhein/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/glenhein/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/glenhein/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/glenhein/ddf/merges","archive_url":"https://api.github.com/repos/glenhein/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/glenhein/ddf/downloads","issues_url":"https://api.github.com/repos/glenhein/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/glenhein/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/glenhein/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/glenhein/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/glenhein/ddf/labels{/name}","releases_url":"https://api.github.com/repos/glenhein/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/glenhein/ddf/deployments","created_at":"2016-03-22T15:36:01Z","updated_at":"2016-03-22T15:36:13Z","pushed_at":"2016-11-10T18:05:55Z","git_url":"git://github.com/glenhein/ddf.git","ssh_url":"git@github.com:glenhein/ddf.git","clone_url":"https://github.com/glenhein/ddf.git","svn_url":"https://github.com/glenhein/ddf","homepage":"","size":150144,"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":"codice:master","ref":"master","sha":"5f2e5786ee97d893b8f84103b9a07e4059cf4963","user":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"repo":{"id":15173563,"name":"ddf","full_name":"codice/ddf","owner":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codice/ddf","description":"Distributed Data Framework - an open source, modular integration framework.","fork":false,"url":"https://api.github.com/repos/codice/ddf","forks_url":"https://api.github.com/repos/codice/ddf/forks","keys_url":"https://api.github.com/repos/codice/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codice/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codice/ddf/teams","hooks_url":"https://api.github.com/repos/codice/ddf/hooks","issue_events_url":"https://api.github.com/repos/codice/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/codice/ddf/events","assignees_url":"https://api.github.com/repos/codice/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/codice/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/codice/ddf/tags","blobs_url":"https://api.github.com/repos/codice/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codice/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codice/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/codice/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/codice/ddf/languages","stargazers_url":"https://api.github.com/repos/codice/ddf/stargazers","contributors_url":"https://api.github.com/repos/codice/ddf/contributors","subscribers_url":"https://api.github.com/repos/codice/ddf/subscribers","subscription_url":"https://api.github.com/repos/codice/ddf/subscription","commits_url":"https://api.github.com/repos/codice/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/codice/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/codice/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/codice/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/codice/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/codice/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codice/ddf/merges","archive_url":"https://api.github.com/repos/codice/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codice/ddf/downloads","issues_url":"https://api.github.com/repos/codice/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/codice/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/codice/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/codice/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codice/ddf/labels{/name}","releases_url":"https://api.github.com/repos/codice/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/codice/ddf/deployments","created_at":"2013-12-13T20:38:28Z","updated_at":"2016-11-08T16:53:10Z","pushed_at":"2016-11-10T18:40:31Z","git_url":"git://github.com/codice/ddf.git","ssh_url":"git@github.com:codice/ddf.git","clone_url":"https://github.com/codice/ddf.git","svn_url":"https://github.com/codice/ddf","homepage":"http://ddf.codice.org","size":295412,"stargazers_count":49,"watchers_count":49,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":96,"mirror_url":null,"open_issues_count":32,"forks":96,"open_issues":32,"watchers":49,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/1416"},"html":{"href":"https://github.com/codice/ddf/pull/1416"},"issue":{"href":"https://api.github.com/repos/codice/ddf/issues/1416"},"comments":{"href":"https://api.github.com/repos/codice/ddf/issues/1416/comments"},"review_comments":{"href":"https://api.github.com/repos/codice/ddf/pulls/1416/comments"},"review_comment":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codice/ddf/pulls/1416/commits"},"statuses":{"href":"https://api.github.com/repos/codice/ddf/statuses/31a10a94b20574788509bc4655d102df474126a3"}}}}
{"actor":{"display_login":"coyotesqrl"}}