{"action":"created","comment":{"url":"https://api.github.com/repos/wso2/product-af/pulls/comments/42018303","id":42018303,"diff_hunk":"@@ -0,0 +1,99 @@\n+/*\r\n+ *\r\n+ *  Copyright 2014 WSO2, Inc. (http://wso2.com)\r\n+ *\r\n+ *  Licensed under the Apache License, Version 2.0 (the \"License\");\r\n+ *  you may not use this file except in compliance with the License.\r\n+ *  You may obtain a copy of the License at\r\n+ *\r\n+ *  http://www.apache.org/licenses/LICENSE-2.0\r\n+ *\r\n+ *  Unless required by applicable law or agreed to in writing, software\r\n+ *  distributed under the License is distributed on an \"AS IS\" BASIS,\r\n+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n+ *  See the License for the specific language governing permissions and\r\n+ *  limitations under the License.\r\n+ *\r\n+ */\r\n+\r\n+package org.wso2.carbon.appfactory.resource.mgt.listeners;\r\n+\r\n+import org.apache.commons.logging.Log;\r\n+import org.apache.commons.logging.LogFactory;\r\n+import org.wso2.carbon.CarbonConstants;\r\n+import org.wso2.carbon.appfactory.common.AppFactoryConstants;\r\n+import org.wso2.carbon.appfactory.common.AppFactoryException;\r\n+import org.wso2.carbon.appfactory.eventing.AppFactoryEventException;\r\n+import org.wso2.carbon.appfactory.eventing.utils.Util;\r\n+\r\n+import javax.jms.*;\r\n+import javax.naming.Context;\r\n+import javax.naming.InitialContext;\r\n+import javax.naming.NamingException;\r\n+import java.util.Properties;\r\n+\r\n+/**\r\n+ * Durable subscriber for topics  in MB - tenant creation.\r\n+ * TenantCreatioMessageListener is set as the message listener\r\n+ */\r\n+public class TenantCreationDurableSubscriber {\r\n+    private static Log log = LogFactory.getLog(TenantCreationDurableSubscriber.class);\r\n+    private String subscriptionId;\r\n+    private String topicName;\r\n+\r\n+    public TenantCreationDurableSubscriber(String topicName, String subscriptionId)\r\n+            throws AppFactoryException {\r\n+        this.topicName = topicName;\r\n+\t    this.subscriptionId = subscriptionId;\r\n+        try {\r\n+            subscribe();\r\n+        } catch (AppFactoryEventException e) {\r\n+\t        throw new AppFactoryException(\"Subscriber activation failed for topic\" + topicName + \" and subscription \" +\r\n+\t                                      \"id :  \" + subscriptionId, e);\r\n+        }\r\n+    }\r\n+\r\n+    /**\r\n+     * Subscribe as a durable subscriber to the topic.\r\n+     *\r\n+     * @throws AppFactoryEventException\r\n+     */\r\n+    public void subscribe() throws AppFactoryEventException {\r\n+        Properties properties = new Properties();\r\n+        properties.put(Context.INITIAL_CONTEXT_FACTORY, AppFactoryConstants.ANDES_ICF);\r\n+        properties.put(AppFactoryConstants.CF_NAME_PREFIX + AppFactoryConstants.CF_NAME, Util.getTCPConnectionURL());\r\n+        properties.put(CarbonConstants.REQUEST_BASE_CONTEXT, \"true\");\r\n+        properties.put(AppFactoryConstants.TOPIC, topicName);\r\n+        TopicConnectionFactory connFactory;\r\n+        TopicConnection topicConnection;\r\n+        TopicSession topicSession;\r\n+        TopicSubscriber topicSubscriber;\r\n+        InitialContext ctx;\r\n+        try {\r\n+            ctx = new InitialContext(properties);\r\n+            connFactory = (TopicConnectionFactory) ctx.lookup(AppFactoryConstants.CF_NAME);\r\n+            topicConnection = connFactory.createTopicConnection();\r\n+            topicSession = topicConnection.createTopicSession(false, TopicSession.CLIENT_ACKNOWLEDGE);\r\n+            Topic topic;\r\n+            try {\r\n+                topic = (Topic) ctx.lookup(topicName);\r\n+            } catch (NamingException e) {\r\n+                topic = topicSession.createTopic(topicName);\r","path":"modules/components/org.wso2.carbon.appfactory.resource.mgt/src/main/java/org/wso2/carbon/appfactory/resource/mgt/listeners/TenantCreationDurableSubscriber.java","position":81,"original_position":81,"commit_id":"886d97817751fac17b38ff989ac20324f8fc4b34","original_commit_id":"886d97817751fac17b38ff989ac20324f8fc4b34","user":{"login":"hisamith","id":3128241,"avatar_url":"https://avatars.githubusercontent.com/u/3128241?v=3","gravatar_id":"","url":"https://api.github.com/users/hisamith","html_url":"https://github.com/hisamith","followers_url":"https://api.github.com/users/hisamith/followers","following_url":"https://api.github.com/users/hisamith/following{/other_user}","gists_url":"https://api.github.com/users/hisamith/gists{/gist_id}","starred_url":"https://api.github.com/users/hisamith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hisamith/subscriptions","organizations_url":"https://api.github.com/users/hisamith/orgs","repos_url":"https://api.github.com/users/hisamith/repos","events_url":"https://api.github.com/users/hisamith/events{/privacy}","received_events_url":"https://api.github.com/users/hisamith/received_events","type":"User","site_admin":false},"body":"Why we are not logging the exception here? If it is not needed, add comment stating the reason. ","created_at":"2015-10-14T16:39:06Z","updated_at":"2015-10-14T16:39:06Z","html_url":"https://github.com/wso2/product-af/pull/650#discussion_r42018303","pull_request_url":"https://api.github.com/repos/wso2/product-af/pulls/650","_links":{"self":{"href":"https://api.github.com/repos/wso2/product-af/pulls/comments/42018303"},"html":{"href":"https://github.com/wso2/product-af/pull/650#discussion_r42018303"},"pull_request":{"href":"https://api.github.com/repos/wso2/product-af/pulls/650"}}},"pull_request":{"url":"https://api.github.com/repos/wso2/product-af/pulls/650","id":46986054,"html_url":"https://github.com/wso2/product-af/pull/650","diff_url":"https://github.com/wso2/product-af/pull/650.diff","patch_url":"https://github.com/wso2/product-af/pull/650.patch","issue_url":"https://api.github.com/repos/wso2/product-af/issues/650","number":650,"state":"closed","locked":false,"title":"Dockersupport 1.1","user":{"login":"amalkasubasinghe","id":238594,"avatar_url":"https://avatars.githubusercontent.com/u/238594?v=3","gravatar_id":"","url":"https://api.github.com/users/amalkasubasinghe","html_url":"https://github.com/amalkasubasinghe","followers_url":"https://api.github.com/users/amalkasubasinghe/followers","following_url":"https://api.github.com/users/amalkasubasinghe/following{/other_user}","gists_url":"https://api.github.com/users/amalkasubasinghe/gists{/gist_id}","starred_url":"https://api.github.com/users/amalkasubasinghe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amalkasubasinghe/subscriptions","organizations_url":"https://api.github.com/users/amalkasubasinghe/orgs","repos_url":"https://api.github.com/users/amalkasubasinghe/repos","events_url":"https://api.github.com/users/amalkasubasinghe/events{/privacy}","received_events_url":"https://api.github.com/users/amalkasubasinghe/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-07T04:28:28Z","updated_at":"2015-10-14T16:39:06Z","closed_at":"2015-10-07T04:28:32Z","merged_at":"2015-10-07T04:28:32Z","merge_commit_sha":"d20d5dc71ebea0936d7f5c7fe14dea1bf4e8f2d2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wso2/product-af/pulls/650/commits","review_comments_url":"https://api.github.com/repos/wso2/product-af/pulls/650/comments","review_comment_url":"https://api.github.com/repos/wso2/product-af/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wso2/product-af/issues/650/comments","statuses_url":"https://api.github.com/repos/wso2/product-af/statuses/886d97817751fac17b38ff989ac20324f8fc4b34","head":{"label":"amalkasubasinghe:dockersupport-1.1","ref":"dockersupport-1.1","sha":"886d97817751fac17b38ff989ac20324f8fc4b34","user":{"login":"amalkasubasinghe","id":238594,"avatar_url":"https://avatars.githubusercontent.com/u/238594?v=3","gravatar_id":"","url":"https://api.github.com/users/amalkasubasinghe","html_url":"https://github.com/amalkasubasinghe","followers_url":"https://api.github.com/users/amalkasubasinghe/followers","following_url":"https://api.github.com/users/amalkasubasinghe/following{/other_user}","gists_url":"https://api.github.com/users/amalkasubasinghe/gists{/gist_id}","starred_url":"https://api.github.com/users/amalkasubasinghe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amalkasubasinghe/subscriptions","organizations_url":"https://api.github.com/users/amalkasubasinghe/orgs","repos_url":"https://api.github.com/users/amalkasubasinghe/repos","events_url":"https://api.github.com/users/amalkasubasinghe/events{/privacy}","received_events_url":"https://api.github.com/users/amalkasubasinghe/received_events","type":"User","site_admin":false},"repo":{"id":39772049,"name":"product-af","full_name":"amalkasubasinghe/product-af","owner":{"login":"amalkasubasinghe","id":238594,"avatar_url":"https://avatars.githubusercontent.com/u/238594?v=3","gravatar_id":"","url":"https://api.github.com/users/amalkasubasinghe","html_url":"https://github.com/amalkasubasinghe","followers_url":"https://api.github.com/users/amalkasubasinghe/followers","following_url":"https://api.github.com/users/amalkasubasinghe/following{/other_user}","gists_url":"https://api.github.com/users/amalkasubasinghe/gists{/gist_id}","starred_url":"https://api.github.com/users/amalkasubasinghe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amalkasubasinghe/subscriptions","organizations_url":"https://api.github.com/users/amalkasubasinghe/orgs","repos_url":"https://api.github.com/users/amalkasubasinghe/repos","events_url":"https://api.github.com/users/amalkasubasinghe/events{/privacy}","received_events_url":"https://api.github.com/users/amalkasubasinghe/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/amalkasubasinghe/product-af","description":"","fork":true,"url":"https://api.github.com/repos/amalkasubasinghe/product-af","forks_url":"https://api.github.com/repos/amalkasubasinghe/product-af/forks","keys_url":"https://api.github.com/repos/amalkasubasinghe/product-af/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amalkasubasinghe/product-af/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amalkasubasinghe/product-af/teams","hooks_url":"https://api.github.com/repos/amalkasubasinghe/product-af/hooks","issue_events_url":"https://api.github.com/repos/amalkasubasinghe/product-af/issues/events{/number}","events_url":"https://api.github.com/repos/amalkasubasinghe/product-af/events","assignees_url":"https://api.github.com/repos/amalkasubasinghe/product-af/assignees{/user}","branches_url":"https://api.github.com/repos/amalkasubasinghe/product-af/branches{/branch}","tags_url":"https://api.github.com/repos/amalkasubasinghe/product-af/tags","blobs_url":"https://api.github.com/repos/amalkasubasinghe/product-af/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amalkasubasinghe/product-af/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amalkasubasinghe/product-af/git/refs{/sha}","trees_url":"https://api.github.com/repos/amalkasubasinghe/product-af/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amalkasubasinghe/product-af/statuses/{sha}","languages_url":"https://api.github.com/repos/amalkasubasinghe/product-af/languages","stargazers_url":"https://api.github.com/repos/amalkasubasinghe/product-af/stargazers","contributors_url":"https://api.github.com/repos/amalkasubasinghe/product-af/contributors","subscribers_url":"https://api.github.com/repos/amalkasubasinghe/product-af/subscribers","subscription_url":"https://api.github.com/repos/amalkasubasinghe/product-af/subscription","commits_url":"https://api.github.com/repos/amalkasubasinghe/product-af/commits{/sha}","git_commits_url":"https://api.github.com/repos/amalkasubasinghe/product-af/git/commits{/sha}","comments_url":"https://api.github.com/repos/amalkasubasinghe/product-af/comments{/number}","issue_comment_url":"https://api.github.com/repos/amalkasubasinghe/product-af/issues/comments{/number}","contents_url":"https://api.github.com/repos/amalkasubasinghe/product-af/contents/{+path}","compare_url":"https://api.github.com/repos/amalkasubasinghe/product-af/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amalkasubasinghe/product-af/merges","archive_url":"https://api.github.com/repos/amalkasubasinghe/product-af/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amalkasubasinghe/product-af/downloads","issues_url":"https://api.github.com/repos/amalkasubasinghe/product-af/issues{/number}","pulls_url":"https://api.github.com/repos/amalkasubasinghe/product-af/pulls{/number}","milestones_url":"https://api.github.com/repos/amalkasubasinghe/product-af/milestones{/number}","notifications_url":"https://api.github.com/repos/amalkasubasinghe/product-af/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amalkasubasinghe/product-af/labels{/name}","releases_url":"https://api.github.com/repos/amalkasubasinghe/product-af/releases{/id}","created_at":"2015-07-27T11:58:02Z","updated_at":"2015-07-27T11:58:27Z","pushed_at":"2015-10-14T13:17:41Z","git_url":"git://github.com/amalkasubasinghe/product-af.git","ssh_url":"git@github.com:amalkasubasinghe/product-af.git","clone_url":"https://github.com/amalkasubasinghe/product-af.git","svn_url":"https://github.com/amalkasubasinghe/product-af","homepage":null,"size":400057,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"wso2:dockersupport-1.1","ref":"dockersupport-1.1","sha":"6c7528074cc719c64f3e0b3f1b9f46c7cc91096d","user":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"repo":{"id":17127687,"name":"product-af","full_name":"wso2/product-af","owner":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wso2/product-af","description":"","fork":false,"url":"https://api.github.com/repos/wso2/product-af","forks_url":"https://api.github.com/repos/wso2/product-af/forks","keys_url":"https://api.github.com/repos/wso2/product-af/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2/product-af/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2/product-af/teams","hooks_url":"https://api.github.com/repos/wso2/product-af/hooks","issue_events_url":"https://api.github.com/repos/wso2/product-af/issues/events{/number}","events_url":"https://api.github.com/repos/wso2/product-af/events","assignees_url":"https://api.github.com/repos/wso2/product-af/assignees{/user}","branches_url":"https://api.github.com/repos/wso2/product-af/branches{/branch}","tags_url":"https://api.github.com/repos/wso2/product-af/tags","blobs_url":"https://api.github.com/repos/wso2/product-af/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2/product-af/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2/product-af/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2/product-af/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2/product-af/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2/product-af/languages","stargazers_url":"https://api.github.com/repos/wso2/product-af/stargazers","contributors_url":"https://api.github.com/repos/wso2/product-af/contributors","subscribers_url":"https://api.github.com/repos/wso2/product-af/subscribers","subscription_url":"https://api.github.com/repos/wso2/product-af/subscription","commits_url":"https://api.github.com/repos/wso2/product-af/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2/product-af/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2/product-af/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2/product-af/issues/comments{/number}","contents_url":"https://api.github.com/repos/wso2/product-af/contents/{+path}","compare_url":"https://api.github.com/repos/wso2/product-af/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2/product-af/merges","archive_url":"https://api.github.com/repos/wso2/product-af/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2/product-af/downloads","issues_url":"https://api.github.com/repos/wso2/product-af/issues{/number}","pulls_url":"https://api.github.com/repos/wso2/product-af/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2/product-af/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2/product-af/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2/product-af/labels{/name}","releases_url":"https://api.github.com/repos/wso2/product-af/releases{/id}","created_at":"2014-02-24T06:44:40Z","updated_at":"2015-07-16T03:54:06Z","pushed_at":"2015-10-14T13:18:13Z","git_url":"git://github.com/wso2/product-af.git","ssh_url":"git@github.com:wso2/product-af.git","clone_url":"https://github.com/wso2/product-af.git","svn_url":"https://github.com/wso2/product-af","homepage":null,"size":418072,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":39,"mirror_url":null,"open_issues_count":18,"forks":39,"open_issues":18,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wso2/product-af/pulls/650"},"html":{"href":"https://github.com/wso2/product-af/pull/650"},"issue":{"href":"https://api.github.com/repos/wso2/product-af/issues/650"},"comments":{"href":"https://api.github.com/repos/wso2/product-af/issues/650/comments"},"review_comments":{"href":"https://api.github.com/repos/wso2/product-af/pulls/650/comments"},"review_comment":{"href":"https://api.github.com/repos/wso2/product-af/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wso2/product-af/pulls/650/commits"},"statuses":{"href":"https://api.github.com/repos/wso2/product-af/statuses/886d97817751fac17b38ff989ac20324f8fc4b34"}}}}