{"action":"created","comment":{"url":"https://api.github.com/repos/apache/reef/pulls/comments/61642479","id":61642479,"diff_hunk":"@@ -0,0 +1,154 @@\n+﻿// Licensed to the Apache Software Foundation (ASF) under one\n+// or more contributor license agreements.  See the NOTICE file\n+// distributed with this work for additional information\n+// regarding copyright ownership.  The ASF licenses this file\n+// to you under the Apache License, Version 2.0 (the\n+// \"License\"); you may not use this file except in compliance\n+// with the License.  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,\n+// software distributed under the License is distributed on an\n+// \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+// KIND, either express or implied.  See the License for the\n+// specific language governing permissions and limitations\n+// under the License.\n+\n+using System.Collections.Generic;\n+using System.Globalization;\n+using Org.Apache.REEF.Driver.Context;\n+using Org.Apache.REEF.Driver.Evaluator;\n+using Org.Apache.REEF.Utilities.Attributes;\n+using Org.Apache.REEF.Utilities.Diagnostics;\n+using Org.Apache.REEF.Utilities.Logging;\n+\n+namespace Org.Apache.REEF.IMRU.OnREEF.Driver\n+{\n+    /// <summary>\n+    /// Manages active contexts for the driver\n+    /// </summary>\n+    [NotThreadSafe]\n+    internal sealed class ActiveContextManager\n+    {\n+        private static readonly Logger Logger = Logger.GetLogger(typeof(ActiveContextManager));\n+        private readonly IDictionary<string, IActiveContext> _activeContexts = new Dictionary<string, IActiveContext>();\n+        private readonly int _totalExpectedContexts;\n+\n+        /// <summary>\n+        /// Constructor of ActiveContextManager\n+        /// totalContexts specify the total number of expected active contexts that driver needs\n+        /// </summary>\n+        /// <param name=\"totalContexts\"></param>\n+        internal ActiveContextManager(int totalContexts)\n+        {\n+            _totalExpectedContexts = totalContexts;\n+        }\n+\n+        /// <summary>\n+        /// Returns the collection of IActiveContext\n+        /// </summary>\n+        internal ICollection<IActiveContext> ActiveContexts\n+        {\n+            get { return _activeContexts.Values; }\n+        }\n+\n+        /// <summary>\n+        /// Returns the difference between the number of expected IActiveContext and actually number of IActiveContext. \n+        /// </summary>\n+        internal int NumberOfMissingContexts\n+        {\n+            get { return _totalExpectedContexts - NumberOfActiveContexts; }\n+        }\n+\n+        /// <summary>\n+        /// Checks if all the requested contexts are received. \n+        /// </summary>\n+        internal bool AllContextsReceived\n+        {\n+            get { return NumberOfMissingContexts == 0; }\n+        }\n+\n+        /// <summary>\n+        /// Adding an IActiveContext to the ActiveContext collection\n+        /// Throw ApplicationException if the IActiveContext already exists.\n+        /// </summary>\n+        /// <param name=\"activeContext\"></param>\n+        internal void Add(IActiveContext activeContext)\n+        {\n+            if (_activeContexts.ContainsKey(activeContext.Id))\n+            {\n+                var msg = string.Format(CultureInfo.InvariantCulture, \"The context [{0}] received already exists.\", activeContext.Id);\n+                Exceptions.Throw(new IMRUSystemException(msg), Logger);\n+            }\n+\n+            if (NumberOfActiveContexts >= _totalExpectedContexts)\n+            {\n+                var msg = string.Format(CultureInfo.InvariantCulture, \"Trying to add an extra active context {0}. The total number of the active contexts has reached to the expected number {1}.\", activeContext.Id, _totalExpectedContexts);\n+                Exceptions.Throw(new IMRUSystemException(msg), Logger);\n+            }\n+\n+            _activeContexts.Add(activeContext.Id, activeContext);\n+        }\n+\n+        /// <summary>\n+        /// Remove an IActiveContext from the ActiveContext collection\n+        /// Throw ApplicationException if the IActiveContext doesn't exist.\n+        /// </summary>\n+        /// <param name=\"activeContextId\"></param>\n+        internal void Remove(string activeContextId)\n+        {\n+            if (!_activeContexts.ContainsKey(activeContextId))\n+            {\n+                var msg = string.Format(CultureInfo.InvariantCulture, \"The context [{0}] to be removed does not exist.\", activeContextId);\n+                Exceptions.Throw(new IMRUSystemException(msg), Logger);\n+            }\n+            _activeContexts.Remove(activeContextId);\n+        }\n+\n+        /// <summary>\n+        /// Returns the current number of IActiveContext in the ActiveContext collection\n+        /// </summary>\n+        internal int NumberOfActiveContexts\n+        {\n+            get { return _activeContexts.Count; }\n+        }\n+\n+        /// <summary>\n+        /// Given an IFailedEvaluator, remove associated IActiveContext from the collection\n+        /// Throw SystemException if associated IActiveContext doesn't exist.","path":"lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/ActiveContextManager.cs","position":119,"original_position":119,"commit_id":"533ed62c4177024c5480a3965397660991084b49","original_commit_id":"533ed62c4177024c5480a3965397660991084b49","user":{"login":"afchung","id":2817619,"avatar_url":"https://avatars.githubusercontent.com/u/2817619?v=3","gravatar_id":"","url":"https://api.github.com/users/afchung","html_url":"https://github.com/afchung","followers_url":"https://api.github.com/users/afchung/followers","following_url":"https://api.github.com/users/afchung/following{/other_user}","gists_url":"https://api.github.com/users/afchung/gists{/gist_id}","starred_url":"https://api.github.com/users/afchung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afchung/subscriptions","organizations_url":"https://api.github.com/users/afchung/orgs","repos_url":"https://api.github.com/users/afchung/repos","events_url":"https://api.github.com/users/afchung/events{/privacy}","received_events_url":"https://api.github.com/users/afchung/received_events","type":"User","site_admin":false},"body":"Where is `SystemException` thrown?","created_at":"2016-04-29T20:48:23Z","updated_at":"2016-04-29T20:48:23Z","html_url":"https://github.com/apache/reef/pull/977#discussion_r61642479","pull_request_url":"https://api.github.com/repos/apache/reef/pulls/977","_links":{"self":{"href":"https://api.github.com/repos/apache/reef/pulls/comments/61642479"},"html":{"href":"https://github.com/apache/reef/pull/977#discussion_r61642479"},"pull_request":{"href":"https://api.github.com/repos/apache/reef/pulls/977"}}},"pull_request":{"url":"https://api.github.com/repos/apache/reef/pulls/977","id":68293639,"html_url":"https://github.com/apache/reef/pull/977","diff_url":"https://github.com/apache/reef/pull/977.diff","patch_url":"https://github.com/apache/reef/pull/977.patch","issue_url":"https://api.github.com/repos/apache/reef/issues/977","number":977,"state":"open","locked":false,"title":"[REEF-1340] Creating Context manager for Fault Tolerant","user":{"login":"jwang98052","id":5666504,"avatar_url":"https://avatars.githubusercontent.com/u/5666504?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang98052","html_url":"https://github.com/jwang98052","followers_url":"https://api.github.com/users/jwang98052/followers","following_url":"https://api.github.com/users/jwang98052/following{/other_user}","gists_url":"https://api.github.com/users/jwang98052/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang98052/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang98052/subscriptions","organizations_url":"https://api.github.com/users/jwang98052/orgs","repos_url":"https://api.github.com/users/jwang98052/repos","events_url":"https://api.github.com/users/jwang98052/events{/privacy}","received_events_url":"https://api.github.com/users/jwang98052/received_events","type":"User","site_admin":false},"body":"Adding ContextManager which manages IActiveContext Add/Remove, etc operations\r\nAdding test cases for it\r\n\r\nJIRA: [REEF-1340](https://issues.apache.org/jira/browse/REEF-1340)\r\nThis closes","created_at":"2016-04-28T21:28:11Z","updated_at":"2016-04-29T20:48:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"520a18da215d491673bf5cdf07a3b9152eb4de71","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/reef/pulls/977/commits","review_comments_url":"https://api.github.com/repos/apache/reef/pulls/977/comments","review_comment_url":"https://api.github.com/repos/apache/reef/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/reef/issues/977/comments","statuses_url":"https://api.github.com/repos/apache/reef/statuses/533ed62c4177024c5480a3965397660991084b49","head":{"label":"jwang98052:REEF-1340","ref":"REEF-1340","sha":"533ed62c4177024c5480a3965397660991084b49","user":{"login":"jwang98052","id":5666504,"avatar_url":"https://avatars.githubusercontent.com/u/5666504?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang98052","html_url":"https://github.com/jwang98052","followers_url":"https://api.github.com/users/jwang98052/followers","following_url":"https://api.github.com/users/jwang98052/following{/other_user}","gists_url":"https://api.github.com/users/jwang98052/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang98052/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang98052/subscriptions","organizations_url":"https://api.github.com/users/jwang98052/orgs","repos_url":"https://api.github.com/users/jwang98052/repos","events_url":"https://api.github.com/users/jwang98052/events{/privacy}","received_events_url":"https://api.github.com/users/jwang98052/received_events","type":"User","site_admin":false},"repo":{"id":25940156,"name":"reef","full_name":"jwang98052/reef","owner":{"login":"jwang98052","id":5666504,"avatar_url":"https://avatars.githubusercontent.com/u/5666504?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang98052","html_url":"https://github.com/jwang98052","followers_url":"https://api.github.com/users/jwang98052/followers","following_url":"https://api.github.com/users/jwang98052/following{/other_user}","gists_url":"https://api.github.com/users/jwang98052/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang98052/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang98052/subscriptions","organizations_url":"https://api.github.com/users/jwang98052/orgs","repos_url":"https://api.github.com/users/jwang98052/repos","events_url":"https://api.github.com/users/jwang98052/events{/privacy}","received_events_url":"https://api.github.com/users/jwang98052/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jwang98052/reef","description":"Mirror of Apache REEF (Incubating)","fork":true,"url":"https://api.github.com/repos/jwang98052/reef","forks_url":"https://api.github.com/repos/jwang98052/reef/forks","keys_url":"https://api.github.com/repos/jwang98052/reef/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jwang98052/reef/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jwang98052/reef/teams","hooks_url":"https://api.github.com/repos/jwang98052/reef/hooks","issue_events_url":"https://api.github.com/repos/jwang98052/reef/issues/events{/number}","events_url":"https://api.github.com/repos/jwang98052/reef/events","assignees_url":"https://api.github.com/repos/jwang98052/reef/assignees{/user}","branches_url":"https://api.github.com/repos/jwang98052/reef/branches{/branch}","tags_url":"https://api.github.com/repos/jwang98052/reef/tags","blobs_url":"https://api.github.com/repos/jwang98052/reef/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jwang98052/reef/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jwang98052/reef/git/refs{/sha}","trees_url":"https://api.github.com/repos/jwang98052/reef/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jwang98052/reef/statuses/{sha}","languages_url":"https://api.github.com/repos/jwang98052/reef/languages","stargazers_url":"https://api.github.com/repos/jwang98052/reef/stargazers","contributors_url":"https://api.github.com/repos/jwang98052/reef/contributors","subscribers_url":"https://api.github.com/repos/jwang98052/reef/subscribers","subscription_url":"https://api.github.com/repos/jwang98052/reef/subscription","commits_url":"https://api.github.com/repos/jwang98052/reef/commits{/sha}","git_commits_url":"https://api.github.com/repos/jwang98052/reef/git/commits{/sha}","comments_url":"https://api.github.com/repos/jwang98052/reef/comments{/number}","issue_comment_url":"https://api.github.com/repos/jwang98052/reef/issues/comments{/number}","contents_url":"https://api.github.com/repos/jwang98052/reef/contents/{+path}","compare_url":"https://api.github.com/repos/jwang98052/reef/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jwang98052/reef/merges","archive_url":"https://api.github.com/repos/jwang98052/reef/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jwang98052/reef/downloads","issues_url":"https://api.github.com/repos/jwang98052/reef/issues{/number}","pulls_url":"https://api.github.com/repos/jwang98052/reef/pulls{/number}","milestones_url":"https://api.github.com/repos/jwang98052/reef/milestones{/number}","notifications_url":"https://api.github.com/repos/jwang98052/reef/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jwang98052/reef/labels{/name}","releases_url":"https://api.github.com/repos/jwang98052/reef/releases{/id}","deployments_url":"https://api.github.com/repos/jwang98052/reef/deployments","created_at":"2014-10-29T20:32:40Z","updated_at":"2015-12-02T18:42:15Z","pushed_at":"2016-04-29T19:45:38Z","git_url":"git://github.com/jwang98052/reef.git","ssh_url":"git@github.com:jwang98052/reef.git","clone_url":"https://github.com/jwang98052/reef.git","svn_url":"https://github.com/jwang98052/reef","homepage":null,"size":36958,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"771b34bd24a358784ec4d24a907fecae39701220","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":25623941,"name":"reef","full_name":"apache/reef","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/reef","description":"Mirror of Apache REEF","fork":false,"url":"https://api.github.com/repos/apache/reef","forks_url":"https://api.github.com/repos/apache/reef/forks","keys_url":"https://api.github.com/repos/apache/reef/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/reef/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/reef/teams","hooks_url":"https://api.github.com/repos/apache/reef/hooks","issue_events_url":"https://api.github.com/repos/apache/reef/issues/events{/number}","events_url":"https://api.github.com/repos/apache/reef/events","assignees_url":"https://api.github.com/repos/apache/reef/assignees{/user}","branches_url":"https://api.github.com/repos/apache/reef/branches{/branch}","tags_url":"https://api.github.com/repos/apache/reef/tags","blobs_url":"https://api.github.com/repos/apache/reef/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/reef/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/reef/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/reef/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/reef/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/reef/languages","stargazers_url":"https://api.github.com/repos/apache/reef/stargazers","contributors_url":"https://api.github.com/repos/apache/reef/contributors","subscribers_url":"https://api.github.com/repos/apache/reef/subscribers","subscription_url":"https://api.github.com/repos/apache/reef/subscription","commits_url":"https://api.github.com/repos/apache/reef/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/reef/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/reef/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/reef/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/reef/contents/{+path}","compare_url":"https://api.github.com/repos/apache/reef/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/reef/merges","archive_url":"https://api.github.com/repos/apache/reef/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/reef/downloads","issues_url":"https://api.github.com/repos/apache/reef/issues{/number}","pulls_url":"https://api.github.com/repos/apache/reef/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/reef/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/reef/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/reef/labels{/name}","releases_url":"https://api.github.com/repos/apache/reef/releases{/id}","deployments_url":"https://api.github.com/repos/apache/reef/deployments","created_at":"2014-10-23T07:00:10Z","updated_at":"2016-04-23T12:24:09Z","pushed_at":"2016-04-29T20:40:08Z","git_url":"git://github.com/apache/reef.git","ssh_url":"git@github.com:apache/reef.git","clone_url":"https://github.com/apache/reef.git","svn_url":"https://github.com/apache/reef","homepage":"","size":47913,"stargazers_count":47,"watchers_count":47,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":55,"mirror_url":"git://git.apache.org/reef.git","open_issues_count":5,"forks":55,"open_issues":5,"watchers":47,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/reef/pulls/977"},"html":{"href":"https://github.com/apache/reef/pull/977"},"issue":{"href":"https://api.github.com/repos/apache/reef/issues/977"},"comments":{"href":"https://api.github.com/repos/apache/reef/issues/977/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/reef/pulls/977/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/reef/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/reef/pulls/977/commits"},"statuses":{"href":"https://api.github.com/repos/apache/reef/statuses/533ed62c4177024c5480a3965397660991084b49"}}}}