{"action":"created","comment":{"url":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/comments/62122425","id":62122425,"diff_hunk":"@@ -0,0 +1,80 @@\n+package io.buoyant.namerd.iface\n+\n+import com.google.common.cache.{CacheBuilder, RemovalListener, RemovalNotification}\n+import com.twitter.util.{Return, Throw, Try}\n+import io.buoyant.namerd.iface.ThriftNamerInterface.Observer\n+import java.util.concurrent.{Callable, ConcurrentHashMap}\n+\n+class MaximumObservationsReached(maxObservations: Int)\n+  extends Exception(s\"The maximum number of concurrent observations has been reached ($maxObservations)\")\n+\n+/**\n+ * A cache for Observer[T].  ObserverCache contains two levels of caching: active and inactive.\n+ *\n+ * The active cache is for Observers that have current outstanding requests against them.\n+ * Therefore, any Observer in the active cache must not be closed as this would cause the\n+ * outstanding requests to hang.\n+ *\n+ * The inactive cache is for Observers without outstanding requests against them.  These Observers\n+ * are kept open while in the inactive cache in case they receive a request and need to be moved\n+ * to the active cache.  The inactive cache has LRU eviction and Observers are closed upon\n+ * eviction.  Since Observers in the inactive cache have no outstanding requests against them,\n+ * this is safe to do.\n+ *\n+ * When get is called, the Observer for that key is moved to the active cache if it exists or\n+ * created and placed in the active cache if it does not exist.  When the value of an Observer\n+ * in the active cache changes, the Observer is moved to the inactive cache.  If the inactive\n+ * cache is full at that time, an older inactive Observer will be evicted.\n+ *\n+ * @param activeCapacity The maximum size of the active cache.  If get would cause the active cache\n+ *                       to exceed this size, a MaximumObservationsReached exception is returned\n+ *                       instead.\n+ * @param inactiveCapacity The maximum size of the inactive cache.  LRU eviction is used to\n+ *                         maintain this constraint.\n+ * @param mkObserver The function to use to create new Observers if they are not in either cache.\n+ */\n+class ObserverCache[K <: AnyRef, T](activeCapacity: Int = 100, inactiveCapacity: Int = 10)(mkObserver: K => Observer[T]) {","path":"namerd/iface/interpreter-thrift/src/main/scala/io/buoyant/namerd/iface/ObserverCache.scala","position":36,"original_position":36,"commit_id":"1f79e3109cbea891fa4b97f9f44bc89d7d09c028","original_commit_id":"1f79e3109cbea891fa4b97f9f44bc89d7d09c028","user":{"login":"adleong","id":3979810,"avatar_url":"https://avatars.githubusercontent.com/u/3979810?v=3","gravatar_id":"","url":"https://api.github.com/users/adleong","html_url":"https://github.com/adleong","followers_url":"https://api.github.com/users/adleong/followers","following_url":"https://api.github.com/users/adleong/following{/other_user}","gists_url":"https://api.github.com/users/adleong/gists{/gist_id}","starred_url":"https://api.github.com/users/adleong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adleong/subscriptions","organizations_url":"https://api.github.com/users/adleong/orgs","repos_url":"https://api.github.com/users/adleong/repos","events_url":"https://api.github.com/users/adleong/events{/privacy}","received_events_url":"https://api.github.com/users/adleong/received_events","type":"User","site_admin":false},"body":"yup, good idea","created_at":"2016-05-04T22:00:57Z","updated_at":"2016-05-04T22:00:57Z","html_url":"https://github.com/BuoyantIO/linkerd/pull/353#discussion_r62122425","pull_request_url":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/353","_links":{"self":{"href":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/comments/62122425"},"html":{"href":"https://github.com/BuoyantIO/linkerd/pull/353#discussion_r62122425"},"pull_request":{"href":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/353"}}},"pull_request":{"url":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/353","id":68439680,"html_url":"https://github.com/BuoyantIO/linkerd/pull/353","diff_url":"https://github.com/BuoyantIO/linkerd/pull/353.diff","patch_url":"https://github.com/BuoyantIO/linkerd/pull/353.patch","issue_url":"https://api.github.com/repos/BuoyantIO/linkerd/issues/353","number":353,"state":"open","locked":false,"title":"[RFC] Introduce ObserverCache","user":{"login":"adleong","id":3979810,"avatar_url":"https://avatars.githubusercontent.com/u/3979810?v=3","gravatar_id":"","url":"https://api.github.com/users/adleong","html_url":"https://github.com/adleong","followers_url":"https://api.github.com/users/adleong/followers","following_url":"https://api.github.com/users/adleong/following{/other_user}","gists_url":"https://api.github.com/users/adleong/gists{/gist_id}","starred_url":"https://api.github.com/users/adleong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adleong/subscriptions","organizations_url":"https://api.github.com/users/adleong/orgs","repos_url":"https://api.github.com/users/adleong/repos","events_url":"https://api.github.com/users/adleong/events{/privacy}","received_events_url":"https://api.github.com/users/adleong/received_events","type":"User","site_admin":false},"body":"Introduce ObserverCache for caching stamping observers.  ObserverCache contains two levels of caching: active and inactive.\r\n\r\nThe active cache is for Observers that have current outstanding requests against them.\r\nTherefore, any Observer in the active cache must not be closed as this would cause the\r\noutstanding requests to hang.\r\n\r\nThe inactive cache is for Observers without outstanding requests against them.  These Observers\r\nare kept open while in the inactive cache in case they receive a request and need to be moved\r\nto the active cache.  The inactive cache has LRU eviction and Observers are closed upon\r\neviction.  Since Observers in the inactive cache have no outstanding requests against them,\r\nthis is safe to do.\r\n\r\nWhen get is called, the Observer for that key is moved to the active cache if it exists or\r\ncreated and placed in the active cache if it does not exist.  When the value of an Observer\r\nin the active cache changes, the Observer is moved to the inactive cache.  If the inactive\r\ncache is full at that time, an older inactive Observer will be evicted.","created_at":"2016-04-29T21:56:26Z","updated_at":"2016-05-04T22:00:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4ba81042a75d95d46495e307a5653db2c4e8a900","assignee":{"login":"adleong","id":3979810,"avatar_url":"https://avatars.githubusercontent.com/u/3979810?v=3","gravatar_id":"","url":"https://api.github.com/users/adleong","html_url":"https://github.com/adleong","followers_url":"https://api.github.com/users/adleong/followers","following_url":"https://api.github.com/users/adleong/following{/other_user}","gists_url":"https://api.github.com/users/adleong/gists{/gist_id}","starred_url":"https://api.github.com/users/adleong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adleong/subscriptions","organizations_url":"https://api.github.com/users/adleong/orgs","repos_url":"https://api.github.com/users/adleong/repos","events_url":"https://api.github.com/users/adleong/events{/privacy}","received_events_url":"https://api.github.com/users/adleong/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/353/commits","review_comments_url":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/353/comments","review_comment_url":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/BuoyantIO/linkerd/issues/353/comments","statuses_url":"https://api.github.com/repos/BuoyantIO/linkerd/statuses/1f79e3109cbea891fa4b97f9f44bc89d7d09c028","head":{"label":"BuoyantIO:alex/obs-cache","ref":"alex/obs-cache","sha":"1f79e3109cbea891fa4b97f9f44bc89d7d09c028","user":{"login":"BuoyantIO","id":10824329,"avatar_url":"https://avatars.githubusercontent.com/u/10824329?v=3","gravatar_id":"","url":"https://api.github.com/users/BuoyantIO","html_url":"https://github.com/BuoyantIO","followers_url":"https://api.github.com/users/BuoyantIO/followers","following_url":"https://api.github.com/users/BuoyantIO/following{/other_user}","gists_url":"https://api.github.com/users/BuoyantIO/gists{/gist_id}","starred_url":"https://api.github.com/users/BuoyantIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BuoyantIO/subscriptions","organizations_url":"https://api.github.com/users/BuoyantIO/orgs","repos_url":"https://api.github.com/users/BuoyantIO/repos","events_url":"https://api.github.com/users/BuoyantIO/events{/privacy}","received_events_url":"https://api.github.com/users/BuoyantIO/received_events","type":"Organization","site_admin":false},"repo":{"id":49605596,"name":"linkerd","full_name":"BuoyantIO/linkerd","owner":{"login":"BuoyantIO","id":10824329,"avatar_url":"https://avatars.githubusercontent.com/u/10824329?v=3","gravatar_id":"","url":"https://api.github.com/users/BuoyantIO","html_url":"https://github.com/BuoyantIO","followers_url":"https://api.github.com/users/BuoyantIO/followers","following_url":"https://api.github.com/users/BuoyantIO/following{/other_user}","gists_url":"https://api.github.com/users/BuoyantIO/gists{/gist_id}","starred_url":"https://api.github.com/users/BuoyantIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BuoyantIO/subscriptions","organizations_url":"https://api.github.com/users/BuoyantIO/orgs","repos_url":"https://api.github.com/users/BuoyantIO/repos","events_url":"https://api.github.com/users/BuoyantIO/events{/privacy}","received_events_url":"https://api.github.com/users/BuoyantIO/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BuoyantIO/linkerd","description":"A dynamic linker for microservices.","fork":false,"url":"https://api.github.com/repos/BuoyantIO/linkerd","forks_url":"https://api.github.com/repos/BuoyantIO/linkerd/forks","keys_url":"https://api.github.com/repos/BuoyantIO/linkerd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BuoyantIO/linkerd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BuoyantIO/linkerd/teams","hooks_url":"https://api.github.com/repos/BuoyantIO/linkerd/hooks","issue_events_url":"https://api.github.com/repos/BuoyantIO/linkerd/issues/events{/number}","events_url":"https://api.github.com/repos/BuoyantIO/linkerd/events","assignees_url":"https://api.github.com/repos/BuoyantIO/linkerd/assignees{/user}","branches_url":"https://api.github.com/repos/BuoyantIO/linkerd/branches{/branch}","tags_url":"https://api.github.com/repos/BuoyantIO/linkerd/tags","blobs_url":"https://api.github.com/repos/BuoyantIO/linkerd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BuoyantIO/linkerd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BuoyantIO/linkerd/git/refs{/sha}","trees_url":"https://api.github.com/repos/BuoyantIO/linkerd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BuoyantIO/linkerd/statuses/{sha}","languages_url":"https://api.github.com/repos/BuoyantIO/linkerd/languages","stargazers_url":"https://api.github.com/repos/BuoyantIO/linkerd/stargazers","contributors_url":"https://api.github.com/repos/BuoyantIO/linkerd/contributors","subscribers_url":"https://api.github.com/repos/BuoyantIO/linkerd/subscribers","subscription_url":"https://api.github.com/repos/BuoyantIO/linkerd/subscription","commits_url":"https://api.github.com/repos/BuoyantIO/linkerd/commits{/sha}","git_commits_url":"https://api.github.com/repos/BuoyantIO/linkerd/git/commits{/sha}","comments_url":"https://api.github.com/repos/BuoyantIO/linkerd/comments{/number}","issue_comment_url":"https://api.github.com/repos/BuoyantIO/linkerd/issues/comments{/number}","contents_url":"https://api.github.com/repos/BuoyantIO/linkerd/contents/{+path}","compare_url":"https://api.github.com/repos/BuoyantIO/linkerd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BuoyantIO/linkerd/merges","archive_url":"https://api.github.com/repos/BuoyantIO/linkerd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BuoyantIO/linkerd/downloads","issues_url":"https://api.github.com/repos/BuoyantIO/linkerd/issues{/number}","pulls_url":"https://api.github.com/repos/BuoyantIO/linkerd/pulls{/number}","milestones_url":"https://api.github.com/repos/BuoyantIO/linkerd/milestones{/number}","notifications_url":"https://api.github.com/repos/BuoyantIO/linkerd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BuoyantIO/linkerd/labels{/name}","releases_url":"https://api.github.com/repos/BuoyantIO/linkerd/releases{/id}","deployments_url":"https://api.github.com/repos/BuoyantIO/linkerd/deployments","created_at":"2016-01-13T22:14:52Z","updated_at":"2016-05-04T03:14:32Z","pushed_at":"2016-05-04T18:25:26Z","git_url":"git://github.com/BuoyantIO/linkerd.git","ssh_url":"git@github.com:BuoyantIO/linkerd.git","clone_url":"https://github.com/BuoyantIO/linkerd.git","svn_url":"https://github.com/BuoyantIO/linkerd","homepage":"https://linkerd.io","size":1424,"stargazers_count":599,"watchers_count":599,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":29,"mirror_url":null,"open_issues_count":56,"forks":29,"open_issues":56,"watchers":599,"default_branch":"master"}},"base":{"label":"BuoyantIO:master","ref":"master","sha":"8995e9b0192572a3f893af49ff62c531bcded71b","user":{"login":"BuoyantIO","id":10824329,"avatar_url":"https://avatars.githubusercontent.com/u/10824329?v=3","gravatar_id":"","url":"https://api.github.com/users/BuoyantIO","html_url":"https://github.com/BuoyantIO","followers_url":"https://api.github.com/users/BuoyantIO/followers","following_url":"https://api.github.com/users/BuoyantIO/following{/other_user}","gists_url":"https://api.github.com/users/BuoyantIO/gists{/gist_id}","starred_url":"https://api.github.com/users/BuoyantIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BuoyantIO/subscriptions","organizations_url":"https://api.github.com/users/BuoyantIO/orgs","repos_url":"https://api.github.com/users/BuoyantIO/repos","events_url":"https://api.github.com/users/BuoyantIO/events{/privacy}","received_events_url":"https://api.github.com/users/BuoyantIO/received_events","type":"Organization","site_admin":false},"repo":{"id":49605596,"name":"linkerd","full_name":"BuoyantIO/linkerd","owner":{"login":"BuoyantIO","id":10824329,"avatar_url":"https://avatars.githubusercontent.com/u/10824329?v=3","gravatar_id":"","url":"https://api.github.com/users/BuoyantIO","html_url":"https://github.com/BuoyantIO","followers_url":"https://api.github.com/users/BuoyantIO/followers","following_url":"https://api.github.com/users/BuoyantIO/following{/other_user}","gists_url":"https://api.github.com/users/BuoyantIO/gists{/gist_id}","starred_url":"https://api.github.com/users/BuoyantIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BuoyantIO/subscriptions","organizations_url":"https://api.github.com/users/BuoyantIO/orgs","repos_url":"https://api.github.com/users/BuoyantIO/repos","events_url":"https://api.github.com/users/BuoyantIO/events{/privacy}","received_events_url":"https://api.github.com/users/BuoyantIO/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BuoyantIO/linkerd","description":"A dynamic linker for microservices.","fork":false,"url":"https://api.github.com/repos/BuoyantIO/linkerd","forks_url":"https://api.github.com/repos/BuoyantIO/linkerd/forks","keys_url":"https://api.github.com/repos/BuoyantIO/linkerd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BuoyantIO/linkerd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BuoyantIO/linkerd/teams","hooks_url":"https://api.github.com/repos/BuoyantIO/linkerd/hooks","issue_events_url":"https://api.github.com/repos/BuoyantIO/linkerd/issues/events{/number}","events_url":"https://api.github.com/repos/BuoyantIO/linkerd/events","assignees_url":"https://api.github.com/repos/BuoyantIO/linkerd/assignees{/user}","branches_url":"https://api.github.com/repos/BuoyantIO/linkerd/branches{/branch}","tags_url":"https://api.github.com/repos/BuoyantIO/linkerd/tags","blobs_url":"https://api.github.com/repos/BuoyantIO/linkerd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BuoyantIO/linkerd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BuoyantIO/linkerd/git/refs{/sha}","trees_url":"https://api.github.com/repos/BuoyantIO/linkerd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BuoyantIO/linkerd/statuses/{sha}","languages_url":"https://api.github.com/repos/BuoyantIO/linkerd/languages","stargazers_url":"https://api.github.com/repos/BuoyantIO/linkerd/stargazers","contributors_url":"https://api.github.com/repos/BuoyantIO/linkerd/contributors","subscribers_url":"https://api.github.com/repos/BuoyantIO/linkerd/subscribers","subscription_url":"https://api.github.com/repos/BuoyantIO/linkerd/subscription","commits_url":"https://api.github.com/repos/BuoyantIO/linkerd/commits{/sha}","git_commits_url":"https://api.github.com/repos/BuoyantIO/linkerd/git/commits{/sha}","comments_url":"https://api.github.com/repos/BuoyantIO/linkerd/comments{/number}","issue_comment_url":"https://api.github.com/repos/BuoyantIO/linkerd/issues/comments{/number}","contents_url":"https://api.github.com/repos/BuoyantIO/linkerd/contents/{+path}","compare_url":"https://api.github.com/repos/BuoyantIO/linkerd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BuoyantIO/linkerd/merges","archive_url":"https://api.github.com/repos/BuoyantIO/linkerd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BuoyantIO/linkerd/downloads","issues_url":"https://api.github.com/repos/BuoyantIO/linkerd/issues{/number}","pulls_url":"https://api.github.com/repos/BuoyantIO/linkerd/pulls{/number}","milestones_url":"https://api.github.com/repos/BuoyantIO/linkerd/milestones{/number}","notifications_url":"https://api.github.com/repos/BuoyantIO/linkerd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BuoyantIO/linkerd/labels{/name}","releases_url":"https://api.github.com/repos/BuoyantIO/linkerd/releases{/id}","deployments_url":"https://api.github.com/repos/BuoyantIO/linkerd/deployments","created_at":"2016-01-13T22:14:52Z","updated_at":"2016-05-04T03:14:32Z","pushed_at":"2016-05-04T18:25:26Z","git_url":"git://github.com/BuoyantIO/linkerd.git","ssh_url":"git@github.com:BuoyantIO/linkerd.git","clone_url":"https://github.com/BuoyantIO/linkerd.git","svn_url":"https://github.com/BuoyantIO/linkerd","homepage":"https://linkerd.io","size":1424,"stargazers_count":599,"watchers_count":599,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":29,"mirror_url":null,"open_issues_count":56,"forks":29,"open_issues":56,"watchers":599,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/353"},"html":{"href":"https://github.com/BuoyantIO/linkerd/pull/353"},"issue":{"href":"https://api.github.com/repos/BuoyantIO/linkerd/issues/353"},"comments":{"href":"https://api.github.com/repos/BuoyantIO/linkerd/issues/353/comments"},"review_comments":{"href":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/353/comments"},"review_comment":{"href":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/BuoyantIO/linkerd/pulls/353/commits"},"statuses":{"href":"https://api.github.com/repos/BuoyantIO/linkerd/statuses/1f79e3109cbea891fa4b97f9f44bc89d7d09c028"}}}}