GitHub PullRequestReviewCommentEvent at 2014-06-25 14:30:56
Repository: finagle
Actor: jixu
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/twitter/finagle/pulls/comments/14188707","id":14188707,"diff_hunk":"@@ -39,13 +40,62 @@ trait Resolver {\n  */\n abstract class AbstractResolver extends Resolver\n \n+/**\n+ * Resolver for inet scheme. This Resolver resolves DNS after each ttl timeouts.\n+ * Ttl is got from \"networkaddress.cache.ttl\" which is a Java Security Property.\n+ * If \"networkaddress.cache.ttl\" is not set or set to non-positive value, DNS cache refresh will be turned off.\n+ */\n object InetResolver extends Resolver {\n   val scheme = \"inet\"\n+  private val log = Logger.getLogger(getClass.getName)\n+  private val ttlOption = {\n+    val t = Try(Option(java.security.AccessController.doPrivileged(\n+      new PrivilegedAction[String] {\n+        override def run(): String = Security.getProperty(\"networkaddress.cache.ttl\")\n+      }\n+    )) map { s => s.toInt })\n+\n+    t match {\n+      case Throw(exc: NumberFormatException) =>\n+        log.log(Level.WARNING, \"networkaddress.cache.ttl is set as non-number, DNS cache refresh turned off\", exc)\n+        None\n+      case Return(None) =>\n+        log.log(Level.INFO, \"networkaddress.cache.ttl is not set, DNS cache refresh turned off\")\n+        None\n+      case Return(Some(value)) =>\n+        if (value <= 0) {\n+          log.log(Level.INFO, \"networkaddress.cache.ttl is set as non-positive value, DNS cache refresh turned off\")\n+          None\n+        } else Some(value.seconds)\n+    }\n+  }\n+  private val timer = DefaultTimer.twitter\n+  private val futurePool = FuturePool.unboundedPool\n \n-  def bind(arg: String) = {\n-    val sockaddrs = InetSocketAddressUtil.parseHosts(arg)\n-    val addr = Addr.Bound(sockaddrs:_*)\n-    Var.value(addr)\n+  /**\n+   * Binds to the specified hostnames, and refreshes the DNS information periodically.\n+   */\n+  def bind(hosts: String): Var[Addr] = {\n+    import InetSocketAddressUtil._\n+\n+    if (hosts == \":*\") return Var.value(Addr.Bound(new InetSocketAddress(0)))\n+\n+    val hostPorts = parseHostPorts(hosts)\n+    val init = Addr.Bound(resolveHostPorts(hostPorts))\n+    ttlOption match {\n+      case Some(ttl) =>\n+        Var.async(init) { u =>\n+          timer.schedule(ttl.fromNow, ttl) {","path":"finagle-core/src/main/scala/com/twitter/finagle/Resolver.scala","position":71,"original_position":71,"commit_id":"175aef9f36a1b50f88fb684b726550b7197c2f1b","original_commit_id":"175aef9f36a1b50f88fb684b726550b7197c2f1b","user":{"login":"jixu","id":1232329,"avatar_url":"https://avatars.githubusercontent.com/u/1232329?","gravatar_id":"bf12693cbf97d83ec03d037bbbcf8473","url":"https://api.github.com/users/jixu","html_url":"https://github.com/jixu","followers_url":"https://api.github.com/users/jixu/followers","following_url":"https://api.github.com/users/jixu/following{/other_user}","gists_url":"https://api.github.com/users/jixu/gists{/gist_id}","starred_url":"https://api.github.com/users/jixu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jixu/subscriptions","organizations_url":"https://api.github.com/users/jixu/orgs","repos_url":"https://api.github.com/users/jixu/repos","events_url":"https://api.github.com/users/jixu/events{/privacy}","received_events_url":"https://api.github.com/users/jixu/received_events","type":"User","site_admin":false},"body":"@mariusaeriksen Do you mean we should use <code>com.twitter.finagle.util.Updater</code> to prevent duplicated DNS resolution on one host?\r\nAny examples I can refer to create the <code>Updater</code>?","created_at":"2014-06-25T14:30:56Z","updated_at":"2014-06-25T14:30:56Z","html_url":"https://github.com/twitter/finagle/pull/282#discussion_r14188707","pull_request_url":"https://api.github.com/repos/twitter/finagle/pulls/282","_links":{"self":{"href":"https://api.github.com/repos/twitter/finagle/pulls/comments/14188707"},"html":{"href":"https://github.com/twitter/finagle/pull/282#discussion_r14188707"},"pull_request":{"href":"https://api.github.com/repos/twitter/finagle/pulls/282"}}},"pull_request":{"url":"https://api.github.com/repos/twitter/finagle/pulls/282","id":17294470,"html_url":"https://github.com/twitter/finagle/pull/282","diff_url":"https://github.com/twitter/finagle/pull/282.diff","patch_url":"https://github.com/twitter/finagle/pull/282.patch","issue_url":"https://api.github.com/repos/twitter/finagle/issues/282","number":282,"state":"open","title":"finagle-core: make timer-based DNS resolution as default of InetResolver","user":{"login":"jixu","id":1232329,"avatar_url":"https://avatars.githubusercontent.com/u/1232329?","gravatar_id":"bf12693cbf97d83ec03d037bbbcf8473","url":"https://api.github.com/users/jixu","html_url":"https://github.com/jixu","followers_url":"https://api.github.com/users/jixu/followers","following_url":"https://api.github.com/users/jixu/following{/other_user}","gists_url":"https://api.github.com/users/jixu/gists{/gist_id}","starred_url":"https://api.github.com/users/jixu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jixu/subscriptions","organizations_url":"https://api.github.com/users/jixu/orgs","repos_url":"https://api.github.com/users/jixu/repos","events_url":"https://api.github.com/users/jixu/events{/privacy}","received_events_url":"https://api.github.com/users/jixu/received_events","type":"User","site_admin":false},"body":"I have tested on my macbook and the timer-based DNS resolution works fine.","created_at":"2014-06-18T13:56:20Z","updated_at":"2014-06-25T14:30:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a4c3a471fe1e37b64aebda1db65c331a0b0ecf1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/twitter/finagle/pulls/282/commits","review_comments_url":"https://api.github.com/repos/twitter/finagle/pulls/282/comments","review_comment_url":"https://api.github.com/repos/twitter/finagle/pulls/comments/{number}","comments_url":"https://api.github.com/repos/twitter/finagle/issues/282/comments","statuses_url":"https://api.github.com/repos/twitter/finagle/statuses/175aef9f36a1b50f88fb684b726550b7197c2f1b","head":{"label":"jixu:dns-resolution","ref":"dns-resolution","sha":"175aef9f36a1b50f88fb684b726550b7197c2f1b","user":{"login":"jixu","id":1232329,"avatar_url":"https://avatars.githubusercontent.com/u/1232329?","gravatar_id":"bf12693cbf97d83ec03d037bbbcf8473","url":"https://api.github.com/users/jixu","html_url":"https://github.com/jixu","followers_url":"https://api.github.com/users/jixu/followers","following_url":"https://api.github.com/users/jixu/following{/other_user}","gists_url":"https://api.github.com/users/jixu/gists{/gist_id}","starred_url":"https://api.github.com/users/jixu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jixu/subscriptions","organizations_url":"https://api.github.com/users/jixu/orgs","repos_url":"https://api.github.com/users/jixu/repos","events_url":"https://api.github.com/users/jixu/events{/privacy}","received_events_url":"https://api.github.com/users/jixu/received_events","type":"User","site_admin":false},"repo":{"id":15668088,"name":"finagle","full_name":"jixu/finagle","owner":{"login":"jixu","id":1232329,"avatar_url":"https://avatars.githubusercontent.com/u/1232329?","gravatar_id":"bf12693cbf97d83ec03d037bbbcf8473","url":"https://api.github.com/users/jixu","html_url":"https://github.com/jixu","followers_url":"https://api.github.com/users/jixu/followers","following_url":"https://api.github.com/users/jixu/following{/other_user}","gists_url":"https://api.github.com/users/jixu/gists{/gist_id}","starred_url":"https://api.github.com/users/jixu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jixu/subscriptions","organizations_url":"https://api.github.com/users/jixu/orgs","repos_url":"https://api.github.com/users/jixu/repos","events_url":"https://api.github.com/users/jixu/events{/privacy}","received_events_url":"https://api.github.com/users/jixu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jixu/finagle","description":"A fault tolerant, protocol-agnostic RPC system","fork":true,"url":"https://api.github.com/repos/jixu/finagle","forks_url":"https://api.github.com/repos/jixu/finagle/forks","keys_url":"https://api.github.com/repos/jixu/finagle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jixu/finagle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jixu/finagle/teams","hooks_url":"https://api.github.com/repos/jixu/finagle/hooks","issue_events_url":"https://api.github.com/repos/jixu/finagle/issues/events{/number}","events_url":"https://api.github.com/repos/jixu/finagle/events","assignees_url":"https://api.github.com/repos/jixu/finagle/assignees{/user}","branches_url":"https://api.github.com/repos/jixu/finagle/branches{/branch}","tags_url":"https://api.github.com/repos/jixu/finagle/tags","blobs_url":"https://api.github.com/repos/jixu/finagle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jixu/finagle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jixu/finagle/git/refs{/sha}","trees_url":"https://api.github.com/repos/jixu/finagle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jixu/finagle/statuses/{sha}","languages_url":"https://api.github.com/repos/jixu/finagle/languages","stargazers_url":"https://api.github.com/repos/jixu/finagle/stargazers","contributors_url":"https://api.github.com/repos/jixu/finagle/contributors","subscribers_url":"https://api.github.com/repos/jixu/finagle/subscribers","subscription_url":"https://api.github.com/repos/jixu/finagle/subscription","commits_url":"https://api.github.com/repos/jixu/finagle/commits{/sha}","git_commits_url":"https://api.github.com/repos/jixu/finagle/git/commits{/sha}","comments_url":"https://api.github.com/repos/jixu/finagle/comments{/number}","issue_comment_url":"https://api.github.com/repos/jixu/finagle/issues/comments/{number}","contents_url":"https://api.github.com/repos/jixu/finagle/contents/{+path}","compare_url":"https://api.github.com/repos/jixu/finagle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jixu/finagle/merges","archive_url":"https://api.github.com/repos/jixu/finagle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jixu/finagle/downloads","issues_url":"https://api.github.com/repos/jixu/finagle/issues{/number}","pulls_url":"https://api.github.com/repos/jixu/finagle/pulls{/number}","milestones_url":"https://api.github.com/repos/jixu/finagle/milestones{/number}","notifications_url":"https://api.github.com/repos/jixu/finagle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jixu/finagle/labels{/name}","releases_url":"https://api.github.com/repos/jixu/finagle/releases{/id}","created_at":"2014-01-06T07:31:15Z","updated_at":"2014-06-22T00:57:45Z","pushed_at":"2014-06-22T00:57:45Z","git_url":"git://github.com/jixu/finagle.git","ssh_url":"git@github.com:jixu/finagle.git","clone_url":"https://github.com/jixu/finagle.git","svn_url":"https://github.com/jixu/finagle","homepage":"http://twitter.github.io/finagle","size":17757,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"76e25a43308fc1fa468f332426710334a3220741","user":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?","gravatar_id":"2f4a8254d032a8ec5e4c48d461e54fcc","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":1007362,"name":"finagle","full_name":"twitter/finagle","owner":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?","gravatar_id":"2f4a8254d032a8ec5e4c48d461e54fcc","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/finagle","description":"A fault tolerant, protocol-agnostic RPC system","fork":false,"url":"https://api.github.com/repos/twitter/finagle","forks_url":"https://api.github.com/repos/twitter/finagle/forks","keys_url":"https://api.github.com/repos/twitter/finagle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twitter/finagle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twitter/finagle/teams","hooks_url":"https://api.github.com/repos/twitter/finagle/hooks","issue_events_url":"https://api.github.com/repos/twitter/finagle/issues/events{/number}","events_url":"https://api.github.com/repos/twitter/finagle/events","assignees_url":"https://api.github.com/repos/twitter/finagle/assignees{/user}","branches_url":"https://api.github.com/repos/twitter/finagle/branches{/branch}","tags_url":"https://api.github.com/repos/twitter/finagle/tags","blobs_url":"https://api.github.com/repos/twitter/finagle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twitter/finagle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twitter/finagle/git/refs{/sha}","trees_url":"https://api.github.com/repos/twitter/finagle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twitter/finagle/statuses/{sha}","languages_url":"https://api.github.com/repos/twitter/finagle/languages","stargazers_url":"https://api.github.com/repos/twitter/finagle/stargazers","contributors_url":"https://api.github.com/repos/twitter/finagle/contributors","subscribers_url":"https://api.github.com/repos/twitter/finagle/subscribers","subscription_url":"https://api.github.com/repos/twitter/finagle/subscription","commits_url":"https://api.github.com/repos/twitter/finagle/commits{/sha}","git_commits_url":"https://api.github.com/repos/twitter/finagle/git/commits{/sha}","comments_url":"https://api.github.com/repos/twitter/finagle/comments{/number}","issue_comment_url":"https://api.github.com/repos/twitter/finagle/issues/comments/{number}","contents_url":"https://api.github.com/repos/twitter/finagle/contents/{+path}","compare_url":"https://api.github.com/repos/twitter/finagle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twitter/finagle/merges","archive_url":"https://api.github.com/repos/twitter/finagle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twitter/finagle/downloads","issues_url":"https://api.github.com/repos/twitter/finagle/issues{/number}","pulls_url":"https://api.github.com/repos/twitter/finagle/pulls{/number}","milestones_url":"https://api.github.com/repos/twitter/finagle/milestones{/number}","notifications_url":"https://api.github.com/repos/twitter/finagle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twitter/finagle/labels{/name}","releases_url":"https://api.github.com/repos/twitter/finagle/releases{/id}","created_at":"2010-10-19T22:10:09Z","updated_at":"2014-06-24T05:38:50Z","pushed_at":"2014-06-07T01:59:16Z","git_url":"git://github.com/twitter/finagle.git","ssh_url":"git@github.com:twitter/finagle.git","clone_url":"https://github.com/twitter/finagle.git","svn_url":"https://github.com/twitter/finagle","homepage":"http://twitter.github.io/finagle","size":24218,"stargazers_count":2645,"watchers_count":2645,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"forks_count":453,"mirror_url":null,"open_issues_count":44,"forks":453,"open_issues":44,"watchers":2645,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/twitter/finagle/pulls/282"},"html":{"href":"https://github.com/twitter/finagle/pull/282"},"issue":{"href":"https://api.github.com/repos/twitter/finagle/issues/282"},"comments":{"href":"https://api.github.com/repos/twitter/finagle/issues/282/comments"},"review_comments":{"href":"https://api.github.com/repos/twitter/finagle/pulls/282/comments"},"review_comment":{"href":"https://api.github.com/repos/twitter/finagle/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/twitter/finagle/pulls/282/commits"},"statuses":{"href":"https://api.github.com/repos/twitter/finagle/statuses/175aef9f36a1b50f88fb684b726550b7197c2f1b"}}}}