{"action":"created","comment":{"url":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/comments/22768197","id":22768197,"diff_hunk":"@@ -0,0 +1,178 @@\n+/*\n+ *  Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.\n+ *\n+ *  WSO2 Inc. licenses this file to you under the Apache License,\n+ *  Version 2.0 (the \"License\"); you may not use this file except\n+ *  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,\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+ */\n+\n+package org.wso2.carbon.event.core.sharedmemory;\n+\n+import org.apache.commons.logging.Log;\n+import org.apache.commons.logging.LogFactory;\n+import org.wso2.carbon.event.core.EventBroker;\n+import org.wso2.carbon.event.core.Message;\n+import org.wso2.carbon.event.core.exception.EventBrokerConfigurationException;\n+import org.wso2.carbon.event.core.sharedmemory.util.SharedMemoryCacheUtil;\n+import org.wso2.carbon.event.core.util.EventBrokerConstants;\n+import org.wso2.carbon.event.core.delivery.DeliveryManager;\n+import org.wso2.carbon.event.core.delivery.MatchingManager;\n+import org.wso2.carbon.event.core.exception.EventBrokerException;\n+import org.wso2.carbon.event.core.internal.delivery.Worker;\n+import org.wso2.carbon.event.core.internal.util.JavaUtil;\n+import org.wso2.carbon.event.core.internal.util.EventBrokerHolder;\n+import org.wso2.carbon.event.core.notify.NotificationManager;\n+import org.wso2.carbon.event.core.subscription.Subscription;\n+import org.wso2.carbon.user.api.UserRealm;\n+import org.wso2.carbon.user.api.UserStoreException;\n+import org.wso2.carbon.context.CarbonContext;\n+import org.wso2.carbon.CarbonConstants;\n+\n+import javax.cache.Cache;\n+\n+import java.util.List;\n+import java.util.concurrent.ExecutorService;\n+\n+/**\n+ * shared memory implementation of the delivery manager.\n+ */\n+public class SharedMemoryDeliveryManager implements DeliveryManager {\n+\n+\tprivate static final Log log = LogFactory.getLog(SharedMemoryDeliveryManager.class);\n+    private ExecutorService executor;\n+    private NotificationManager notificationManager;\n+    private String topicStoragePath;\n+    private EventBroker eventBroker;\n+\n+    public SharedMemoryDeliveryManager(ExecutorService executor, String topicStoragePath) {\n+        this.executor = executor;\n+        this.topicStoragePath = topicStoragePath;\n+    }\n+\n+    public void subscribe(Subscription subscription) throws EventBrokerException {\n+\n+       String resourcePath = JavaUtil.getResourcePath(subscription.getTopicName(), this.topicStoragePath);\n+        try {\n+            UserRealm userRealm =\n+                    EventBrokerHolder.getInstance().getRealmService().getTenantUserRealm\n+                                               (CarbonContext.getThreadLocalCarbonContext().getTenantId());\n+            String userName = subscription.getOwner();\n+\n+            // trim the domain part if it is there.\n+            if (userName.indexOf('@') != -1){\n+                userName = userName.substring(0, userName.indexOf('@'));\n+            }\n+            if (userName.equals(CarbonConstants.REGISTRY_SYSTEM_USERNAME) ||\n+                    userRealm.getAuthorizationManager().isUserAuthorized(\n+                        userName,\n+                        resourcePath,\n+                        EventBrokerConstants.EB_PERMISSION_SUBSCRIBE)){\n+                getMatchingManager().addSubscription(subscription);\n+            } else {\n+                throw new EventBrokerException(\"User \" + CarbonContext.getThreadLocalCarbonContext().getUsername()\n+                               + \" is not allowed to subscribes to \" + subscription.getTopicName());\n+            }\n+        } catch (UserStoreException e) {\n+            throw new EventBrokerException(\"Can not access the user store manager\",e);\n+        }\n+\n+    }\n+\n+    public void setNotificationManager(NotificationManager notificationManager) {\n+       this.notificationManager = notificationManager;\n+    }\n+\n+    public void publish(Message message, String topicName, int deliveryMode) throws EventBrokerException {\n+\n+        String resourcePath = JavaUtil.getResourcePath(topicName, this.topicStoragePath);\n+        try {\n+            UserRealm userRealm =\n+                    EventBrokerHolder.getInstance().getRealmService().getTenantUserRealm\n+                            (CarbonContext.getThreadLocalCarbonContext().getTenantId());\n+            String userName = CarbonContext.getThreadLocalCarbonContext().getUsername();\n+            \n+            if (userName == null){\n+                userName = CarbonConstants.REGISTRY_SYSTEM_USERNAME;\n+            }\n+            if (userName.equals(CarbonConstants.REGISTRY_SYSTEM_USERNAME) ||\n+                    userRealm.getAuthorizationManager().isUserAuthorized(\n+                        userName,\n+                        resourcePath,\n+                        EventBrokerConstants.EB_PERMISSION_PUBLISH)) {\n+                List<Subscription> subscriptions = getMatchingManager().getMatchingSubscriptions(topicName);","path":"components/event/org.wso2.carbon.event.core/src/main/java/org/wso2/carbon/event/core/sharedmemory/SharedMemoryDeliveryManager.java","position":113,"original_position":113,"commit_id":"5e1beb2f83c1f8f22f2bb8c5a02adde9746671ae","original_commit_id":"5e1beb2f83c1f8f22f2bb8c5a02adde9746671ae","user":{"login":"daneshk","id":8402398,"avatar_url":"https://avatars.githubusercontent.com/u/8402398?v=3","gravatar_id":"","url":"https://api.github.com/users/daneshk","html_url":"https://github.com/daneshk","followers_url":"https://api.github.com/users/daneshk/followers","following_url":"https://api.github.com/users/daneshk/following{/other_user}","gists_url":"https://api.github.com/users/daneshk/gists{/gist_id}","starred_url":"https://api.github.com/users/daneshk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daneshk/subscriptions","organizations_url":"https://api.github.com/users/daneshk/orgs","repos_url":"https://api.github.com/users/daneshk/repos","events_url":"https://api.github.com/users/daneshk/events{/privacy}","received_events_url":"https://api.github.com/users/daneshk/received_events","type":"User","site_admin":false},"body":"corrected in PR https://github.com/wso2-dev/carbon-utils/pull/45","created_at":"2015-01-11T17:07:25Z","updated_at":"2015-01-11T17:07:25Z","html_url":"https://github.com/wso2-dev/carbon-utils/pull/32#discussion_r22768197","pull_request_url":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/32","_links":{"self":{"href":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/comments/22768197"},"html":{"href":"https://github.com/wso2-dev/carbon-utils/pull/32#discussion_r22768197"},"pull_request":{"href":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/32"}}},"pull_request":{"url":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/32","id":24126024,"html_url":"https://github.com/wso2-dev/carbon-utils/pull/32","diff_url":"https://github.com/wso2-dev/carbon-utils/pull/32.diff","patch_url":"https://github.com/wso2-dev/carbon-utils/pull/32.patch","issue_url":"https://api.github.com/repos/wso2-dev/carbon-utils/issues/32","number":32,"state":"closed","locked":false,"title":"Change cluster notification impl to support new HZ patch","user":{"login":"daneshk","id":8402398,"avatar_url":"https://avatars.githubusercontent.com/u/8402398?v=3","gravatar_id":"","url":"https://api.github.com/users/daneshk","html_url":"https://github.com/daneshk","followers_url":"https://api.github.com/users/daneshk/followers","following_url":"https://api.github.com/users/daneshk/following{/other_user}","gists_url":"https://api.github.com/users/daneshk/gists{/gist_id}","starred_url":"https://api.github.com/users/daneshk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daneshk/subscriptions","organizations_url":"https://api.github.com/users/daneshk/orgs","repos_url":"https://api.github.com/users/daneshk/repos","events_url":"https://api.github.com/users/daneshk/events{/privacy}","received_events_url":"https://api.github.com/users/daneshk/received_events","type":"User","site_admin":false},"body":"Change cluster notification impl to support new HZ patch","created_at":"2014-11-10T04:12:04Z","updated_at":"2015-01-11T17:07:25Z","closed_at":"2014-11-12T12:26:02Z","merged_at":"2014-11-12T12:26:02Z","merge_commit_sha":"7dfc9da6f929f924ec1394221f7393d3e23e5add","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/32/commits","review_comments_url":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/32/comments","review_comment_url":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/comments/{number}","comments_url":"https://api.github.com/repos/wso2-dev/carbon-utils/issues/32/comments","statuses_url":"https://api.github.com/repos/wso2-dev/carbon-utils/statuses/5e1beb2f83c1f8f22f2bb8c5a02adde9746671ae","head":{"label":"daneshk:MERGE-FIX","ref":"MERGE-FIX","sha":"5e1beb2f83c1f8f22f2bb8c5a02adde9746671ae","user":{"login":"daneshk","id":8402398,"avatar_url":"https://avatars.githubusercontent.com/u/8402398?v=3","gravatar_id":"","url":"https://api.github.com/users/daneshk","html_url":"https://github.com/daneshk","followers_url":"https://api.github.com/users/daneshk/followers","following_url":"https://api.github.com/users/daneshk/following{/other_user}","gists_url":"https://api.github.com/users/daneshk/gists{/gist_id}","starred_url":"https://api.github.com/users/daneshk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daneshk/subscriptions","organizations_url":"https://api.github.com/users/daneshk/orgs","repos_url":"https://api.github.com/users/daneshk/repos","events_url":"https://api.github.com/users/daneshk/events{/privacy}","received_events_url":"https://api.github.com/users/daneshk/received_events","type":"User","site_admin":false},"repo":{"id":23860027,"name":"carbon-utils","full_name":"daneshk/carbon-utils","owner":{"login":"daneshk","id":8402398,"avatar_url":"https://avatars.githubusercontent.com/u/8402398?v=3","gravatar_id":"","url":"https://api.github.com/users/daneshk","html_url":"https://github.com/daneshk","followers_url":"https://api.github.com/users/daneshk/followers","following_url":"https://api.github.com/users/daneshk/following{/other_user}","gists_url":"https://api.github.com/users/daneshk/gists{/gist_id}","starred_url":"https://api.github.com/users/daneshk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daneshk/subscriptions","organizations_url":"https://api.github.com/users/daneshk/orgs","repos_url":"https://api.github.com/users/daneshk/repos","events_url":"https://api.github.com/users/daneshk/events{/privacy}","received_events_url":"https://api.github.com/users/daneshk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/daneshk/carbon-utils","description":"","fork":true,"url":"https://api.github.com/repos/daneshk/carbon-utils","forks_url":"https://api.github.com/repos/daneshk/carbon-utils/forks","keys_url":"https://api.github.com/repos/daneshk/carbon-utils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/daneshk/carbon-utils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/daneshk/carbon-utils/teams","hooks_url":"https://api.github.com/repos/daneshk/carbon-utils/hooks","issue_events_url":"https://api.github.com/repos/daneshk/carbon-utils/issues/events{/number}","events_url":"https://api.github.com/repos/daneshk/carbon-utils/events","assignees_url":"https://api.github.com/repos/daneshk/carbon-utils/assignees{/user}","branches_url":"https://api.github.com/repos/daneshk/carbon-utils/branches{/branch}","tags_url":"https://api.github.com/repos/daneshk/carbon-utils/tags","blobs_url":"https://api.github.com/repos/daneshk/carbon-utils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/daneshk/carbon-utils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/daneshk/carbon-utils/git/refs{/sha}","trees_url":"https://api.github.com/repos/daneshk/carbon-utils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/daneshk/carbon-utils/statuses/{sha}","languages_url":"https://api.github.com/repos/daneshk/carbon-utils/languages","stargazers_url":"https://api.github.com/repos/daneshk/carbon-utils/stargazers","contributors_url":"https://api.github.com/repos/daneshk/carbon-utils/contributors","subscribers_url":"https://api.github.com/repos/daneshk/carbon-utils/subscribers","subscription_url":"https://api.github.com/repos/daneshk/carbon-utils/subscription","commits_url":"https://api.github.com/repos/daneshk/carbon-utils/commits{/sha}","git_commits_url":"https://api.github.com/repos/daneshk/carbon-utils/git/commits{/sha}","comments_url":"https://api.github.com/repos/daneshk/carbon-utils/comments{/number}","issue_comment_url":"https://api.github.com/repos/daneshk/carbon-utils/issues/comments/{number}","contents_url":"https://api.github.com/repos/daneshk/carbon-utils/contents/{+path}","compare_url":"https://api.github.com/repos/daneshk/carbon-utils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/daneshk/carbon-utils/merges","archive_url":"https://api.github.com/repos/daneshk/carbon-utils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/daneshk/carbon-utils/downloads","issues_url":"https://api.github.com/repos/daneshk/carbon-utils/issues{/number}","pulls_url":"https://api.github.com/repos/daneshk/carbon-utils/pulls{/number}","milestones_url":"https://api.github.com/repos/daneshk/carbon-utils/milestones{/number}","notifications_url":"https://api.github.com/repos/daneshk/carbon-utils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/daneshk/carbon-utils/labels{/name}","releases_url":"https://api.github.com/repos/daneshk/carbon-utils/releases{/id}","created_at":"2014-09-10T03:56:24Z","updated_at":"2014-10-09T15:49:50Z","pushed_at":"2015-01-11T17:06:03Z","git_url":"git://github.com/daneshk/carbon-utils.git","ssh_url":"git@github.com:daneshk/carbon-utils.git","clone_url":"https://github.com/daneshk/carbon-utils.git","svn_url":"https://github.com/daneshk/carbon-utils","homepage":null,"size":6068,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"wso2-dev:master","ref":"master","sha":"6b7dcc926446c77d0f037554140f7a5c5ceef187","user":{"login":"wso2-dev","id":6744733,"avatar_url":"https://avatars.githubusercontent.com/u/6744733?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2-dev","html_url":"https://github.com/wso2-dev","followers_url":"https://api.github.com/users/wso2-dev/followers","following_url":"https://api.github.com/users/wso2-dev/following{/other_user}","gists_url":"https://api.github.com/users/wso2-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2-dev/subscriptions","organizations_url":"https://api.github.com/users/wso2-dev/orgs","repos_url":"https://api.github.com/users/wso2-dev/repos","events_url":"https://api.github.com/users/wso2-dev/events{/privacy}","received_events_url":"https://api.github.com/users/wso2-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":20399658,"name":"carbon-utils","full_name":"wso2-dev/carbon-utils","owner":{"login":"wso2-dev","id":6744733,"avatar_url":"https://avatars.githubusercontent.com/u/6744733?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2-dev","html_url":"https://github.com/wso2-dev","followers_url":"https://api.github.com/users/wso2-dev/followers","following_url":"https://api.github.com/users/wso2-dev/following{/other_user}","gists_url":"https://api.github.com/users/wso2-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2-dev/subscriptions","organizations_url":"https://api.github.com/users/wso2-dev/orgs","repos_url":"https://api.github.com/users/wso2-dev/repos","events_url":"https://api.github.com/users/wso2-dev/events{/privacy}","received_events_url":"https://api.github.com/users/wso2-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wso2-dev/carbon-utils","description":"","fork":true,"url":"https://api.github.com/repos/wso2-dev/carbon-utils","forks_url":"https://api.github.com/repos/wso2-dev/carbon-utils/forks","keys_url":"https://api.github.com/repos/wso2-dev/carbon-utils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2-dev/carbon-utils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2-dev/carbon-utils/teams","hooks_url":"https://api.github.com/repos/wso2-dev/carbon-utils/hooks","issue_events_url":"https://api.github.com/repos/wso2-dev/carbon-utils/issues/events{/number}","events_url":"https://api.github.com/repos/wso2-dev/carbon-utils/events","assignees_url":"https://api.github.com/repos/wso2-dev/carbon-utils/assignees{/user}","branches_url":"https://api.github.com/repos/wso2-dev/carbon-utils/branches{/branch}","tags_url":"https://api.github.com/repos/wso2-dev/carbon-utils/tags","blobs_url":"https://api.github.com/repos/wso2-dev/carbon-utils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2-dev/carbon-utils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2-dev/carbon-utils/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2-dev/carbon-utils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2-dev/carbon-utils/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2-dev/carbon-utils/languages","stargazers_url":"https://api.github.com/repos/wso2-dev/carbon-utils/stargazers","contributors_url":"https://api.github.com/repos/wso2-dev/carbon-utils/contributors","subscribers_url":"https://api.github.com/repos/wso2-dev/carbon-utils/subscribers","subscription_url":"https://api.github.com/repos/wso2-dev/carbon-utils/subscription","commits_url":"https://api.github.com/repos/wso2-dev/carbon-utils/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2-dev/carbon-utils/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2-dev/carbon-utils/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2-dev/carbon-utils/issues/comments/{number}","contents_url":"https://api.github.com/repos/wso2-dev/carbon-utils/contents/{+path}","compare_url":"https://api.github.com/repos/wso2-dev/carbon-utils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2-dev/carbon-utils/merges","archive_url":"https://api.github.com/repos/wso2-dev/carbon-utils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2-dev/carbon-utils/downloads","issues_url":"https://api.github.com/repos/wso2-dev/carbon-utils/issues{/number}","pulls_url":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2-dev/carbon-utils/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2-dev/carbon-utils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2-dev/carbon-utils/labels{/name}","releases_url":"https://api.github.com/repos/wso2-dev/carbon-utils/releases{/id}","created_at":"2014-06-02T10:01:45Z","updated_at":"2015-01-10T05:53:08Z","pushed_at":"2015-01-10T05:53:04Z","git_url":"git://github.com/wso2-dev/carbon-utils.git","ssh_url":"git@github.com:wso2-dev/carbon-utils.git","clone_url":"https://github.com/wso2-dev/carbon-utils.git","svn_url":"https://github.com/wso2-dev/carbon-utils","homepage":null,"size":6487,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":5,"forks":31,"open_issues":5,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/32"},"html":{"href":"https://github.com/wso2-dev/carbon-utils/pull/32"},"issue":{"href":"https://api.github.com/repos/wso2-dev/carbon-utils/issues/32"},"comments":{"href":"https://api.github.com/repos/wso2-dev/carbon-utils/issues/32/comments"},"review_comments":{"href":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/32/comments"},"review_comment":{"href":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/wso2-dev/carbon-utils/pulls/32/commits"},"statuses":{"href":"https://api.github.com/repos/wso2-dev/carbon-utils/statuses/5e1beb2f83c1f8f22f2bb8c5a02adde9746671ae"}}}}