{"action":"created","comment":{"url":"https://api.github.com/repos/paypal/SeLion/pulls/comments/56918881","id":56918881,"diff_hunk":"@@ -0,0 +1,132 @@\n+/*-------------------------------------------------------------------------------------------------------------------*\\\n+|  Copyright (C) 2016 PayPal                                                                                          |\n+|                                                                                                                     |\n+|  Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance     |\n+|  with the License.                                                                                                  |\n+|                                                                                                                     |\n+|  You may obtain a copy of the License at                                                                            |\n+|                                                                                                                     |\n+|       http://www.apache.org/licenses/LICENSE-2.0                                                                    |\n+|                                                                                                                     |\n+|  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed   |\n+|  on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for  |\n+|  the specific language governing permissions and limitations under the License.                                     |\n+\\*-------------------------------------------------------------------------------------------------------------------*/\n+\n+package com.paypal.selion.pojos;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+import org.apache.commons.lang.StringUtils;\n+\n+import com.google.gson.Gson;\n+import com.paypal.selion.logging.SeLionGridLogger;\n+\n+/**\n+ * <code>BrowserStatisticsCollection</code> stores the all the supported browsers by the Grid and Nodes collectively. It\n+ * stores the maximum available instances of a particular browser in the Grid - Nodes farm along with the waiting\n+ * requests for a particular browser. This class is not thread safe, the clients are expected to create individual\n+ * instances of this class in separate threads.\n+ * \n+ */\n+public class BrowserStatisticsCollection {\n+\n+    private static final SeLionGridLogger logger = SeLionGridLogger.getLogger(BrowserStatisticsCollection.class);\n+\n+    private final List<BrowserStatistics> browserStatisticsList;\n+\n+    public BrowserStatisticsCollection() {\n+        browserStatisticsList = new ArrayList<BrowserStatistics>();\n+    }\n+\n+    /**\n+     * Sets the maximum instances for a particular browser. This call creates a unique statistics for the provided\n+     * browser name it does not exists.\n+     * \n+     * @param browserName\n+     *            Name of the browser.\n+     * @param maxBrowserInstances\n+     *            Maximum instances of the browser.\n+     */\n+    public void setMaxBrowserInstances(String browserName, int maxBrowserInstances) {\n+        logger.entering(new Object[] { browserName, maxBrowserInstances });\n+        validateBrowserName(browserName);\n+        BrowserStatistics lStatistics = createStatisticsIfNotPresent(browserName);\n+        lStatistics.setMaxBrowserInstances(maxBrowserInstances);\n+        logger.exiting();\n+    }\n+\n+    /**\n+     * Increments the waiting request for the provided browser name. This call creates a unique statistics for the\n+     * provided browser name it does not exists.\n+     * \n+     * @param browserName\n+     *            Name of the browser.\n+     */\n+    public void incrementWaitingRequests(String browserName) {\n+        logger.entering(browserName);\n+        validateBrowserName(browserName);\n+        BrowserStatistics lStatistics = createStatisticsIfNotPresent(browserName);\n+        lStatistics.incrementWaitingRequests();\n+        logger.exiting();\n+    }\n+\n+    private void validateBrowserName(String browserName) {\n+        if (StringUtils.isBlank(browserName)) {\n+            throw new IllegalArgumentException(\"Browser name cannot be null\");\n+        }\n+    }\n+\n+    private synchronized BrowserStatistics createStatisticsIfNotPresent(String browserName) {\n+        for (BrowserStatistics loadStatistics : this.browserStatisticsList) {\n+            if (loadStatistics.browserName.equals(browserName)) {\n+                return loadStatistics;\n+            }\n+        }\n+        BrowserStatistics loadStatistics = new BrowserStatistics(browserName);\n+        this.browserStatisticsList.add(loadStatistics);\n+        return loadStatistics;\n+    }\n+\n+    @Override\n+    public String toString() {\n+        Gson gson = new Gson();\n+        return gson.toJson(browserStatisticsList);\n+    }\n+\n+    /**\n+     * <code>BrowserStatistics</code> holds the statistics for an individual browser. This class acts as a mere Value\n+     * Object.\n+     * \n+     */\n+    private class BrowserStatistics {\n+\n+        private final String browserName;\n+\n+        private Statistics statistics;\n+\n+        public BrowserStatistics(String browserName) {\n+            this.browserName = browserName;\n+            this.statistics = new Statistics();\n+        }\n+\n+        public void setMaxBrowserInstances(int maxBrowserInstances) {\n+            this.statistics.maxBrowserInstances = maxBrowserInstances;\n+        }\n+\n+        public void incrementWaitingRequests() {\n+            ++this.statistics.waitingRequests;","path":"server/src/main/java/com/paypal/selion/pojos/BrowserStatisticsCollection.java","position":119,"original_position":119,"commit_id":"f380c659f0cdc36a2bf22ab210db9a53822d2260","original_commit_id":"f380c659f0cdc36a2bf22ab210db9a53822d2260","user":{"login":"mach6","id":3238999,"avatar_url":"https://avatars.githubusercontent.com/u/3238999?v=3","gravatar_id":"","url":"https://api.github.com/users/mach6","html_url":"https://github.com/mach6","followers_url":"https://api.github.com/users/mach6/followers","following_url":"https://api.github.com/users/mach6/following{/other_user}","gists_url":"https://api.github.com/users/mach6/gists{/gist_id}","starred_url":"https://api.github.com/users/mach6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mach6/subscriptions","organizations_url":"https://api.github.com/users/mach6/orgs","repos_url":"https://api.github.com/users/mach6/repos","events_url":"https://api.github.com/users/mach6/events{/privacy}","received_events_url":"https://api.github.com/users/mach6/received_events","type":"User","site_admin":false},"body":"please use `+= 1` vs this prefix form","created_at":"2016-03-22T00:05:36Z","updated_at":"2016-03-22T00:05:36Z","html_url":"https://github.com/paypal/SeLion/pull/251#discussion_r56918881","pull_request_url":"https://api.github.com/repos/paypal/SeLion/pulls/251","_links":{"self":{"href":"https://api.github.com/repos/paypal/SeLion/pulls/comments/56918881"},"html":{"href":"https://github.com/paypal/SeLion/pull/251#discussion_r56918881"},"pull_request":{"href":"https://api.github.com/repos/paypal/SeLion/pulls/251"}}},"pull_request":{"url":"https://api.github.com/repos/paypal/SeLion/pulls/251","id":60440652,"html_url":"https://github.com/paypal/SeLion/pull/251","diff_url":"https://github.com/paypal/SeLion/pull/251.diff","patch_url":"https://github.com/paypal/SeLion/pull/251.patch","issue_url":"https://api.github.com/repos/paypal/SeLion/issues/251","number":251,"state":"open","locked":false,"title":"Add browser load monitoring servlet","user":{"login":"mach6","id":3238999,"avatar_url":"https://avatars.githubusercontent.com/u/3238999?v=3","gravatar_id":"","url":"https://api.github.com/users/mach6","html_url":"https://github.com/mach6","followers_url":"https://api.github.com/users/mach6/followers","following_url":"https://api.github.com/users/mach6/following{/other_user}","gists_url":"https://api.github.com/users/mach6/gists{/gist_id}","starred_url":"https://api.github.com/users/mach6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mach6/subscriptions","organizations_url":"https://api.github.com/users/mach6/orgs","repos_url":"https://api.github.com/users/mach6/repos","events_url":"https://api.github.com/users/mach6/events{/privacy}","received_events_url":"https://api.github.com/users/mach6/received_events","type":"User","site_admin":false},"body":" * Add GridStatistics servlet to monitor browser load\r\n * Add maximum instances of every browser type in response\r\n * Add number of requests waiting on queue per browser type in response\r\n * Add support for JSON responses\r\n * Add supporting classes BrowserInformationCache and BrowserStatisticsCollection\r\n * Include GridStatistics servlet in hubConfig.json","created_at":"2016-02-24T01:18:25Z","updated_at":"2016-03-22T00:05:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cfb4585a6ea215a800d05b80237db7d2998e196e","assignee":null,"milestone":{"url":"https://api.github.com/repos/paypal/SeLion/milestones/4","html_url":"https://github.com/paypal/SeLion/milestones/1.1.0","labels_url":"https://api.github.com/repos/paypal/SeLion/milestones/4/labels","id":1414157,"number":4,"title":"1.1.0","description":"","creator":{"login":"mach6","id":3238999,"avatar_url":"https://avatars.githubusercontent.com/u/3238999?v=3","gravatar_id":"","url":"https://api.github.com/users/mach6","html_url":"https://github.com/mach6","followers_url":"https://api.github.com/users/mach6/followers","following_url":"https://api.github.com/users/mach6/following{/other_user}","gists_url":"https://api.github.com/users/mach6/gists{/gist_id}","starred_url":"https://api.github.com/users/mach6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mach6/subscriptions","organizations_url":"https://api.github.com/users/mach6/orgs","repos_url":"https://api.github.com/users/mach6/repos","events_url":"https://api.github.com/users/mach6/events{/privacy}","received_events_url":"https://api.github.com/users/mach6/received_events","type":"User","site_admin":false},"open_issues":7,"closed_issues":38,"state":"open","created_at":"2015-11-16T17:08:49Z","updated_at":"2016-03-21T21:00:24Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/paypal/SeLion/pulls/251/commits","review_comments_url":"https://api.github.com/repos/paypal/SeLion/pulls/251/comments","review_comment_url":"https://api.github.com/repos/paypal/SeLion/pulls/comments{/number}","comments_url":"https://api.github.com/repos/paypal/SeLion/issues/251/comments","statuses_url":"https://api.github.com/repos/paypal/SeLion/statuses/f380c659f0cdc36a2bf22ab210db9a53822d2260","head":{"label":"paypal:kumar-queue-servlet","ref":"kumar-queue-servlet","sha":"f380c659f0cdc36a2bf22ab210db9a53822d2260","user":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"repo":{"id":22930887,"name":"SeLion","full_name":"paypal/SeLion","owner":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/paypal/SeLion","description":"Enabling Test Automation in Java","fork":false,"url":"https://api.github.com/repos/paypal/SeLion","forks_url":"https://api.github.com/repos/paypal/SeLion/forks","keys_url":"https://api.github.com/repos/paypal/SeLion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paypal/SeLion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paypal/SeLion/teams","hooks_url":"https://api.github.com/repos/paypal/SeLion/hooks","issue_events_url":"https://api.github.com/repos/paypal/SeLion/issues/events{/number}","events_url":"https://api.github.com/repos/paypal/SeLion/events","assignees_url":"https://api.github.com/repos/paypal/SeLion/assignees{/user}","branches_url":"https://api.github.com/repos/paypal/SeLion/branches{/branch}","tags_url":"https://api.github.com/repos/paypal/SeLion/tags","blobs_url":"https://api.github.com/repos/paypal/SeLion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paypal/SeLion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paypal/SeLion/git/refs{/sha}","trees_url":"https://api.github.com/repos/paypal/SeLion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paypal/SeLion/statuses/{sha}","languages_url":"https://api.github.com/repos/paypal/SeLion/languages","stargazers_url":"https://api.github.com/repos/paypal/SeLion/stargazers","contributors_url":"https://api.github.com/repos/paypal/SeLion/contributors","subscribers_url":"https://api.github.com/repos/paypal/SeLion/subscribers","subscription_url":"https://api.github.com/repos/paypal/SeLion/subscription","commits_url":"https://api.github.com/repos/paypal/SeLion/commits{/sha}","git_commits_url":"https://api.github.com/repos/paypal/SeLion/git/commits{/sha}","comments_url":"https://api.github.com/repos/paypal/SeLion/comments{/number}","issue_comment_url":"https://api.github.com/repos/paypal/SeLion/issues/comments{/number}","contents_url":"https://api.github.com/repos/paypal/SeLion/contents/{+path}","compare_url":"https://api.github.com/repos/paypal/SeLion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paypal/SeLion/merges","archive_url":"https://api.github.com/repos/paypal/SeLion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paypal/SeLion/downloads","issues_url":"https://api.github.com/repos/paypal/SeLion/issues{/number}","pulls_url":"https://api.github.com/repos/paypal/SeLion/pulls{/number}","milestones_url":"https://api.github.com/repos/paypal/SeLion/milestones{/number}","notifications_url":"https://api.github.com/repos/paypal/SeLion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paypal/SeLion/labels{/name}","releases_url":"https://api.github.com/repos/paypal/SeLion/releases{/id}","deployments_url":"https://api.github.com/repos/paypal/SeLion/deployments","created_at":"2014-08-13T20:52:57Z","updated_at":"2016-03-10T01:13:22Z","pushed_at":"2016-03-21T21:59:19Z","git_url":"git://github.com/paypal/SeLion.git","ssh_url":"git@github.com:paypal/SeLion.git","clone_url":"https://github.com/paypal/SeLion.git","svn_url":"https://github.com/paypal/SeLion","homepage":"http://selion.io","size":31195,"stargazers_count":58,"watchers_count":58,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":95,"mirror_url":null,"open_issues_count":13,"forks":95,"open_issues":13,"watchers":58,"default_branch":"develop"}},"base":{"label":"paypal:develop","ref":"develop","sha":"69f5a6c9b5995b96ecd764983f959c085d9ceeb1","user":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"repo":{"id":22930887,"name":"SeLion","full_name":"paypal/SeLion","owner":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/paypal/SeLion","description":"Enabling Test Automation in Java","fork":false,"url":"https://api.github.com/repos/paypal/SeLion","forks_url":"https://api.github.com/repos/paypal/SeLion/forks","keys_url":"https://api.github.com/repos/paypal/SeLion/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paypal/SeLion/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paypal/SeLion/teams","hooks_url":"https://api.github.com/repos/paypal/SeLion/hooks","issue_events_url":"https://api.github.com/repos/paypal/SeLion/issues/events{/number}","events_url":"https://api.github.com/repos/paypal/SeLion/events","assignees_url":"https://api.github.com/repos/paypal/SeLion/assignees{/user}","branches_url":"https://api.github.com/repos/paypal/SeLion/branches{/branch}","tags_url":"https://api.github.com/repos/paypal/SeLion/tags","blobs_url":"https://api.github.com/repos/paypal/SeLion/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paypal/SeLion/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paypal/SeLion/git/refs{/sha}","trees_url":"https://api.github.com/repos/paypal/SeLion/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paypal/SeLion/statuses/{sha}","languages_url":"https://api.github.com/repos/paypal/SeLion/languages","stargazers_url":"https://api.github.com/repos/paypal/SeLion/stargazers","contributors_url":"https://api.github.com/repos/paypal/SeLion/contributors","subscribers_url":"https://api.github.com/repos/paypal/SeLion/subscribers","subscription_url":"https://api.github.com/repos/paypal/SeLion/subscription","commits_url":"https://api.github.com/repos/paypal/SeLion/commits{/sha}","git_commits_url":"https://api.github.com/repos/paypal/SeLion/git/commits{/sha}","comments_url":"https://api.github.com/repos/paypal/SeLion/comments{/number}","issue_comment_url":"https://api.github.com/repos/paypal/SeLion/issues/comments{/number}","contents_url":"https://api.github.com/repos/paypal/SeLion/contents/{+path}","compare_url":"https://api.github.com/repos/paypal/SeLion/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paypal/SeLion/merges","archive_url":"https://api.github.com/repos/paypal/SeLion/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paypal/SeLion/downloads","issues_url":"https://api.github.com/repos/paypal/SeLion/issues{/number}","pulls_url":"https://api.github.com/repos/paypal/SeLion/pulls{/number}","milestones_url":"https://api.github.com/repos/paypal/SeLion/milestones{/number}","notifications_url":"https://api.github.com/repos/paypal/SeLion/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paypal/SeLion/labels{/name}","releases_url":"https://api.github.com/repos/paypal/SeLion/releases{/id}","deployments_url":"https://api.github.com/repos/paypal/SeLion/deployments","created_at":"2014-08-13T20:52:57Z","updated_at":"2016-03-10T01:13:22Z","pushed_at":"2016-03-21T21:59:19Z","git_url":"git://github.com/paypal/SeLion.git","ssh_url":"git@github.com:paypal/SeLion.git","clone_url":"https://github.com/paypal/SeLion.git","svn_url":"https://github.com/paypal/SeLion","homepage":"http://selion.io","size":31195,"stargazers_count":58,"watchers_count":58,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":95,"mirror_url":null,"open_issues_count":13,"forks":95,"open_issues":13,"watchers":58,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/paypal/SeLion/pulls/251"},"html":{"href":"https://github.com/paypal/SeLion/pull/251"},"issue":{"href":"https://api.github.com/repos/paypal/SeLion/issues/251"},"comments":{"href":"https://api.github.com/repos/paypal/SeLion/issues/251/comments"},"review_comments":{"href":"https://api.github.com/repos/paypal/SeLion/pulls/251/comments"},"review_comment":{"href":"https://api.github.com/repos/paypal/SeLion/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/paypal/SeLion/pulls/251/commits"},"statuses":{"href":"https://api.github.com/repos/paypal/SeLion/statuses/f380c659f0cdc36a2bf22ab210db9a53822d2260"}}}}