{"action":"created","comment":{"url":"https://api.github.com/repos/camelot-framework/camelot/pulls/comments/46099293","id":46099293,"diff_hunk":"@@ -0,0 +1,117 @@\n+package ru.yandex.qatools.camelot.mongodb;\n+\n+import com.mongodb.MongoClient;\n+import org.apache.camel.CamelContext;\n+import org.apache.camel.CamelContextAware;\n+import org.apache.camel.LoggingLevel;\n+import org.apache.camel.builder.RouteBuilder;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+import ru.qatools.mongodb.MongoTailingQueue;\n+import ru.yandex.qatools.camelot.api.ClientMessageSender;\n+import ru.yandex.qatools.camelot.api.ClientSendersProvider;\n+import ru.yandex.qatools.camelot.api.EventProducer;\n+import ru.yandex.qatools.camelot.common.MessagesSerializer;\n+import ru.yandex.qatools.camelot.common.PluginUriBuilder;\n+\n+import java.io.Serializable;\n+import java.util.concurrent.ExecutorService;\n+\n+import static java.util.concurrent.Executors.newFixedThreadPool;\n+import static java.util.concurrent.Executors.newSingleThreadExecutor;\n+import static ru.yandex.qatools.camelot.api.Constants.Headers.*;\n+import static ru.yandex.qatools.camelot.util.MapUtil.map;\n+import static ru.yandex.qatools.camelot.util.ServiceUtil.initEventProducer;\n+\n+/**\n+ * @author Ilya Sadykov\n+ */\n+public class MongodbClientSendersProvider implements ClientSendersProvider, CamelContextAware {\n+    private static final String MONGODB_FRONTEND_URI = \"direct:mongodb.frontend.notify\";\n+    private final static Logger LOGGER = LoggerFactory.getLogger(MongodbClientSendersProvider.class);\n+    private static final int DEFAULT_POOL_SIZE = 10;\n+    private final ExecutorService senderPool;\n+    private final MongoTailingQueue<MongoQueueMessage> queue;\n+    private final MessagesSerializer serializer;\n+    private final String feBroadcastUri;\n+    private CamelContext camelContext;\n+\n+    public MongodbClientSendersProvider(MessagesSerializer serializer, PluginUriBuilder uriBuilder,\n+                                        MongoClient mongoClient, String dbName, String colName, long maxSize) {\n+        this(serializer, uriBuilder, DEFAULT_POOL_SIZE, mongoClient, dbName, colName, maxSize);\n+    }\n+\n+    public MongodbClientSendersProvider(MessagesSerializer serializer, PluginUriBuilder uriBuilder, int poolSize,\n+                                        MongoClient mongoClient, String dbName, String colName, long maxSize) {\n+        this.queue = new MongoTailingQueue<>(MongoQueueMessage.class, mongoClient, dbName, colName, maxSize);\n+        queue.init();\n+        this.serializer = serializer;\n+        this.feBroadcastUri = uriBuilder.frontendBroadcastUri();\n+        this.senderPool = newFixedThreadPool(poolSize);\n+    }\n+\n+    @Override\n+    public ClientMessageSender getSender(String topic, String pluginId, String feNotifyUri) {\n+        return (t, m) -> senderPool.submit(\n+                () -> queue.add(new MongoQueueMessage(pluginId, m, topic))\n+        );\n+    }\n+\n+    @Override\n+    public CamelContext getCamelContext() {\n+        return camelContext;\n+    }\n+\n+    @Override\n+    public void setCamelContext(CamelContext camelContext) {\n+        this.camelContext = camelContext;\n+        initPoller(camelContext);\n+        initRoutes(camelContext);\n+    }\n+\n+    private void initRoutes(CamelContext camelContext) {\n+        try {\n+            LOGGER.info(\"Initializing MongoDB queue routes\");\n+            camelContext.addRoutes(new RouteBuilder() {\n+                @Override\n+                public void configure() throws Exception {\n+                    from(MONGODB_FRONTEND_URI).\n+                            log(LoggingLevel.DEBUG, \"MongoDB frontend notify message {headers.bodyClass}\")\n+                            .to(feBroadcastUri);\n+                }\n+            });\n+        } catch (Exception e) {\n+            throw new RuntimeException(\"Failed to initialize additional routes for MongoDB client notify support!\", e);","path":"camelot-ext/camelot-mongodb/src/main/java/ru/yandex/qatools/camelot/mongodb/MongodbClientSendersProvider.java","position":84,"original_position":84,"commit_id":"c417e026e03fb3e87f133e6644f167e655f38028","original_commit_id":"c417e026e03fb3e87f133e6644f167e655f38028","user":{"login":"qatools-ci","id":4466920,"avatar_url":"https://avatars.githubusercontent.com/u/4466920?v=3","gravatar_id":"","url":"https://api.github.com/users/qatools-ci","html_url":"https://github.com/qatools-ci","followers_url":"https://api.github.com/users/qatools-ci/followers","following_url":"https://api.github.com/users/qatools-ci/following{/other_user}","gists_url":"https://api.github.com/users/qatools-ci/gists{/gist_id}","starred_url":"https://api.github.com/users/qatools-ci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qatools-ci/subscriptions","organizations_url":"https://api.github.com/users/qatools-ci/orgs","repos_url":"https://api.github.com/users/qatools-ci/repos","events_url":"https://api.github.com/users/qatools-ci/events{/privacy}","received_events_url":"https://api.github.com/users/qatools-ci/received_events","type":"User","site_admin":false},"body":"![MAJOR](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/severity-major.png) Define and throw a dedicated exception instead of using a generic one. [![rule](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/rule.png)](http://nemo.sonarqube.org/coding_rules#rule_key=squid%3AS00112)\n","created_at":"2015-11-29T22:34:05Z","updated_at":"2015-11-29T22:34:05Z","html_url":"https://github.com/camelot-framework/camelot/pull/133#discussion_r46099293","pull_request_url":"https://api.github.com/repos/camelot-framework/camelot/pulls/133","_links":{"self":{"href":"https://api.github.com/repos/camelot-framework/camelot/pulls/comments/46099293"},"html":{"href":"https://github.com/camelot-framework/camelot/pull/133#discussion_r46099293"},"pull_request":{"href":"https://api.github.com/repos/camelot-framework/camelot/pulls/133"}}},"pull_request":{"url":"https://api.github.com/repos/camelot-framework/camelot/pulls/133","id":52072661,"html_url":"https://github.com/camelot-framework/camelot/pull/133","diff_url":"https://github.com/camelot-framework/camelot/pull/133.diff","patch_url":"https://github.com/camelot-framework/camelot/pull/133.patch","issue_url":"https://api.github.com/repos/camelot-framework/camelot/issues/133","number":133,"state":"open","locked":false,"title":"Frontend senders refactoring. MongoDB queue integrated.","user":{"login":"smecsia","id":214657,"avatar_url":"https://avatars.githubusercontent.com/u/214657?v=3","gravatar_id":"","url":"https://api.github.com/users/smecsia","html_url":"https://github.com/smecsia","followers_url":"https://api.github.com/users/smecsia/followers","following_url":"https://api.github.com/users/smecsia/following{/other_user}","gists_url":"https://api.github.com/users/smecsia/gists{/gist_id}","starred_url":"https://api.github.com/users/smecsia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smecsia/subscriptions","organizations_url":"https://api.github.com/users/smecsia/orgs","repos_url":"https://api.github.com/users/smecsia/repos","events_url":"https://api.github.com/users/smecsia/events{/privacy}","received_events_url":"https://api.github.com/users/smecsia/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-29T22:20:00Z","updated_at":"2015-11-29T22:34:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e62c29efe08e88da9dd1cc0978d8be5029477e24","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/camelot-framework/camelot/pulls/133/commits","review_comments_url":"https://api.github.com/repos/camelot-framework/camelot/pulls/133/comments","review_comment_url":"https://api.github.com/repos/camelot-framework/camelot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/camelot-framework/camelot/issues/133/comments","statuses_url":"https://api.github.com/repos/camelot-framework/camelot/statuses/c417e026e03fb3e87f133e6644f167e655f38028","head":{"label":"smecsia:master","ref":"master","sha":"c417e026e03fb3e87f133e6644f167e655f38028","user":{"login":"smecsia","id":214657,"avatar_url":"https://avatars.githubusercontent.com/u/214657?v=3","gravatar_id":"","url":"https://api.github.com/users/smecsia","html_url":"https://github.com/smecsia","followers_url":"https://api.github.com/users/smecsia/followers","following_url":"https://api.github.com/users/smecsia/following{/other_user}","gists_url":"https://api.github.com/users/smecsia/gists{/gist_id}","starred_url":"https://api.github.com/users/smecsia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smecsia/subscriptions","organizations_url":"https://api.github.com/users/smecsia/orgs","repos_url":"https://api.github.com/users/smecsia/repos","events_url":"https://api.github.com/users/smecsia/events{/privacy}","received_events_url":"https://api.github.com/users/smecsia/received_events","type":"User","site_admin":false},"repo":{"id":22915597,"name":"camelot","full_name":"smecsia/camelot","owner":{"login":"smecsia","id":214657,"avatar_url":"https://avatars.githubusercontent.com/u/214657?v=3","gravatar_id":"","url":"https://api.github.com/users/smecsia","html_url":"https://github.com/smecsia","followers_url":"https://api.github.com/users/smecsia/followers","following_url":"https://api.github.com/users/smecsia/following{/other_user}","gists_url":"https://api.github.com/users/smecsia/gists{/gist_id}","starred_url":"https://api.github.com/users/smecsia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smecsia/subscriptions","organizations_url":"https://api.github.com/users/smecsia/orgs","repos_url":"https://api.github.com/users/smecsia/repos","events_url":"https://api.github.com/users/smecsia/events{/privacy}","received_events_url":"https://api.github.com/users/smecsia/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/smecsia/camelot","description":"Simplified scalable aggregation and processing framework built upon Apache Camel.","fork":true,"url":"https://api.github.com/repos/smecsia/camelot","forks_url":"https://api.github.com/repos/smecsia/camelot/forks","keys_url":"https://api.github.com/repos/smecsia/camelot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/smecsia/camelot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/smecsia/camelot/teams","hooks_url":"https://api.github.com/repos/smecsia/camelot/hooks","issue_events_url":"https://api.github.com/repos/smecsia/camelot/issues/events{/number}","events_url":"https://api.github.com/repos/smecsia/camelot/events","assignees_url":"https://api.github.com/repos/smecsia/camelot/assignees{/user}","branches_url":"https://api.github.com/repos/smecsia/camelot/branches{/branch}","tags_url":"https://api.github.com/repos/smecsia/camelot/tags","blobs_url":"https://api.github.com/repos/smecsia/camelot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/smecsia/camelot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/smecsia/camelot/git/refs{/sha}","trees_url":"https://api.github.com/repos/smecsia/camelot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/smecsia/camelot/statuses/{sha}","languages_url":"https://api.github.com/repos/smecsia/camelot/languages","stargazers_url":"https://api.github.com/repos/smecsia/camelot/stargazers","contributors_url":"https://api.github.com/repos/smecsia/camelot/contributors","subscribers_url":"https://api.github.com/repos/smecsia/camelot/subscribers","subscription_url":"https://api.github.com/repos/smecsia/camelot/subscription","commits_url":"https://api.github.com/repos/smecsia/camelot/commits{/sha}","git_commits_url":"https://api.github.com/repos/smecsia/camelot/git/commits{/sha}","comments_url":"https://api.github.com/repos/smecsia/camelot/comments{/number}","issue_comment_url":"https://api.github.com/repos/smecsia/camelot/issues/comments{/number}","contents_url":"https://api.github.com/repos/smecsia/camelot/contents/{+path}","compare_url":"https://api.github.com/repos/smecsia/camelot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/smecsia/camelot/merges","archive_url":"https://api.github.com/repos/smecsia/camelot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/smecsia/camelot/downloads","issues_url":"https://api.github.com/repos/smecsia/camelot/issues{/number}","pulls_url":"https://api.github.com/repos/smecsia/camelot/pulls{/number}","milestones_url":"https://api.github.com/repos/smecsia/camelot/milestones{/number}","notifications_url":"https://api.github.com/repos/smecsia/camelot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/smecsia/camelot/labels{/name}","releases_url":"https://api.github.com/repos/smecsia/camelot/releases{/id}","created_at":"2014-08-13T12:56:57Z","updated_at":"2015-04-29T13:19:37Z","pushed_at":"2015-11-29T22:23:22Z","git_url":"git://github.com/smecsia/camelot.git","ssh_url":"git@github.com:smecsia/camelot.git","clone_url":"https://github.com/smecsia/camelot.git","svn_url":"https://github.com/smecsia/camelot","homepage":"http://camelot.qatools.ru","size":1443,"stargazers_count":0,"watchers_count":0,"language":"Java","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":"camelot-framework:master","ref":"master","sha":"d8a4e6cfd2db430104c1c72ab2467987a17a99a7","user":{"login":"camelot-framework","id":6671821,"avatar_url":"https://avatars.githubusercontent.com/u/6671821?v=3","gravatar_id":"","url":"https://api.github.com/users/camelot-framework","html_url":"https://github.com/camelot-framework","followers_url":"https://api.github.com/users/camelot-framework/followers","following_url":"https://api.github.com/users/camelot-framework/following{/other_user}","gists_url":"https://api.github.com/users/camelot-framework/gists{/gist_id}","starred_url":"https://api.github.com/users/camelot-framework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camelot-framework/subscriptions","organizations_url":"https://api.github.com/users/camelot-framework/orgs","repos_url":"https://api.github.com/users/camelot-framework/repos","events_url":"https://api.github.com/users/camelot-framework/events{/privacy}","received_events_url":"https://api.github.com/users/camelot-framework/received_events","type":"Organization","site_admin":false},"repo":{"id":22441031,"name":"camelot","full_name":"camelot-framework/camelot","owner":{"login":"camelot-framework","id":6671821,"avatar_url":"https://avatars.githubusercontent.com/u/6671821?v=3","gravatar_id":"","url":"https://api.github.com/users/camelot-framework","html_url":"https://github.com/camelot-framework","followers_url":"https://api.github.com/users/camelot-framework/followers","following_url":"https://api.github.com/users/camelot-framework/following{/other_user}","gists_url":"https://api.github.com/users/camelot-framework/gists{/gist_id}","starred_url":"https://api.github.com/users/camelot-framework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camelot-framework/subscriptions","organizations_url":"https://api.github.com/users/camelot-framework/orgs","repos_url":"https://api.github.com/users/camelot-framework/repos","events_url":"https://api.github.com/users/camelot-framework/events{/privacy}","received_events_url":"https://api.github.com/users/camelot-framework/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/camelot-framework/camelot","description":"Simplified scalable aggregation and processing framework built upon Apache Camel.","fork":false,"url":"https://api.github.com/repos/camelot-framework/camelot","forks_url":"https://api.github.com/repos/camelot-framework/camelot/forks","keys_url":"https://api.github.com/repos/camelot-framework/camelot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/camelot-framework/camelot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/camelot-framework/camelot/teams","hooks_url":"https://api.github.com/repos/camelot-framework/camelot/hooks","issue_events_url":"https://api.github.com/repos/camelot-framework/camelot/issues/events{/number}","events_url":"https://api.github.com/repos/camelot-framework/camelot/events","assignees_url":"https://api.github.com/repos/camelot-framework/camelot/assignees{/user}","branches_url":"https://api.github.com/repos/camelot-framework/camelot/branches{/branch}","tags_url":"https://api.github.com/repos/camelot-framework/camelot/tags","blobs_url":"https://api.github.com/repos/camelot-framework/camelot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/camelot-framework/camelot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/camelot-framework/camelot/git/refs{/sha}","trees_url":"https://api.github.com/repos/camelot-framework/camelot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/camelot-framework/camelot/statuses/{sha}","languages_url":"https://api.github.com/repos/camelot-framework/camelot/languages","stargazers_url":"https://api.github.com/repos/camelot-framework/camelot/stargazers","contributors_url":"https://api.github.com/repos/camelot-framework/camelot/contributors","subscribers_url":"https://api.github.com/repos/camelot-framework/camelot/subscribers","subscription_url":"https://api.github.com/repos/camelot-framework/camelot/subscription","commits_url":"https://api.github.com/repos/camelot-framework/camelot/commits{/sha}","git_commits_url":"https://api.github.com/repos/camelot-framework/camelot/git/commits{/sha}","comments_url":"https://api.github.com/repos/camelot-framework/camelot/comments{/number}","issue_comment_url":"https://api.github.com/repos/camelot-framework/camelot/issues/comments{/number}","contents_url":"https://api.github.com/repos/camelot-framework/camelot/contents/{+path}","compare_url":"https://api.github.com/repos/camelot-framework/camelot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/camelot-framework/camelot/merges","archive_url":"https://api.github.com/repos/camelot-framework/camelot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/camelot-framework/camelot/downloads","issues_url":"https://api.github.com/repos/camelot-framework/camelot/issues{/number}","pulls_url":"https://api.github.com/repos/camelot-framework/camelot/pulls{/number}","milestones_url":"https://api.github.com/repos/camelot-framework/camelot/milestones{/number}","notifications_url":"https://api.github.com/repos/camelot-framework/camelot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/camelot-framework/camelot/labels{/name}","releases_url":"https://api.github.com/repos/camelot-framework/camelot/releases{/id}","created_at":"2014-07-30T19:06:12Z","updated_at":"2015-11-10T19:28:04Z","pushed_at":"2015-11-29T22:23:23Z","git_url":"git://github.com/camelot-framework/camelot.git","ssh_url":"git@github.com:camelot-framework/camelot.git","clone_url":"https://github.com/camelot-framework/camelot.git","svn_url":"https://github.com/camelot-framework/camelot","homepage":"","size":1433,"stargazers_count":11,"watchers_count":11,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":4,"forks":6,"open_issues":4,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/camelot-framework/camelot/pulls/133"},"html":{"href":"https://github.com/camelot-framework/camelot/pull/133"},"issue":{"href":"https://api.github.com/repos/camelot-framework/camelot/issues/133"},"comments":{"href":"https://api.github.com/repos/camelot-framework/camelot/issues/133/comments"},"review_comments":{"href":"https://api.github.com/repos/camelot-framework/camelot/pulls/133/comments"},"review_comment":{"href":"https://api.github.com/repos/camelot-framework/camelot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/camelot-framework/camelot/pulls/133/commits"},"statuses":{"href":"https://api.github.com/repos/camelot-framework/camelot/statuses/c417e026e03fb3e87f133e6644f167e655f38028"}}}}