{"action":"created","comment":{"url":"https://api.github.com/repos/apache/reef/pulls/comments/135363799","pull_request_review_id":58775439,"id":135363799,"diff_hunk":"@@ -0,0 +1,118 @@\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.reef.util;\n+\n+import java.util.concurrent.FutureTask;\n+import java.util.concurrent.TimeUnit;\n+import java.util.concurrent.locks.Condition;\n+import java.util.concurrent.locks.Lock;\n+import java.util.concurrent.locks.ReentrantLock;\n+\n+/**\n+ * Manages Java lock and condition objects to create a simplified\n+ * condition variable interface.\n+ */\n+public final class SimpleCondition {\n+  private final Lock lockVar = new ReentrantLock();\n+  private final Condition conditionVar = lockVar.newCondition();\n+  private final long timeoutPeriod;\n+  private final TimeUnit timeoutUnits;\n+  private static final long DEFAULT_TIMEOUT = 10;\n+\n+  /**\n+   * Default constructor which initializes timeout period to 10 seconds.\n+   */\n+  public SimpleCondition() {\n+    this(DEFAULT_TIMEOUT, TimeUnit.SECONDS);\n+  }\n+\n+  /**\n+   * Initialize condition variable with user specified timeout.\n+   * @param timeoutPeriod The length of time in units given by the the timeoutUnits\n+   *                      parameter before the condition automatically times out.\n+   * @param timeoutUnits The unit of time for the timeoutPeriod parameter.\n+   */\n+  public SimpleCondition(final long timeoutPeriod, final TimeUnit timeoutUnits) {\n+    this.timeoutPeriod = timeoutPeriod;\n+    this.timeoutUnits = timeoutUnits;\n+  }\n+\n+  /**\n+   * Blocks the caller until {@code signal()} is called or a timeout occurs.\n+   * Logical structure:\n+   * {@code\n+   *   cv.lock();\n+   *   try {\n+   *     doTry.run();\n+   *     cv.await(); // or cv.signal()\n+   *   } finally {\n+   *     doFinally.run();\n+   *     cv.unlock();\n+   *   }\n+   * }\n+   * @param doTry A {@code FutureTask<TTry>} object that is run after the internal\n+   *              condition lock is taken but before waiting on the condition occurs.\n+   * @param doFinally A {@code FutureTask<TFinally>} object that is run after the wakeup\n+   *                  on the condition occurs but before giving up the condition lock\n+   *                  is released.\n+   * @param <TTry> The return type of the {@code doTry} future task.\n+   * @param <TFinally> The return type of the {@code doFinally} future task.\n+   * @return A boolean value that indicates whether or not a timeout occurred.\n+   * @throws InterruptedException Thread was interrupted by another thread while\n+   * waiting for the signal.\n+   * @throws Exception The callers\n+   */\n+  public <TTry, TFinally> boolean await(final FutureTask<TTry> doTry,\n+                                        final FutureTask<TFinally> doFinally) throws Exception {\n+    final boolean timeoutOccurred;\n+    lockVar.lock();\n+    try {\n+      if (null != doTry) {\n+        // Invoke the caller's asynchronous processing while holding the lock\n+        // so a wakeup cannot occur before the caller sleeps.\n+        doTry.run();\n+      }\n+      // Put the caller asleep on the condition until a signal is received\n+      // or a timeout occurs.\n+      timeoutOccurred = !conditionVar.await(timeoutPeriod, timeoutUnits);","path":"lang/java/reef-utils/src/main/java/org/apache/reef/util/SimpleCondition.java","position":null,"original_position":92,"commit_id":"ec137ea14f145d75f7806bd257a3ba042bfaca7b","original_commit_id":"74a98c791eb26bf29a9f8ded8ef30b2051afdeaf","user":{"login":"dougmsft","id":8461862,"avatar_url":"https://avatars2.githubusercontent.com/u/8461862?v=4","gravatar_id":"","url":"https://api.github.com/users/dougmsft","html_url":"https://github.com/dougmsft","followers_url":"https://api.github.com/users/dougmsft/followers","following_url":"https://api.github.com/users/dougmsft/following{/other_user}","gists_url":"https://api.github.com/users/dougmsft/gists{/gist_id}","starred_url":"https://api.github.com/users/dougmsft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougmsft/subscriptions","organizations_url":"https://api.github.com/users/dougmsft/orgs","repos_url":"https://api.github.com/users/dougmsft/repos","events_url":"https://api.github.com/users/dougmsft/events{/privacy}","received_events_url":"https://api.github.com/users/dougmsft/received_events","type":"User","site_admin":false},"body":"Fixed.","created_at":"2017-08-25T22:17:44Z","updated_at":"2017-08-25T22:17:44Z","html_url":"https://github.com/apache/reef/pull/1365#discussion_r135363799","pull_request_url":"https://api.github.com/repos/apache/reef/pulls/1365","_links":{"self":{"href":"https://api.github.com/repos/apache/reef/pulls/comments/135363799"},"html":{"href":"https://github.com/apache/reef/pull/1365#discussion_r135363799"},"pull_request":{"href":"https://api.github.com/repos/apache/reef/pulls/1365"}},"in_reply_to_id":135110833},"pull_request":{"url":"https://api.github.com/repos/apache/reef/pulls/1365","id":135439972,"html_url":"https://github.com/apache/reef/pull/1365","diff_url":"https://github.com/apache/reef/pull/1365.diff","patch_url":"https://github.com/apache/reef/pull/1365.patch","issue_url":"https://api.github.com/repos/apache/reef/issues/1365","number":1365,"state":"open","locked":false,"title":"[REEF-1864] Utility to convert asynchronous API to synchronous.","user":{"login":"dougmsft","id":8461862,"avatar_url":"https://avatars2.githubusercontent.com/u/8461862?v=4","gravatar_id":"","url":"https://api.github.com/users/dougmsft","html_url":"https://github.com/dougmsft","followers_url":"https://api.github.com/users/dougmsft/followers","following_url":"https://api.github.com/users/dougmsft/following{/other_user}","gists_url":"https://api.github.com/users/dougmsft/gists{/gist_id}","starred_url":"https://api.github.com/users/dougmsft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougmsft/subscriptions","organizations_url":"https://api.github.com/users/dougmsft/orgs","repos_url":"https://api.github.com/users/dougmsft/repos","events_url":"https://api.github.com/users/dougmsft/events{/privacy}","received_events_url":"https://api.github.com/users/dougmsft/received_events","type":"User","site_admin":false},"body":"JIRA:\r\n  [REEF-1864](https://issues.apache.org/jira/browse/REEF-1864)\r\n\r\n  * Adds condition variable class to manage sleep on condition variables.\r\n  * Adds MultiAsyncToSynch class to for managing the callers of an API\r\n    which is synchronous but is implmented asynchronously.\r\n  * Adds MultiAsyncToSyncTest which verifies that non-timeout, timeout,\r\n    and multiple non-timeout calls are complete correctly.\r\n\r\nPull Request:\r\n  Closes #","created_at":"2017-08-12T00:32:25Z","updated_at":"2017-08-25T22:17:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e37304c9db12818b4cb415c69d186c27d04c0623","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/reef/pulls/1365/commits","review_comments_url":"https://api.github.com/repos/apache/reef/pulls/1365/comments","review_comment_url":"https://api.github.com/repos/apache/reef/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/reef/issues/1365/comments","statuses_url":"https://api.github.com/repos/apache/reef/statuses/ec137ea14f145d75f7806bd257a3ba042bfaca7b","head":{"label":"dougmsft:REEF-1864","ref":"REEF-1864","sha":"ec137ea14f145d75f7806bd257a3ba042bfaca7b","user":{"login":"dougmsft","id":8461862,"avatar_url":"https://avatars2.githubusercontent.com/u/8461862?v=4","gravatar_id":"","url":"https://api.github.com/users/dougmsft","html_url":"https://github.com/dougmsft","followers_url":"https://api.github.com/users/dougmsft/followers","following_url":"https://api.github.com/users/dougmsft/following{/other_user}","gists_url":"https://api.github.com/users/dougmsft/gists{/gist_id}","starred_url":"https://api.github.com/users/dougmsft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougmsft/subscriptions","organizations_url":"https://api.github.com/users/dougmsft/orgs","repos_url":"https://api.github.com/users/dougmsft/repos","events_url":"https://api.github.com/users/dougmsft/events{/privacy}","received_events_url":"https://api.github.com/users/dougmsft/received_events","type":"User","site_admin":false},"repo":{"id":64526716,"name":"reef","full_name":"dougmsft/reef","owner":{"login":"dougmsft","id":8461862,"avatar_url":"https://avatars2.githubusercontent.com/u/8461862?v=4","gravatar_id":"","url":"https://api.github.com/users/dougmsft","html_url":"https://github.com/dougmsft","followers_url":"https://api.github.com/users/dougmsft/followers","following_url":"https://api.github.com/users/dougmsft/following{/other_user}","gists_url":"https://api.github.com/users/dougmsft/gists{/gist_id}","starred_url":"https://api.github.com/users/dougmsft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougmsft/subscriptions","organizations_url":"https://api.github.com/users/dougmsft/orgs","repos_url":"https://api.github.com/users/dougmsft/repos","events_url":"https://api.github.com/users/dougmsft/events{/privacy}","received_events_url":"https://api.github.com/users/dougmsft/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dougmsft/reef","description":"Mirror of Apache REEF","fork":true,"url":"https://api.github.com/repos/dougmsft/reef","forks_url":"https://api.github.com/repos/dougmsft/reef/forks","keys_url":"https://api.github.com/repos/dougmsft/reef/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dougmsft/reef/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dougmsft/reef/teams","hooks_url":"https://api.github.com/repos/dougmsft/reef/hooks","issue_events_url":"https://api.github.com/repos/dougmsft/reef/issues/events{/number}","events_url":"https://api.github.com/repos/dougmsft/reef/events","assignees_url":"https://api.github.com/repos/dougmsft/reef/assignees{/user}","branches_url":"https://api.github.com/repos/dougmsft/reef/branches{/branch}","tags_url":"https://api.github.com/repos/dougmsft/reef/tags","blobs_url":"https://api.github.com/repos/dougmsft/reef/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dougmsft/reef/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dougmsft/reef/git/refs{/sha}","trees_url":"https://api.github.com/repos/dougmsft/reef/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dougmsft/reef/statuses/{sha}","languages_url":"https://api.github.com/repos/dougmsft/reef/languages","stargazers_url":"https://api.github.com/repos/dougmsft/reef/stargazers","contributors_url":"https://api.github.com/repos/dougmsft/reef/contributors","subscribers_url":"https://api.github.com/repos/dougmsft/reef/subscribers","subscription_url":"https://api.github.com/repos/dougmsft/reef/subscription","commits_url":"https://api.github.com/repos/dougmsft/reef/commits{/sha}","git_commits_url":"https://api.github.com/repos/dougmsft/reef/git/commits{/sha}","comments_url":"https://api.github.com/repos/dougmsft/reef/comments{/number}","issue_comment_url":"https://api.github.com/repos/dougmsft/reef/issues/comments{/number}","contents_url":"https://api.github.com/repos/dougmsft/reef/contents/{+path}","compare_url":"https://api.github.com/repos/dougmsft/reef/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dougmsft/reef/merges","archive_url":"https://api.github.com/repos/dougmsft/reef/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dougmsft/reef/downloads","issues_url":"https://api.github.com/repos/dougmsft/reef/issues{/number}","pulls_url":"https://api.github.com/repos/dougmsft/reef/pulls{/number}","milestones_url":"https://api.github.com/repos/dougmsft/reef/milestones{/number}","notifications_url":"https://api.github.com/repos/dougmsft/reef/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dougmsft/reef/labels{/name}","releases_url":"https://api.github.com/repos/dougmsft/reef/releases{/id}","deployments_url":"https://api.github.com/repos/dougmsft/reef/deployments","created_at":"2016-07-30T04:47:03Z","updated_at":"2017-04-04T02:52:09Z","pushed_at":"2017-08-25T22:14:18Z","git_url":"git://github.com/dougmsft/reef.git","ssh_url":"git@github.com:dougmsft/reef.git","clone_url":"https://github.com/dougmsft/reef.git","svn_url":"https://github.com/dougmsft/reef","homepage":"","size":56742,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"47593a77059e082b1e094af3b6811473cb5ac628","user":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","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":25623941,"name":"reef","full_name":"apache/reef","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","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/reef","description":"Mirror of Apache REEF","fork":false,"url":"https://api.github.com/repos/apache/reef","forks_url":"https://api.github.com/repos/apache/reef/forks","keys_url":"https://api.github.com/repos/apache/reef/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/reef/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/reef/teams","hooks_url":"https://api.github.com/repos/apache/reef/hooks","issue_events_url":"https://api.github.com/repos/apache/reef/issues/events{/number}","events_url":"https://api.github.com/repos/apache/reef/events","assignees_url":"https://api.github.com/repos/apache/reef/assignees{/user}","branches_url":"https://api.github.com/repos/apache/reef/branches{/branch}","tags_url":"https://api.github.com/repos/apache/reef/tags","blobs_url":"https://api.github.com/repos/apache/reef/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/reef/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/reef/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/reef/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/reef/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/reef/languages","stargazers_url":"https://api.github.com/repos/apache/reef/stargazers","contributors_url":"https://api.github.com/repos/apache/reef/contributors","subscribers_url":"https://api.github.com/repos/apache/reef/subscribers","subscription_url":"https://api.github.com/repos/apache/reef/subscription","commits_url":"https://api.github.com/repos/apache/reef/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/reef/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/reef/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/reef/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/reef/contents/{+path}","compare_url":"https://api.github.com/repos/apache/reef/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/reef/merges","archive_url":"https://api.github.com/repos/apache/reef/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/reef/downloads","issues_url":"https://api.github.com/repos/apache/reef/issues{/number}","pulls_url":"https://api.github.com/repos/apache/reef/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/reef/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/reef/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/reef/labels{/name}","releases_url":"https://api.github.com/repos/apache/reef/releases{/id}","deployments_url":"https://api.github.com/repos/apache/reef/deployments","created_at":"2014-10-23T07:00:10Z","updated_at":"2017-08-20T14:45:18Z","pushed_at":"2017-08-25T22:14:20Z","git_url":"git://github.com/apache/reef.git","ssh_url":"git@github.com:apache/reef.git","clone_url":"https://github.com/apache/reef.git","svn_url":"https://github.com/apache/reef","homepage":"","size":38875,"stargazers_count":71,"watchers_count":71,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":88,"mirror_url":"git://git.apache.org/reef.git","open_issues_count":11,"forks":88,"open_issues":11,"watchers":71,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/reef/pulls/1365"},"html":{"href":"https://github.com/apache/reef/pull/1365"},"issue":{"href":"https://api.github.com/repos/apache/reef/issues/1365"},"comments":{"href":"https://api.github.com/repos/apache/reef/issues/1365/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/reef/pulls/1365/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/reef/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/reef/pulls/1365/commits"},"statuses":{"href":"https://api.github.com/repos/apache/reef/statuses/ec137ea14f145d75f7806bd257a3ba042bfaca7b"}}}}
{"actor":{"display_login":"dougmsft"}}