{"action":"created","comment":{"url":"https://api.github.com/repos/linkedin/gobblin/pulls/comments/55246485","id":55246485,"diff_hunk":"@@ -0,0 +1,81 @@\n+/*\n+ * Copyright (C) 2014-2016 LinkedIn Corp. All rights reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use\n+ * this file except in compliance with the License. You may obtain a copy of the\n+ * License at  http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software distributed\n+ * under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR\n+ * CONDITIONS OF ANY KIND, either express or implied.\n+ */\n+\n+package gobblin.util.concurrent;\n+\n+import com.google.common.base.Optional;\n+import com.google.common.base.Preconditions;\n+import com.google.common.collect.ArrayListMultimap;\n+import com.google.common.collect.ImmutableList;\n+import com.google.common.collect.Multimap;\n+import org.apache.commons.lang.StringUtils;\n+\n+import java.io.Closeable;\n+import java.io.IOException;\n+import java.util.concurrent.TimeUnit;\n+\n+import lombok.Synchronized;\n+\n+\n+public abstract class TaskScheduler<K, T extends ScheduledTask<K>> implements Closeable {\n+  private final Multimap<K, CancellableScheduledTask<K>> cancellableScheduledTaskMap = ArrayListMultimap.create();\n+  private volatile boolean isStarted = false;\n+\n+  protected TaskScheduler() {\n+  }\n+\n+  @Synchronized\n+  final void start(Optional<String> name) {\n+    if (!this.isStarted) {\n+      this.startImpl(name);\n+      this.isStarted = true;\n+    }\n+  }\n+\n+  abstract void startImpl(Optional<String> name);\n+\n+  public final void schedule(T task, long interval, TimeUnit timeUnit) {\n+    Preconditions.checkArgument(isStarted, \"TaskScheduler is not started\");\n+    CancellableScheduledTask<K> cancellable = scheduleImpl(task, interval, timeUnit);\n+    this.cancellableScheduledTaskMap.put(task.getKey(), cancellable);\n+  }\n+\n+  abstract CancellableScheduledTask<K> scheduleImpl(T task, long interval, TimeUnit timeUnit);\n+\n+  public final Iterable<CancellableScheduledTask<K>> getScheduledTasks() {\n+    return ImmutableList.copyOf(this.cancellableScheduledTaskMap.values());\n+  }\n+\n+  public final Iterable<CancellableScheduledTask<K>> getScheduledTasks(K key) {\n+    return ImmutableList.copyOf(this.cancellableScheduledTaskMap.get(key));\n+  }\n+\n+  public void cancel(CancellableScheduledTask<K> task) {\n+    if (this.cancellableScheduledTaskMap.remove(task.getKey(), task)) {\n+      task.cancel();","path":"gobblin-utility/src/main/java/gobblin/util/concurrent/TaskScheduler.java","position":64,"original_position":64,"commit_id":"6692134fbe23c3038db01b4dba99eea76a7dd2bc","original_commit_id":"6692134fbe23c3038db01b4dba99eea76a7dd2bc","user":{"login":"ibuenros","id":1364112,"avatar_url":"https://avatars.githubusercontent.com/u/1364112?v=3","gravatar_id":"","url":"https://api.github.com/users/ibuenros","html_url":"https://github.com/ibuenros","followers_url":"https://api.github.com/users/ibuenros/followers","following_url":"https://api.github.com/users/ibuenros/following{/other_user}","gists_url":"https://api.github.com/users/ibuenros/gists{/gist_id}","starred_url":"https://api.github.com/users/ibuenros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ibuenros/subscriptions","organizations_url":"https://api.github.com/users/ibuenros/orgs","repos_url":"https://api.github.com/users/ibuenros/repos","events_url":"https://api.github.com/users/ibuenros/events{/privacy}","received_events_url":"https://api.github.com/users/ibuenros/received_events","type":"User","site_admin":false},"body":"My concern is, say `task.cancel()` throws a runtime exception, which is caught by the caller. If the caller attempts to cancel the task once again, the task will no longer be in the map, and nothing will be cancelled. Or am I understanding this wrong?","created_at":"2016-03-07T18:21:58Z","updated_at":"2016-03-07T18:21:58Z","html_url":"https://github.com/linkedin/gobblin/pull/768#discussion_r55246485","pull_request_url":"https://api.github.com/repos/linkedin/gobblin/pulls/768","_links":{"self":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/comments/55246485"},"html":{"href":"https://github.com/linkedin/gobblin/pull/768#discussion_r55246485"},"pull_request":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/768"}}},"pull_request":{"url":"https://api.github.com/repos/linkedin/gobblin/pulls/768","id":60879353,"html_url":"https://github.com/linkedin/gobblin/pull/768","diff_url":"https://github.com/linkedin/gobblin/pull/768.diff","patch_url":"https://github.com/linkedin/gobblin/pull/768.patch","issue_url":"https://api.github.com/repos/linkedin/gobblin/issues/768","number":768,"state":"open","locked":false,"title":"Switch LogCopier from ScheduledExecutorService to HashedWheelTimer","user":{"login":"kadaan","id":1904898,"avatar_url":"https://avatars.githubusercontent.com/u/1904898?v=3","gravatar_id":"","url":"https://api.github.com/users/kadaan","html_url":"https://github.com/kadaan","followers_url":"https://api.github.com/users/kadaan/followers","following_url":"https://api.github.com/users/kadaan/following{/other_user}","gists_url":"https://api.github.com/users/kadaan/gists{/gist_id}","starred_url":"https://api.github.com/users/kadaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kadaan/subscriptions","organizations_url":"https://api.github.com/users/kadaan/orgs","repos_url":"https://api.github.com/users/kadaan/repos","events_url":"https://api.github.com/users/kadaan/events{/privacy}","received_events_url":"https://api.github.com/users/kadaan/received_events","type":"User","site_admin":false},"body":"@sahilTakiar @ibuenros Can you please review this fix for #729. Also, add anyone else on your side who has had experience with this.","created_at":"2016-02-26T17:59:04Z","updated_at":"2016-03-07T18:21:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"22d26e7d3fa99fc9bcb28c60cca29edcd515fdbf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/linkedin/gobblin/pulls/768/commits","review_comments_url":"https://api.github.com/repos/linkedin/gobblin/pulls/768/comments","review_comment_url":"https://api.github.com/repos/linkedin/gobblin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/linkedin/gobblin/issues/768/comments","statuses_url":"https://api.github.com/repos/linkedin/gobblin/statuses/6692134fbe23c3038db01b4dba99eea76a7dd2bc","head":{"label":"kadaan:FixFor#729","ref":"FixFor#729","sha":"6692134fbe23c3038db01b4dba99eea76a7dd2bc","user":{"login":"kadaan","id":1904898,"avatar_url":"https://avatars.githubusercontent.com/u/1904898?v=3","gravatar_id":"","url":"https://api.github.com/users/kadaan","html_url":"https://github.com/kadaan","followers_url":"https://api.github.com/users/kadaan/followers","following_url":"https://api.github.com/users/kadaan/following{/other_user}","gists_url":"https://api.github.com/users/kadaan/gists{/gist_id}","starred_url":"https://api.github.com/users/kadaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kadaan/subscriptions","organizations_url":"https://api.github.com/users/kadaan/orgs","repos_url":"https://api.github.com/users/kadaan/repos","events_url":"https://api.github.com/users/kadaan/events{/privacy}","received_events_url":"https://api.github.com/users/kadaan/received_events","type":"User","site_admin":false},"repo":{"id":47274294,"name":"gobblin","full_name":"kadaan/gobblin","owner":{"login":"kadaan","id":1904898,"avatar_url":"https://avatars.githubusercontent.com/u/1904898?v=3","gravatar_id":"","url":"https://api.github.com/users/kadaan","html_url":"https://github.com/kadaan","followers_url":"https://api.github.com/users/kadaan/followers","following_url":"https://api.github.com/users/kadaan/following{/other_user}","gists_url":"https://api.github.com/users/kadaan/gists{/gist_id}","starred_url":"https://api.github.com/users/kadaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kadaan/subscriptions","organizations_url":"https://api.github.com/users/kadaan/orgs","repos_url":"https://api.github.com/users/kadaan/repos","events_url":"https://api.github.com/users/kadaan/events{/privacy}","received_events_url":"https://api.github.com/users/kadaan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kadaan/gobblin","description":"Universal data ingestion framework for Hadoop.","fork":true,"url":"https://api.github.com/repos/kadaan/gobblin","forks_url":"https://api.github.com/repos/kadaan/gobblin/forks","keys_url":"https://api.github.com/repos/kadaan/gobblin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kadaan/gobblin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kadaan/gobblin/teams","hooks_url":"https://api.github.com/repos/kadaan/gobblin/hooks","issue_events_url":"https://api.github.com/repos/kadaan/gobblin/issues/events{/number}","events_url":"https://api.github.com/repos/kadaan/gobblin/events","assignees_url":"https://api.github.com/repos/kadaan/gobblin/assignees{/user}","branches_url":"https://api.github.com/repos/kadaan/gobblin/branches{/branch}","tags_url":"https://api.github.com/repos/kadaan/gobblin/tags","blobs_url":"https://api.github.com/repos/kadaan/gobblin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kadaan/gobblin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kadaan/gobblin/git/refs{/sha}","trees_url":"https://api.github.com/repos/kadaan/gobblin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kadaan/gobblin/statuses/{sha}","languages_url":"https://api.github.com/repos/kadaan/gobblin/languages","stargazers_url":"https://api.github.com/repos/kadaan/gobblin/stargazers","contributors_url":"https://api.github.com/repos/kadaan/gobblin/contributors","subscribers_url":"https://api.github.com/repos/kadaan/gobblin/subscribers","subscription_url":"https://api.github.com/repos/kadaan/gobblin/subscription","commits_url":"https://api.github.com/repos/kadaan/gobblin/commits{/sha}","git_commits_url":"https://api.github.com/repos/kadaan/gobblin/git/commits{/sha}","comments_url":"https://api.github.com/repos/kadaan/gobblin/comments{/number}","issue_comment_url":"https://api.github.com/repos/kadaan/gobblin/issues/comments{/number}","contents_url":"https://api.github.com/repos/kadaan/gobblin/contents/{+path}","compare_url":"https://api.github.com/repos/kadaan/gobblin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kadaan/gobblin/merges","archive_url":"https://api.github.com/repos/kadaan/gobblin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kadaan/gobblin/downloads","issues_url":"https://api.github.com/repos/kadaan/gobblin/issues{/number}","pulls_url":"https://api.github.com/repos/kadaan/gobblin/pulls{/number}","milestones_url":"https://api.github.com/repos/kadaan/gobblin/milestones{/number}","notifications_url":"https://api.github.com/repos/kadaan/gobblin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kadaan/gobblin/labels{/name}","releases_url":"https://api.github.com/repos/kadaan/gobblin/releases{/id}","deployments_url":"https://api.github.com/repos/kadaan/gobblin/deployments","created_at":"2015-12-02T16:40:10Z","updated_at":"2016-01-11T23:41:37Z","pushed_at":"2016-03-05T07:38:33Z","git_url":"git://github.com/kadaan/gobblin.git","ssh_url":"git@github.com:kadaan/gobblin.git","clone_url":"https://github.com/kadaan/gobblin.git","svn_url":"https://github.com/kadaan/gobblin","homepage":"https://github.com/linkedin/gobblin/wiki","size":83466,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"linkedin:master","ref":"master","sha":"9036ab7e4a81e0eb201b76aa185c1164da7bc4b2","user":{"login":"linkedin","id":357098,"avatar_url":"https://avatars.githubusercontent.com/u/357098?v=3","gravatar_id":"","url":"https://api.github.com/users/linkedin","html_url":"https://github.com/linkedin","followers_url":"https://api.github.com/users/linkedin/followers","following_url":"https://api.github.com/users/linkedin/following{/other_user}","gists_url":"https://api.github.com/users/linkedin/gists{/gist_id}","starred_url":"https://api.github.com/users/linkedin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linkedin/subscriptions","organizations_url":"https://api.github.com/users/linkedin/orgs","repos_url":"https://api.github.com/users/linkedin/repos","events_url":"https://api.github.com/users/linkedin/events{/privacy}","received_events_url":"https://api.github.com/users/linkedin/received_events","type":"Organization","site_admin":false},"repo":{"id":27392543,"name":"gobblin","full_name":"linkedin/gobblin","owner":{"login":"linkedin","id":357098,"avatar_url":"https://avatars.githubusercontent.com/u/357098?v=3","gravatar_id":"","url":"https://api.github.com/users/linkedin","html_url":"https://github.com/linkedin","followers_url":"https://api.github.com/users/linkedin/followers","following_url":"https://api.github.com/users/linkedin/following{/other_user}","gists_url":"https://api.github.com/users/linkedin/gists{/gist_id}","starred_url":"https://api.github.com/users/linkedin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linkedin/subscriptions","organizations_url":"https://api.github.com/users/linkedin/orgs","repos_url":"https://api.github.com/users/linkedin/repos","events_url":"https://api.github.com/users/linkedin/events{/privacy}","received_events_url":"https://api.github.com/users/linkedin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/linkedin/gobblin","description":"Universal data ingestion framework for Hadoop.","fork":false,"url":"https://api.github.com/repos/linkedin/gobblin","forks_url":"https://api.github.com/repos/linkedin/gobblin/forks","keys_url":"https://api.github.com/repos/linkedin/gobblin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/linkedin/gobblin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/linkedin/gobblin/teams","hooks_url":"https://api.github.com/repos/linkedin/gobblin/hooks","issue_events_url":"https://api.github.com/repos/linkedin/gobblin/issues/events{/number}","events_url":"https://api.github.com/repos/linkedin/gobblin/events","assignees_url":"https://api.github.com/repos/linkedin/gobblin/assignees{/user}","branches_url":"https://api.github.com/repos/linkedin/gobblin/branches{/branch}","tags_url":"https://api.github.com/repos/linkedin/gobblin/tags","blobs_url":"https://api.github.com/repos/linkedin/gobblin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/linkedin/gobblin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/linkedin/gobblin/git/refs{/sha}","trees_url":"https://api.github.com/repos/linkedin/gobblin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/linkedin/gobblin/statuses/{sha}","languages_url":"https://api.github.com/repos/linkedin/gobblin/languages","stargazers_url":"https://api.github.com/repos/linkedin/gobblin/stargazers","contributors_url":"https://api.github.com/repos/linkedin/gobblin/contributors","subscribers_url":"https://api.github.com/repos/linkedin/gobblin/subscribers","subscription_url":"https://api.github.com/repos/linkedin/gobblin/subscription","commits_url":"https://api.github.com/repos/linkedin/gobblin/commits{/sha}","git_commits_url":"https://api.github.com/repos/linkedin/gobblin/git/commits{/sha}","comments_url":"https://api.github.com/repos/linkedin/gobblin/comments{/number}","issue_comment_url":"https://api.github.com/repos/linkedin/gobblin/issues/comments{/number}","contents_url":"https://api.github.com/repos/linkedin/gobblin/contents/{+path}","compare_url":"https://api.github.com/repos/linkedin/gobblin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/linkedin/gobblin/merges","archive_url":"https://api.github.com/repos/linkedin/gobblin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/linkedin/gobblin/downloads","issues_url":"https://api.github.com/repos/linkedin/gobblin/issues{/number}","pulls_url":"https://api.github.com/repos/linkedin/gobblin/pulls{/number}","milestones_url":"https://api.github.com/repos/linkedin/gobblin/milestones{/number}","notifications_url":"https://api.github.com/repos/linkedin/gobblin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/linkedin/gobblin/labels{/name}","releases_url":"https://api.github.com/repos/linkedin/gobblin/releases{/id}","deployments_url":"https://api.github.com/repos/linkedin/gobblin/deployments","created_at":"2014-12-01T18:10:50Z","updated_at":"2016-03-07T09:49:46Z","pushed_at":"2016-03-07T17:47:58Z","git_url":"git://github.com/linkedin/gobblin.git","ssh_url":"git@github.com:linkedin/gobblin.git","clone_url":"https://github.com/linkedin/gobblin.git","svn_url":"https://github.com/linkedin/gobblin","homepage":"https://github.com/linkedin/gobblin/wiki","size":164479,"stargazers_count":464,"watchers_count":464,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":177,"mirror_url":null,"open_issues_count":68,"forks":177,"open_issues":68,"watchers":464,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/768"},"html":{"href":"https://github.com/linkedin/gobblin/pull/768"},"issue":{"href":"https://api.github.com/repos/linkedin/gobblin/issues/768"},"comments":{"href":"https://api.github.com/repos/linkedin/gobblin/issues/768/comments"},"review_comments":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/768/comments"},"review_comment":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/768/commits"},"statuses":{"href":"https://api.github.com/repos/linkedin/gobblin/statuses/6692134fbe23c3038db01b4dba99eea76a7dd2bc"}}}}