{"action":"created","comment":{"url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/comments/68895936","id":68895936,"diff_hunk":"@@ -0,0 +1,132 @@\n+/*\n+ * Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\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\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package com.hazelcast.durableexecutor.impl;\n+\n+import com.hazelcast.core.DistributedObject;\n+import com.hazelcast.spi.ManagedService;\n+import com.hazelcast.spi.MigrationAwareService;\n+import com.hazelcast.spi.NodeEngine;\n+import com.hazelcast.spi.Operation;\n+import com.hazelcast.spi.PartitionMigrationEvent;\n+import com.hazelcast.spi.PartitionReplicationEvent;\n+import com.hazelcast.spi.RemoteService;\n+import com.hazelcast.spi.impl.NodeEngineImpl;\n+import com.hazelcast.spi.partition.MigrationEndpoint;\n+\n+import java.util.Collections;\n+import java.util.Properties;\n+import java.util.Set;\n+import java.util.concurrent.ConcurrentHashMap;\n+\n+public class DistributedDurableExecutorService implements ManagedService, RemoteService, MigrationAwareService {\n+\n+    public static final String SERVICE_NAME = \"hz:impl:durableExecutorService\";\n+\n+    private final NodeEngineImpl nodeEngine;\n+    private final DurableExecutorPartitionContainer[] partitionContainers;\n+\n+    private final Set<String> shutdownExecutors\n+            = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());\n+\n+    public DistributedDurableExecutorService(NodeEngineImpl nodeEngine) {\n+        this.nodeEngine = nodeEngine;\n+        int partitionCount = nodeEngine.getPartitionService().getPartitionCount();\n+        partitionContainers = new DurableExecutorPartitionContainer[partitionCount];\n+        for (int partitionId = 0; partitionId < partitionCount; partitionId++) {\n+            partitionContainers[partitionId] = new DurableExecutorPartitionContainer(nodeEngine, partitionId);\n+        }\n+    }\n+\n+    @Override\n+    public void init(NodeEngine nodeEngine, Properties properties) {\n+    }\n+\n+    public DurableExecutorPartitionContainer getPartitionContainer(int partitionId) {\n+        return partitionContainers[partitionId];\n+    }\n+\n+    public NodeEngine getNodeEngine() {\n+        return nodeEngine;\n+    }\n+\n+    @Override\n+    public void reset() {\n+        shutdownExecutors.clear();\n+        for (int partitionId = 0; partitionId < partitionContainers.length; partitionId++) {\n+            partitionContainers[partitionId] = new DurableExecutorPartitionContainer(nodeEngine, partitionId);\n+        }\n+    }\n+\n+    @Override\n+    public void shutdown(boolean terminate) {\n+        reset();\n+    }\n+\n+    @Override\n+    public DistributedObject createDistributedObject(String name) {\n+        return new DurableExecutorServiceProxy(nodeEngine, this, name);\n+    }\n+\n+    @Override\n+    public void destroyDistributedObject(String name) {\n+        shutdownExecutors.remove(name);\n+        nodeEngine.getExecutionService().shutdownDurableExecutor(name);\n+    }\n+\n+    public void shutdownExecutor(String name) {\n+        nodeEngine.getExecutionService().shutdownDurableExecutor(name);\n+        shutdownExecutors.add(name);\n+    }\n+\n+    public boolean isShutdown(String name) {\n+        return shutdownExecutors.contains(name);\n+    }\n+\n+    @Override\n+    public Operation prepareReplicationOperation(PartitionReplicationEvent event) {\n+        int partitionId = event.getPartitionId();\n+        DurableExecutorPartitionContainer partitionContainer = partitionContainers[partitionId];\n+        return partitionContainer.prepareReplicationOperation(event.getReplicaIndex());\n+    }\n+\n+    @Override\n+    public void beforeMigration(PartitionMigrationEvent event) {\n+    }\n+\n+    @Override\n+    public void commitMigration(PartitionMigrationEvent event) {\n+        int partitionId = event.getPartitionId();\n+        if (event.getMigrationEndpoint() == MigrationEndpoint.SOURCE) {\n+            clearRingBuddersHavingLesserBackupCountThan(partitionId, event.getNewReplicaIndex());\n+        } else if (event.getNewReplicaIndex() == 0) {\n+            DurableExecutorPartitionContainer partitionContainer = partitionContainers[partitionId];\n+            partitionContainer.executeAll();\n+        }\n+    }\n+\n+    @Override\n+    public void rollbackMigration(PartitionMigrationEvent event) {\n+        if (event.getMigrationEndpoint() == MigrationEndpoint.DESTINATION) {\n+            clearRingBuddersHavingLesserBackupCountThan(event.getPartitionId(), event.getCurrentReplicaIndex());\n+        }\n+    }\n+\n+    private void clearRingBuddersHavingLesserBackupCountThan(int partitionId, int thresholdReplicaIndex) {","path":"hazelcast/src/main/java/com/hazelcast/durableexecutor/impl/DistributedDurableExecutorService.java","position":128,"original_position":128,"commit_id":"88e8fdb851820e6ea7cc40f6f65518242d85bb23","original_commit_id":"88e8fdb851820e6ea7cc40f6f65518242d85bb23","user":{"login":"mdogan","id":1201712,"avatar_url":"https://avatars.githubusercontent.com/u/1201712?v=3","gravatar_id":"","url":"https://api.github.com/users/mdogan","html_url":"https://github.com/mdogan","followers_url":"https://api.github.com/users/mdogan/followers","following_url":"https://api.github.com/users/mdogan/following{/other_user}","gists_url":"https://api.github.com/users/mdogan/gists{/gist_id}","starred_url":"https://api.github.com/users/mdogan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdogan/subscriptions","organizations_url":"https://api.github.com/users/mdogan/orgs","repos_url":"https://api.github.com/users/mdogan/repos","events_url":"https://api.github.com/users/mdogan/events{/privacy}","received_events_url":"https://api.github.com/users/mdogan/received_events","type":"User","site_admin":false},"body":"`RingBudders` 😃 ","created_at":"2016-06-29T07:15:07Z","updated_at":"2016-06-29T07:15:07Z","html_url":"https://github.com/hazelcast/hazelcast/pull/8270#discussion_r68895936","pull_request_url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/8270","_links":{"self":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/comments/68895936"},"html":{"href":"https://github.com/hazelcast/hazelcast/pull/8270#discussion_r68895936"},"pull_request":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/8270"}}},"pull_request":{"url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/8270","id":71840687,"html_url":"https://github.com/hazelcast/hazelcast/pull/8270","diff_url":"https://github.com/hazelcast/hazelcast/pull/8270.diff","patch_url":"https://github.com/hazelcast/hazelcast/pull/8270.patch","issue_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/8270","number":8270,"state":"open","locked":false,"title":"Introduced DurableExecutorService","user":{"login":"gurbuzali","id":1741680,"avatar_url":"https://avatars.githubusercontent.com/u/1741680?v=3","gravatar_id":"","url":"https://api.github.com/users/gurbuzali","html_url":"https://github.com/gurbuzali","followers_url":"https://api.github.com/users/gurbuzali/followers","following_url":"https://api.github.com/users/gurbuzali/following{/other_user}","gists_url":"https://api.github.com/users/gurbuzali/gists{/gist_id}","starred_url":"https://api.github.com/users/gurbuzali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gurbuzali/subscriptions","organizations_url":"https://api.github.com/users/gurbuzali/orgs","repos_url":"https://api.github.com/users/gurbuzali/repos","events_url":"https://api.github.com/users/gurbuzali/events{/privacy}","received_events_url":"https://api.github.com/users/gurbuzali/received_events","type":"User","site_admin":false},"body":"https://hazelcast.atlassian.net/wiki/display/EN/Fault+Tolerant+ExecutorService+Design","created_at":"2016-05-29T23:13:54Z","updated_at":"2016-06-29T07:15:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ec51cb4fe979df10b8ffc861d2495d072d2cd077","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/hazelcast/hazelcast/milestones/70","html_url":"https://github.com/hazelcast/hazelcast/milestones/3.7","labels_url":"https://api.github.com/repos/hazelcast/hazelcast/milestones/70/labels","id":1346433,"number":70,"title":"3.7","description":"","creator":{"login":"pveentjer","id":105243,"avatar_url":"https://avatars.githubusercontent.com/u/105243?v=3","gravatar_id":"","url":"https://api.github.com/users/pveentjer","html_url":"https://github.com/pveentjer","followers_url":"https://api.github.com/users/pveentjer/followers","following_url":"https://api.github.com/users/pveentjer/following{/other_user}","gists_url":"https://api.github.com/users/pveentjer/gists{/gist_id}","starred_url":"https://api.github.com/users/pveentjer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pveentjer/subscriptions","organizations_url":"https://api.github.com/users/pveentjer/orgs","repos_url":"https://api.github.com/users/pveentjer/repos","events_url":"https://api.github.com/users/pveentjer/events{/privacy}","received_events_url":"https://api.github.com/users/pveentjer/received_events","type":"User","site_admin":false},"open_issues":73,"closed_issues":802,"state":"open","created_at":"2015-10-09T12:16:13Z","updated_at":"2016-06-29T07:01:06Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/8270/commits","review_comments_url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/8270/comments","review_comment_url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/8270/comments","statuses_url":"https://api.github.com/repos/hazelcast/hazelcast/statuses/88e8fdb851820e6ea7cc40f6f65518242d85bb23","head":{"label":"gurbuzali:with-twice-invocation","ref":"with-twice-invocation","sha":"88e8fdb851820e6ea7cc40f6f65518242d85bb23","user":{"login":"gurbuzali","id":1741680,"avatar_url":"https://avatars.githubusercontent.com/u/1741680?v=3","gravatar_id":"","url":"https://api.github.com/users/gurbuzali","html_url":"https://github.com/gurbuzali","followers_url":"https://api.github.com/users/gurbuzali/followers","following_url":"https://api.github.com/users/gurbuzali/following{/other_user}","gists_url":"https://api.github.com/users/gurbuzali/gists{/gist_id}","starred_url":"https://api.github.com/users/gurbuzali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gurbuzali/subscriptions","organizations_url":"https://api.github.com/users/gurbuzali/orgs","repos_url":"https://api.github.com/users/gurbuzali/repos","events_url":"https://api.github.com/users/gurbuzali/events{/privacy}","received_events_url":"https://api.github.com/users/gurbuzali/received_events","type":"User","site_admin":false},"repo":{"id":12157261,"name":"hazelcast","full_name":"gurbuzali/hazelcast","owner":{"login":"gurbuzali","id":1741680,"avatar_url":"https://avatars.githubusercontent.com/u/1741680?v=3","gravatar_id":"","url":"https://api.github.com/users/gurbuzali","html_url":"https://github.com/gurbuzali","followers_url":"https://api.github.com/users/gurbuzali/followers","following_url":"https://api.github.com/users/gurbuzali/following{/other_user}","gists_url":"https://api.github.com/users/gurbuzali/gists{/gist_id}","starred_url":"https://api.github.com/users/gurbuzali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gurbuzali/subscriptions","organizations_url":"https://api.github.com/users/gurbuzali/orgs","repos_url":"https://api.github.com/users/gurbuzali/repos","events_url":"https://api.github.com/users/gurbuzali/events{/privacy}","received_events_url":"https://api.github.com/users/gurbuzali/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gurbuzali/hazelcast","description":"Open Source In-Memory Data Grid","fork":true,"url":"https://api.github.com/repos/gurbuzali/hazelcast","forks_url":"https://api.github.com/repos/gurbuzali/hazelcast/forks","keys_url":"https://api.github.com/repos/gurbuzali/hazelcast/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gurbuzali/hazelcast/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gurbuzali/hazelcast/teams","hooks_url":"https://api.github.com/repos/gurbuzali/hazelcast/hooks","issue_events_url":"https://api.github.com/repos/gurbuzali/hazelcast/issues/events{/number}","events_url":"https://api.github.com/repos/gurbuzali/hazelcast/events","assignees_url":"https://api.github.com/repos/gurbuzali/hazelcast/assignees{/user}","branches_url":"https://api.github.com/repos/gurbuzali/hazelcast/branches{/branch}","tags_url":"https://api.github.com/repos/gurbuzali/hazelcast/tags","blobs_url":"https://api.github.com/repos/gurbuzali/hazelcast/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gurbuzali/hazelcast/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gurbuzali/hazelcast/git/refs{/sha}","trees_url":"https://api.github.com/repos/gurbuzali/hazelcast/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gurbuzali/hazelcast/statuses/{sha}","languages_url":"https://api.github.com/repos/gurbuzali/hazelcast/languages","stargazers_url":"https://api.github.com/repos/gurbuzali/hazelcast/stargazers","contributors_url":"https://api.github.com/repos/gurbuzali/hazelcast/contributors","subscribers_url":"https://api.github.com/repos/gurbuzali/hazelcast/subscribers","subscription_url":"https://api.github.com/repos/gurbuzali/hazelcast/subscription","commits_url":"https://api.github.com/repos/gurbuzali/hazelcast/commits{/sha}","git_commits_url":"https://api.github.com/repos/gurbuzali/hazelcast/git/commits{/sha}","comments_url":"https://api.github.com/repos/gurbuzali/hazelcast/comments{/number}","issue_comment_url":"https://api.github.com/repos/gurbuzali/hazelcast/issues/comments{/number}","contents_url":"https://api.github.com/repos/gurbuzali/hazelcast/contents/{+path}","compare_url":"https://api.github.com/repos/gurbuzali/hazelcast/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gurbuzali/hazelcast/merges","archive_url":"https://api.github.com/repos/gurbuzali/hazelcast/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gurbuzali/hazelcast/downloads","issues_url":"https://api.github.com/repos/gurbuzali/hazelcast/issues{/number}","pulls_url":"https://api.github.com/repos/gurbuzali/hazelcast/pulls{/number}","milestones_url":"https://api.github.com/repos/gurbuzali/hazelcast/milestones{/number}","notifications_url":"https://api.github.com/repos/gurbuzali/hazelcast/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gurbuzali/hazelcast/labels{/name}","releases_url":"https://api.github.com/repos/gurbuzali/hazelcast/releases{/id}","deployments_url":"https://api.github.com/repos/gurbuzali/hazelcast/deployments","created_at":"2013-08-16T11:27:45Z","updated_at":"2015-05-22T07:27:36Z","pushed_at":"2016-06-29T06:56:22Z","git_url":"git://github.com/gurbuzali/hazelcast.git","ssh_url":"git@github.com:gurbuzali/hazelcast.git","clone_url":"https://github.com/gurbuzali/hazelcast.git","svn_url":"https://github.com/gurbuzali/hazelcast","homepage":"www.hazelcast.com","size":93065,"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":"hazelcast:master","ref":"master","sha":"d3ae6150e4928c7e6b72635dadb3a3a5b864fb2e","user":{"login":"hazelcast","id":1453152,"avatar_url":"https://avatars.githubusercontent.com/u/1453152?v=3","gravatar_id":"","url":"https://api.github.com/users/hazelcast","html_url":"https://github.com/hazelcast","followers_url":"https://api.github.com/users/hazelcast/followers","following_url":"https://api.github.com/users/hazelcast/following{/other_user}","gists_url":"https://api.github.com/users/hazelcast/gists{/gist_id}","starred_url":"https://api.github.com/users/hazelcast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hazelcast/subscriptions","organizations_url":"https://api.github.com/users/hazelcast/orgs","repos_url":"https://api.github.com/users/hazelcast/repos","events_url":"https://api.github.com/users/hazelcast/events{/privacy}","received_events_url":"https://api.github.com/users/hazelcast/received_events","type":"Organization","site_admin":false},"repo":{"id":3786237,"name":"hazelcast","full_name":"hazelcast/hazelcast","owner":{"login":"hazelcast","id":1453152,"avatar_url":"https://avatars.githubusercontent.com/u/1453152?v=3","gravatar_id":"","url":"https://api.github.com/users/hazelcast","html_url":"https://github.com/hazelcast","followers_url":"https://api.github.com/users/hazelcast/followers","following_url":"https://api.github.com/users/hazelcast/following{/other_user}","gists_url":"https://api.github.com/users/hazelcast/gists{/gist_id}","starred_url":"https://api.github.com/users/hazelcast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hazelcast/subscriptions","organizations_url":"https://api.github.com/users/hazelcast/orgs","repos_url":"https://api.github.com/users/hazelcast/repos","events_url":"https://api.github.com/users/hazelcast/events{/privacy}","received_events_url":"https://api.github.com/users/hazelcast/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hazelcast/hazelcast","description":"Open Source In-Memory Data Grid","fork":false,"url":"https://api.github.com/repos/hazelcast/hazelcast","forks_url":"https://api.github.com/repos/hazelcast/hazelcast/forks","keys_url":"https://api.github.com/repos/hazelcast/hazelcast/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hazelcast/hazelcast/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hazelcast/hazelcast/teams","hooks_url":"https://api.github.com/repos/hazelcast/hazelcast/hooks","issue_events_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/events{/number}","events_url":"https://api.github.com/repos/hazelcast/hazelcast/events","assignees_url":"https://api.github.com/repos/hazelcast/hazelcast/assignees{/user}","branches_url":"https://api.github.com/repos/hazelcast/hazelcast/branches{/branch}","tags_url":"https://api.github.com/repos/hazelcast/hazelcast/tags","blobs_url":"https://api.github.com/repos/hazelcast/hazelcast/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hazelcast/hazelcast/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hazelcast/hazelcast/git/refs{/sha}","trees_url":"https://api.github.com/repos/hazelcast/hazelcast/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hazelcast/hazelcast/statuses/{sha}","languages_url":"https://api.github.com/repos/hazelcast/hazelcast/languages","stargazers_url":"https://api.github.com/repos/hazelcast/hazelcast/stargazers","contributors_url":"https://api.github.com/repos/hazelcast/hazelcast/contributors","subscribers_url":"https://api.github.com/repos/hazelcast/hazelcast/subscribers","subscription_url":"https://api.github.com/repos/hazelcast/hazelcast/subscription","commits_url":"https://api.github.com/repos/hazelcast/hazelcast/commits{/sha}","git_commits_url":"https://api.github.com/repos/hazelcast/hazelcast/git/commits{/sha}","comments_url":"https://api.github.com/repos/hazelcast/hazelcast/comments{/number}","issue_comment_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/comments{/number}","contents_url":"https://api.github.com/repos/hazelcast/hazelcast/contents/{+path}","compare_url":"https://api.github.com/repos/hazelcast/hazelcast/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hazelcast/hazelcast/merges","archive_url":"https://api.github.com/repos/hazelcast/hazelcast/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hazelcast/hazelcast/downloads","issues_url":"https://api.github.com/repos/hazelcast/hazelcast/issues{/number}","pulls_url":"https://api.github.com/repos/hazelcast/hazelcast/pulls{/number}","milestones_url":"https://api.github.com/repos/hazelcast/hazelcast/milestones{/number}","notifications_url":"https://api.github.com/repos/hazelcast/hazelcast/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hazelcast/hazelcast/labels{/name}","releases_url":"https://api.github.com/repos/hazelcast/hazelcast/releases{/id}","deployments_url":"https://api.github.com/repos/hazelcast/hazelcast/deployments","created_at":"2012-03-21T12:25:18Z","updated_at":"2016-06-28T12:45:43Z","pushed_at":"2016-06-29T06:56:23Z","git_url":"git://github.com/hazelcast/hazelcast.git","ssh_url":"git@github.com:hazelcast/hazelcast.git","clone_url":"https://github.com/hazelcast/hazelcast.git","svn_url":"https://github.com/hazelcast/hazelcast","homepage":"www.hazelcast.com","size":128876,"stargazers_count":1610,"watchers_count":1610,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":766,"mirror_url":null,"open_issues_count":543,"forks":766,"open_issues":543,"watchers":1610,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/8270"},"html":{"href":"https://github.com/hazelcast/hazelcast/pull/8270"},"issue":{"href":"https://api.github.com/repos/hazelcast/hazelcast/issues/8270"},"comments":{"href":"https://api.github.com/repos/hazelcast/hazelcast/issues/8270/comments"},"review_comments":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/8270/comments"},"review_comment":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/8270/commits"},"statuses":{"href":"https://api.github.com/repos/hazelcast/hazelcast/statuses/88e8fdb851820e6ea7cc40f6f65518242d85bb23"}}}}
{"actor":{"display_login":"mdogan"}}