{"action":"created","comment":{"url":"https://api.github.com/repos/datastax/java-driver/pulls/comments/36878905","id":36878905,"diff_hunk":"@@ -2282,6 +2289,234 @@ public void run() {\n                 }\n             }\n         }\n+\n+        private class SchemaRefreshRequest {\n+\n+            private final String keyspace;\n+\n+            private final String table;\n+\n+            SchemaRefreshRequest(String keyspace, String table) {\n+                this.keyspace = keyspace;\n+                this.table = table;\n+            }\n+\n+            /**\n+             * Coalesce schema refresh requests.\n+             * The algorithm is simple: if more than 2 keyspaces\n+             * need refresh, then refresh the entire schema;\n+             * otherwise if more than 2 tables in the same keyspace\n+             * need refresh, then refresh the entire keyspace.\n+             *\n+             * @param that the other request to merge with the current one.\n+             * @return A coalesced request\n+             */\n+            SchemaRefreshRequest coalesce(SchemaRefreshRequest that) {\n+                if(this.keyspace == null || that.keyspace == null)\n+                    return new SchemaRefreshRequest(null, null);\n+                if(!this.keyspace.equals(that.keyspace))\n+                    return new SchemaRefreshRequest(null, null);\n+                if(this.table == null || that.table == null)\n+                    return new SchemaRefreshRequest(keyspace, null);\n+                if(!this.table.equals(that.table))\n+                    return new SchemaRefreshRequest(keyspace, null);\n+                return this;\n+            }\n+\n+            @Override\n+            public String toString() {\n+                if(this.keyspace == null)\n+                    return \"Refresh ALL\";\n+                if(this.table == null)\n+                    return \"Refresh keyspace \" + keyspace;\n+                return \"Refresh keyspace \" + keyspace + \" table \" + table;\n+            }\n+        }\n+\n+        private class SchemaRefreshRequestDeliveryCallback implements EventDebouncer.DeliveryCallback<SchemaRefreshRequest> {\n+\n+            @Override\n+            public ListenableFuture<?> deliver(final List<SchemaRefreshRequest> events) {\n+                return executor.submit(new ExceptionCatchingRunnable() {\n+                    @Override\n+                    public void runMayThrow() throws InterruptedException, ExecutionException {\n+                        SchemaRefreshRequest coalesced = null;\n+                        for (SchemaRefreshRequest request : events) {\n+                            coalesced = coalesced == null ? request : coalesced.coalesce(request);\n+                        }\n+                        assert coalesced != null;\n+                        logger.trace(\"Coalesced schema refresh request: {}\", coalesced);\n+                        controlConnection.refreshSchema(coalesced.keyspace, coalesced.table);\n+                    }\n+                });\n+            }\n+\n+        }\n+\n+        private class NodeRefreshRequest {\n+\n+            private final Host host;\n+\n+            private final HostEvent eventType;\n+\n+            private NodeRefreshRequest(Host host, HostEvent eventType) {\n+                this.host = host;\n+                this.eventType = eventType;\n+            }\n+\n+            @Override\n+            public String toString() {\n+                return host + \" \" + eventType;\n+            }\n+\n+        }\n+\n+        private class NodeRefreshRequestDeliveryCallback implements EventDebouncer.DeliveryCallback<NodeRefreshRequest> {\n+\n+            @Override\n+            public ListenableFuture<?> deliver(List<NodeRefreshRequest> events) {\n+                Map<Host, HostEvent> hosts = new HashMap<Host, HostEvent>();\n+                // only keep the last event for each host\n+                for (NodeRefreshRequest req : events) {\n+                    hosts.put(req.host, req.eventType);\n+                }\n+                List<ListenableFuture<?>> futures = new ArrayList<ListenableFuture<?>>(hosts.size());\n+                for (final Entry<Host, HostEvent> entry : hosts.entrySet()) {\n+                    final Host host = entry.getKey();\n+                    HostEvent eventType = entry.getValue();\n+                    switch (eventType) {\n+                        case UP:\n+                            schedule(hostUp(host));","path":"driver-core/src/main/java/com/datastax/driver/core/Cluster.java","position":null,"original_position":333,"commit_id":"3f09d00a3e093f73710757162236a543f5d547c5","original_commit_id":"67cc8b96c69e6a4fdbe4b64c02cf9540cd96b92a","user":{"login":"tolbertam","id":6889771,"avatar_url":"https://avatars.githubusercontent.com/u/6889771?v=3","gravatar_id":"","url":"https://api.github.com/users/tolbertam","html_url":"https://github.com/tolbertam","followers_url":"https://api.github.com/users/tolbertam/followers","following_url":"https://api.github.com/users/tolbertam/following{/other_user}","gists_url":"https://api.github.com/users/tolbertam/gists{/gist_id}","starred_url":"https://api.github.com/users/tolbertam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tolbertam/subscriptions","organizations_url":"https://api.github.com/users/tolbertam/orgs","repos_url":"https://api.github.com/users/tolbertam/repos","events_url":"https://api.github.com/users/tolbertam/events{/privacy}","received_events_url":"https://api.github.com/users/tolbertam/received_events","type":"User","site_admin":false},"body":"Excellent, thanks for the explanation about UP being delayed.   The changes look good so far, will play around a bit and see how it goes :)","created_at":"2015-08-12T16:10:44Z","updated_at":"2015-08-12T16:10:44Z","html_url":"https://github.com/datastax/java-driver/pull/406#discussion_r36878905","pull_request_url":"https://api.github.com/repos/datastax/java-driver/pulls/406","_links":{"self":{"href":"https://api.github.com/repos/datastax/java-driver/pulls/comments/36878905"},"html":{"href":"https://github.com/datastax/java-driver/pull/406#discussion_r36878905"},"pull_request":{"href":"https://api.github.com/repos/datastax/java-driver/pulls/406"}}},"pull_request":{"url":"https://api.github.com/repos/datastax/java-driver/pulls/406","id":39817568,"html_url":"https://github.com/datastax/java-driver/pull/406","diff_url":"https://github.com/datastax/java-driver/pull/406.diff","patch_url":"https://github.com/datastax/java-driver/pull/406.patch","issue_url":"https://api.github.com/repos/datastax/java-driver/issues/406","number":406,"state":"open","locked":false,"title":"JAVA-657: Debounce control connection queries.","user":{"login":"adutra","id":463876,"avatar_url":"https://avatars.githubusercontent.com/u/463876?v=3","gravatar_id":"","url":"https://api.github.com/users/adutra","html_url":"https://github.com/adutra","followers_url":"https://api.github.com/users/adutra/followers","following_url":"https://api.github.com/users/adutra/following{/other_user}","gists_url":"https://api.github.com/users/adutra/gists{/gist_id}","starred_url":"https://api.github.com/users/adutra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adutra/subscriptions","organizations_url":"https://api.github.com/users/adutra/orgs","repos_url":"https://api.github.com/users/adutra/repos","events_url":"https://api.github.com/users/adutra/events{/privacy}","received_events_url":"https://api.github.com/users/adutra/received_events","type":"User","site_admin":false},"body":"Also contains a fix for JAVA-784.","created_at":"2015-07-13T14:30:22Z","updated_at":"2015-08-12T16:10:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f89ca67f116a40493e820ef807a005c0a55aed86","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/datastax/java-driver/pulls/406/commits","review_comments_url":"https://api.github.com/repos/datastax/java-driver/pulls/406/comments","review_comment_url":"https://api.github.com/repos/datastax/java-driver/pulls/comments{/number}","comments_url":"https://api.github.com/repos/datastax/java-driver/issues/406/comments","statuses_url":"https://api.github.com/repos/datastax/java-driver/statuses/3f09d00a3e093f73710757162236a543f5d547c5","head":{"label":"datastax:java657","ref":"java657","sha":"3f09d00a3e093f73710757162236a543f5d547c5","user":{"login":"datastax","id":573369,"avatar_url":"https://avatars.githubusercontent.com/u/573369?v=3","gravatar_id":"","url":"https://api.github.com/users/datastax","html_url":"https://github.com/datastax","followers_url":"https://api.github.com/users/datastax/followers","following_url":"https://api.github.com/users/datastax/following{/other_user}","gists_url":"https://api.github.com/users/datastax/gists{/gist_id}","starred_url":"https://api.github.com/users/datastax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datastax/subscriptions","organizations_url":"https://api.github.com/users/datastax/orgs","repos_url":"https://api.github.com/users/datastax/repos","events_url":"https://api.github.com/users/datastax/events{/privacy}","received_events_url":"https://api.github.com/users/datastax/received_events","type":"Organization","site_admin":false},"repo":{"id":6765281,"name":"java-driver","full_name":"datastax/java-driver","owner":{"login":"datastax","id":573369,"avatar_url":"https://avatars.githubusercontent.com/u/573369?v=3","gravatar_id":"","url":"https://api.github.com/users/datastax","html_url":"https://github.com/datastax","followers_url":"https://api.github.com/users/datastax/followers","following_url":"https://api.github.com/users/datastax/following{/other_user}","gists_url":"https://api.github.com/users/datastax/gists{/gist_id}","starred_url":"https://api.github.com/users/datastax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datastax/subscriptions","organizations_url":"https://api.github.com/users/datastax/orgs","repos_url":"https://api.github.com/users/datastax/repos","events_url":"https://api.github.com/users/datastax/events{/privacy}","received_events_url":"https://api.github.com/users/datastax/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/datastax/java-driver","description":"DataStax Java Driver for Apache Cassandra","fork":false,"url":"https://api.github.com/repos/datastax/java-driver","forks_url":"https://api.github.com/repos/datastax/java-driver/forks","keys_url":"https://api.github.com/repos/datastax/java-driver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/datastax/java-driver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/datastax/java-driver/teams","hooks_url":"https://api.github.com/repos/datastax/java-driver/hooks","issue_events_url":"https://api.github.com/repos/datastax/java-driver/issues/events{/number}","events_url":"https://api.github.com/repos/datastax/java-driver/events","assignees_url":"https://api.github.com/repos/datastax/java-driver/assignees{/user}","branches_url":"https://api.github.com/repos/datastax/java-driver/branches{/branch}","tags_url":"https://api.github.com/repos/datastax/java-driver/tags","blobs_url":"https://api.github.com/repos/datastax/java-driver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/datastax/java-driver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/datastax/java-driver/git/refs{/sha}","trees_url":"https://api.github.com/repos/datastax/java-driver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/datastax/java-driver/statuses/{sha}","languages_url":"https://api.github.com/repos/datastax/java-driver/languages","stargazers_url":"https://api.github.com/repos/datastax/java-driver/stargazers","contributors_url":"https://api.github.com/repos/datastax/java-driver/contributors","subscribers_url":"https://api.github.com/repos/datastax/java-driver/subscribers","subscription_url":"https://api.github.com/repos/datastax/java-driver/subscription","commits_url":"https://api.github.com/repos/datastax/java-driver/commits{/sha}","git_commits_url":"https://api.github.com/repos/datastax/java-driver/git/commits{/sha}","comments_url":"https://api.github.com/repos/datastax/java-driver/comments{/number}","issue_comment_url":"https://api.github.com/repos/datastax/java-driver/issues/comments{/number}","contents_url":"https://api.github.com/repos/datastax/java-driver/contents/{+path}","compare_url":"https://api.github.com/repos/datastax/java-driver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/datastax/java-driver/merges","archive_url":"https://api.github.com/repos/datastax/java-driver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/datastax/java-driver/downloads","issues_url":"https://api.github.com/repos/datastax/java-driver/issues{/number}","pulls_url":"https://api.github.com/repos/datastax/java-driver/pulls{/number}","milestones_url":"https://api.github.com/repos/datastax/java-driver/milestones{/number}","notifications_url":"https://api.github.com/repos/datastax/java-driver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/datastax/java-driver/labels{/name}","releases_url":"https://api.github.com/repos/datastax/java-driver/releases{/id}","created_at":"2012-11-19T18:44:41Z","updated_at":"2015-08-10T16:47:37Z","pushed_at":"2015-08-12T10:32:23Z","git_url":"git://github.com/datastax/java-driver.git","ssh_url":"git@github.com:datastax/java-driver.git","clone_url":"https://github.com/datastax/java-driver.git","svn_url":"https://github.com/datastax/java-driver","homepage":null,"size":23798,"stargazers_count":492,"watchers_count":492,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":349,"mirror_url":null,"open_issues_count":29,"forks":349,"open_issues":29,"watchers":492,"default_branch":"2.1"}},"base":{"label":"datastax:2.0","ref":"2.0","sha":"2d7f93186e9d865aa4b094e6139563b1aba721ad","user":{"login":"datastax","id":573369,"avatar_url":"https://avatars.githubusercontent.com/u/573369?v=3","gravatar_id":"","url":"https://api.github.com/users/datastax","html_url":"https://github.com/datastax","followers_url":"https://api.github.com/users/datastax/followers","following_url":"https://api.github.com/users/datastax/following{/other_user}","gists_url":"https://api.github.com/users/datastax/gists{/gist_id}","starred_url":"https://api.github.com/users/datastax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datastax/subscriptions","organizations_url":"https://api.github.com/users/datastax/orgs","repos_url":"https://api.github.com/users/datastax/repos","events_url":"https://api.github.com/users/datastax/events{/privacy}","received_events_url":"https://api.github.com/users/datastax/received_events","type":"Organization","site_admin":false},"repo":{"id":6765281,"name":"java-driver","full_name":"datastax/java-driver","owner":{"login":"datastax","id":573369,"avatar_url":"https://avatars.githubusercontent.com/u/573369?v=3","gravatar_id":"","url":"https://api.github.com/users/datastax","html_url":"https://github.com/datastax","followers_url":"https://api.github.com/users/datastax/followers","following_url":"https://api.github.com/users/datastax/following{/other_user}","gists_url":"https://api.github.com/users/datastax/gists{/gist_id}","starred_url":"https://api.github.com/users/datastax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datastax/subscriptions","organizations_url":"https://api.github.com/users/datastax/orgs","repos_url":"https://api.github.com/users/datastax/repos","events_url":"https://api.github.com/users/datastax/events{/privacy}","received_events_url":"https://api.github.com/users/datastax/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/datastax/java-driver","description":"DataStax Java Driver for Apache Cassandra","fork":false,"url":"https://api.github.com/repos/datastax/java-driver","forks_url":"https://api.github.com/repos/datastax/java-driver/forks","keys_url":"https://api.github.com/repos/datastax/java-driver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/datastax/java-driver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/datastax/java-driver/teams","hooks_url":"https://api.github.com/repos/datastax/java-driver/hooks","issue_events_url":"https://api.github.com/repos/datastax/java-driver/issues/events{/number}","events_url":"https://api.github.com/repos/datastax/java-driver/events","assignees_url":"https://api.github.com/repos/datastax/java-driver/assignees{/user}","branches_url":"https://api.github.com/repos/datastax/java-driver/branches{/branch}","tags_url":"https://api.github.com/repos/datastax/java-driver/tags","blobs_url":"https://api.github.com/repos/datastax/java-driver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/datastax/java-driver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/datastax/java-driver/git/refs{/sha}","trees_url":"https://api.github.com/repos/datastax/java-driver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/datastax/java-driver/statuses/{sha}","languages_url":"https://api.github.com/repos/datastax/java-driver/languages","stargazers_url":"https://api.github.com/repos/datastax/java-driver/stargazers","contributors_url":"https://api.github.com/repos/datastax/java-driver/contributors","subscribers_url":"https://api.github.com/repos/datastax/java-driver/subscribers","subscription_url":"https://api.github.com/repos/datastax/java-driver/subscription","commits_url":"https://api.github.com/repos/datastax/java-driver/commits{/sha}","git_commits_url":"https://api.github.com/repos/datastax/java-driver/git/commits{/sha}","comments_url":"https://api.github.com/repos/datastax/java-driver/comments{/number}","issue_comment_url":"https://api.github.com/repos/datastax/java-driver/issues/comments{/number}","contents_url":"https://api.github.com/repos/datastax/java-driver/contents/{+path}","compare_url":"https://api.github.com/repos/datastax/java-driver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/datastax/java-driver/merges","archive_url":"https://api.github.com/repos/datastax/java-driver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/datastax/java-driver/downloads","issues_url":"https://api.github.com/repos/datastax/java-driver/issues{/number}","pulls_url":"https://api.github.com/repos/datastax/java-driver/pulls{/number}","milestones_url":"https://api.github.com/repos/datastax/java-driver/milestones{/number}","notifications_url":"https://api.github.com/repos/datastax/java-driver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/datastax/java-driver/labels{/name}","releases_url":"https://api.github.com/repos/datastax/java-driver/releases{/id}","created_at":"2012-11-19T18:44:41Z","updated_at":"2015-08-10T16:47:37Z","pushed_at":"2015-08-12T10:32:23Z","git_url":"git://github.com/datastax/java-driver.git","ssh_url":"git@github.com:datastax/java-driver.git","clone_url":"https://github.com/datastax/java-driver.git","svn_url":"https://github.com/datastax/java-driver","homepage":null,"size":23798,"stargazers_count":492,"watchers_count":492,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":349,"mirror_url":null,"open_issues_count":29,"forks":349,"open_issues":29,"watchers":492,"default_branch":"2.1"}},"_links":{"self":{"href":"https://api.github.com/repos/datastax/java-driver/pulls/406"},"html":{"href":"https://github.com/datastax/java-driver/pull/406"},"issue":{"href":"https://api.github.com/repos/datastax/java-driver/issues/406"},"comments":{"href":"https://api.github.com/repos/datastax/java-driver/issues/406/comments"},"review_comments":{"href":"https://api.github.com/repos/datastax/java-driver/pulls/406/comments"},"review_comment":{"href":"https://api.github.com/repos/datastax/java-driver/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/datastax/java-driver/pulls/406/commits"},"statuses":{"href":"https://api.github.com/repos/datastax/java-driver/statuses/3f09d00a3e093f73710757162236a543f5d547c5"}}}}