{"action":"created","comment":{"url":"https://api.github.com/repos/twitter/finagle/pulls/comments/47053618","id":47053618,"diff_hunk":"@@ -0,0 +1,38 @@\n+package com.twitter.finagle.redis.dispatch\n+\n+import com.twitter.finagle.dispatch.GenSerialClientDispatcher\n+import com.twitter.finagle.redis.protocol._\n+import com.twitter.finagle.transport.Transport\n+import com.twitter.util.{Future, Promise}\n+import java.util.concurrent.atomic.AtomicReference\n+\n+class SubscribeDispatcher(trans: Transport[SubscribeCommand, Reply])\n+    extends GenSerialClientDispatcher[SubscribeCommand, Unit, SubscribeCommand, Reply](trans) {\n+\n+  private var listener = new AtomicReference[SubscribeListener]\n+\n+  loop()\n+\n+  private[this] def handleMessage(reply: Reply) {\n+    listener.get().onMessage(reply)\n+    loop()\n+\n+}\n+\n+  private[this] def loop(): Unit =\n+    trans.read().onSuccess { reply =>\n+      listener.get().onMessage(reply)\n+      loop()\n+    }\n+    .onFailure { ex =>\n+      Option(listener.get()).map(_.onException(ex))\n+    }\n+\n+  protected def dispatch(req: SubscribeCommand, p: Promise[Unit]): Future[Unit] =\n+    trans.write(req).onSuccess { _ => p.setDone() }\n+\n+  override def apply(req: SubscribeCommand): Future[Unit] = {\n+    listener.compareAndSet(null, req.listener)","path":"finagle-redis/src/main/scala/com/twitter/finagle/redis/dispatch/SubscribeDispatcher.scala","position":35,"original_position":35,"commit_id":"f4e6fffe3fc5a09d4ffc8b9c5c05e25bc9dce191","original_commit_id":"49e79618f5097e4353181c948dfb25b0c92e0386","user":{"login":"thirstycrow","id":1327305,"avatar_url":"https://avatars.githubusercontent.com/u/1327305?v=3","gravatar_id":"","url":"https://api.github.com/users/thirstycrow","html_url":"https://github.com/thirstycrow","followers_url":"https://api.github.com/users/thirstycrow/followers","following_url":"https://api.github.com/users/thirstycrow/following{/other_user}","gists_url":"https://api.github.com/users/thirstycrow/gists{/gist_id}","starred_url":"https://api.github.com/users/thirstycrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thirstycrow/subscriptions","organizations_url":"https://api.github.com/users/thirstycrow/orgs","repos_url":"https://api.github.com/users/thirstycrow/repos","events_url":"https://api.github.com/users/thirstycrow/events{/privacy}","received_events_url":"https://api.github.com/users/thirstycrow/received_events","type":"User","site_admin":false},"body":"All commands created by the same SubscribeClient instance carries the same listener, which is the SubscribeClient instance itself. It would be better if the SubscribeClient can be passed as a constructor argument for the dispatcher.","created_at":"2015-12-09T05:51:32Z","updated_at":"2015-12-09T05:51:32Z","html_url":"https://github.com/twitter/finagle/pull/447#discussion_r47053618","pull_request_url":"https://api.github.com/repos/twitter/finagle/pulls/447","_links":{"self":{"href":"https://api.github.com/repos/twitter/finagle/pulls/comments/47053618"},"html":{"href":"https://github.com/twitter/finagle/pull/447#discussion_r47053618"},"pull_request":{"href":"https://api.github.com/repos/twitter/finagle/pulls/447"}}},"pull_request":{"url":"https://api.github.com/repos/twitter/finagle/pulls/447","id":52992378,"html_url":"https://github.com/twitter/finagle/pull/447","diff_url":"https://github.com/twitter/finagle/pull/447.diff","patch_url":"https://github.com/twitter/finagle/pull/447.patch","issue_url":"https://api.github.com/repos/twitter/finagle/issues/447","number":447,"state":"open","locked":false,"title":"pubsub support","user":{"login":"thirstycrow","id":1327305,"avatar_url":"https://avatars.githubusercontent.com/u/1327305?v=3","gravatar_id":"","url":"https://api.github.com/users/thirstycrow","html_url":"https://github.com/thirstycrow","followers_url":"https://api.github.com/users/thirstycrow/followers","following_url":"https://api.github.com/users/thirstycrow/following{/other_user}","gists_url":"https://api.github.com/users/thirstycrow/gists{/gist_id}","starred_url":"https://api.github.com/users/thirstycrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thirstycrow/subscriptions","organizations_url":"https://api.github.com/users/thirstycrow/orgs","repos_url":"https://api.github.com/users/thirstycrow/repos","events_url":"https://api.github.com/users/thirstycrow/events{/privacy}","received_events_url":"https://api.github.com/users/thirstycrow/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-08T15:11:55Z","updated_at":"2015-12-09T05:51:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0d8d5bbe38829723bb6997d4add66b0fa4fe8ce3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/twitter/finagle/pulls/447/commits","review_comments_url":"https://api.github.com/repos/twitter/finagle/pulls/447/comments","review_comment_url":"https://api.github.com/repos/twitter/finagle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/twitter/finagle/issues/447/comments","statuses_url":"https://api.github.com/repos/twitter/finagle/statuses/f4e6fffe3fc5a09d4ffc8b9c5c05e25bc9dce191","head":{"label":"thirstycrow:pubsub-support","ref":"pubsub-support","sha":"f4e6fffe3fc5a09d4ffc8b9c5c05e25bc9dce191","user":{"login":"thirstycrow","id":1327305,"avatar_url":"https://avatars.githubusercontent.com/u/1327305?v=3","gravatar_id":"","url":"https://api.github.com/users/thirstycrow","html_url":"https://github.com/thirstycrow","followers_url":"https://api.github.com/users/thirstycrow/followers","following_url":"https://api.github.com/users/thirstycrow/following{/other_user}","gists_url":"https://api.github.com/users/thirstycrow/gists{/gist_id}","starred_url":"https://api.github.com/users/thirstycrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thirstycrow/subscriptions","organizations_url":"https://api.github.com/users/thirstycrow/orgs","repos_url":"https://api.github.com/users/thirstycrow/repos","events_url":"https://api.github.com/users/thirstycrow/events{/privacy}","received_events_url":"https://api.github.com/users/thirstycrow/received_events","type":"User","site_admin":false},"repo":{"id":21188045,"name":"finagle","full_name":"thirstycrow/finagle","owner":{"login":"thirstycrow","id":1327305,"avatar_url":"https://avatars.githubusercontent.com/u/1327305?v=3","gravatar_id":"","url":"https://api.github.com/users/thirstycrow","html_url":"https://github.com/thirstycrow","followers_url":"https://api.github.com/users/thirstycrow/followers","following_url":"https://api.github.com/users/thirstycrow/following{/other_user}","gists_url":"https://api.github.com/users/thirstycrow/gists{/gist_id}","starred_url":"https://api.github.com/users/thirstycrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thirstycrow/subscriptions","organizations_url":"https://api.github.com/users/thirstycrow/orgs","repos_url":"https://api.github.com/users/thirstycrow/repos","events_url":"https://api.github.com/users/thirstycrow/events{/privacy}","received_events_url":"https://api.github.com/users/thirstycrow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/thirstycrow/finagle","description":"A fault tolerant, protocol-agnostic RPC system","fork":true,"url":"https://api.github.com/repos/thirstycrow/finagle","forks_url":"https://api.github.com/repos/thirstycrow/finagle/forks","keys_url":"https://api.github.com/repos/thirstycrow/finagle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thirstycrow/finagle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thirstycrow/finagle/teams","hooks_url":"https://api.github.com/repos/thirstycrow/finagle/hooks","issue_events_url":"https://api.github.com/repos/thirstycrow/finagle/issues/events{/number}","events_url":"https://api.github.com/repos/thirstycrow/finagle/events","assignees_url":"https://api.github.com/repos/thirstycrow/finagle/assignees{/user}","branches_url":"https://api.github.com/repos/thirstycrow/finagle/branches{/branch}","tags_url":"https://api.github.com/repos/thirstycrow/finagle/tags","blobs_url":"https://api.github.com/repos/thirstycrow/finagle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thirstycrow/finagle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thirstycrow/finagle/git/refs{/sha}","trees_url":"https://api.github.com/repos/thirstycrow/finagle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thirstycrow/finagle/statuses/{sha}","languages_url":"https://api.github.com/repos/thirstycrow/finagle/languages","stargazers_url":"https://api.github.com/repos/thirstycrow/finagle/stargazers","contributors_url":"https://api.github.com/repos/thirstycrow/finagle/contributors","subscribers_url":"https://api.github.com/repos/thirstycrow/finagle/subscribers","subscription_url":"https://api.github.com/repos/thirstycrow/finagle/subscription","commits_url":"https://api.github.com/repos/thirstycrow/finagle/commits{/sha}","git_commits_url":"https://api.github.com/repos/thirstycrow/finagle/git/commits{/sha}","comments_url":"https://api.github.com/repos/thirstycrow/finagle/comments{/number}","issue_comment_url":"https://api.github.com/repos/thirstycrow/finagle/issues/comments{/number}","contents_url":"https://api.github.com/repos/thirstycrow/finagle/contents/{+path}","compare_url":"https://api.github.com/repos/thirstycrow/finagle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thirstycrow/finagle/merges","archive_url":"https://api.github.com/repos/thirstycrow/finagle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thirstycrow/finagle/downloads","issues_url":"https://api.github.com/repos/thirstycrow/finagle/issues{/number}","pulls_url":"https://api.github.com/repos/thirstycrow/finagle/pulls{/number}","milestones_url":"https://api.github.com/repos/thirstycrow/finagle/milestones{/number}","notifications_url":"https://api.github.com/repos/thirstycrow/finagle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thirstycrow/finagle/labels{/name}","releases_url":"https://api.github.com/repos/thirstycrow/finagle/releases{/id}","created_at":"2014-06-25T02:47:30Z","updated_at":"2015-07-02T15:32:00Z","pushed_at":"2015-12-09T04:59:51Z","git_url":"git://github.com/thirstycrow/finagle.git","ssh_url":"git@github.com:thirstycrow/finagle.git","clone_url":"https://github.com/thirstycrow/finagle.git","svn_url":"https://github.com/thirstycrow/finagle","homepage":"http://twitter.github.io/finagle","size":24397,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"twitter:develop","ref":"develop","sha":"36ef5ea7d1b84bdbe7b343a1c1ac9131c0468b20","user":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=3","gravatar_id":"","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?v=3","gravatar_id":"","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":"2015-12-08T17:47:26Z","pushed_at":"2015-12-09T04:59:51Z","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":36524,"stargazers_count":4053,"watchers_count":4053,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":787,"mirror_url":null,"open_issues_count":44,"forks":787,"open_issues":44,"watchers":4053,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/twitter/finagle/pulls/447"},"html":{"href":"https://github.com/twitter/finagle/pull/447"},"issue":{"href":"https://api.github.com/repos/twitter/finagle/issues/447"},"comments":{"href":"https://api.github.com/repos/twitter/finagle/issues/447/comments"},"review_comments":{"href":"https://api.github.com/repos/twitter/finagle/pulls/447/comments"},"review_comment":{"href":"https://api.github.com/repos/twitter/finagle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/twitter/finagle/pulls/447/commits"},"statuses":{"href":"https://api.github.com/repos/twitter/finagle/statuses/f4e6fffe3fc5a09d4ffc8b9c5c05e25bc9dce191"}}}}