{"action":"created","comment":{"url":"https://api.github.com/repos/apache/ignite/pulls/comments/57832627","id":57832627,"diff_hunk":"@@ -0,0 +1,309 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * 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, 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 org.apache.ignite.stream.kafka.connect;\n+\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.UUID;\n+import java.util.concurrent.BlockingQueue;\n+import java.util.concurrent.LinkedBlockingQueue;\n+import java.util.concurrent.TimeUnit;\n+import org.apache.ignite.Ignite;\n+import org.apache.ignite.IgniteException;\n+import org.apache.ignite.Ignition;\n+import org.apache.ignite.cache.affinity.Affinity;\n+import org.apache.ignite.cluster.ClusterNode;\n+import org.apache.ignite.events.CacheEvent;\n+import org.apache.ignite.events.EventType;\n+import org.apache.ignite.lang.IgniteBiPredicate;\n+import org.apache.ignite.lang.IgnitePredicate;\n+import org.apache.kafka.connect.errors.ConnectException;\n+import org.apache.kafka.connect.source.SourceRecord;\n+import org.apache.kafka.connect.source.SourceTask;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+/**\n+ * Task to consume remote cluster cache events from the grid and inject them into Kafka.\n+ * <p>\n+ * Note that a task will create a bounded queue in the grid for more reliable data transfer.\n+ * Queue size can be changed by {@link IgniteSourceConstants#INTL_BUF_SIZE}.\n+ */\n+public class IgniteSourceTask extends SourceTask {\n+    /** Logger. */\n+    private static final Logger log = LoggerFactory.getLogger(IgniteSourceTask.class);\n+\n+    /** Event buffer size. */\n+    private static int evtBufSize = 100000;\n+\n+    /** Event buffer. */\n+    private static BlockingQueue<CacheEvent> evtBuf = new LinkedBlockingQueue<>(evtBufSize);\n+\n+    /** Max number of events taken from the buffer at once. */\n+    private static int evtBatchSize = 100;\n+\n+    /** Flag for stopped state. */\n+    private static volatile boolean stopped = true;\n+\n+    /** Ignite grid configuration file. */\n+    private static String igniteConfigFile;\n+\n+    /** Cache name. */\n+    private static String cacheName;\n+\n+    /** Listener id. */\n+    private static UUID rmtLsnrId;\n+\n+    /** User-defined filter. */\n+    private static IgnitePredicate<CacheEvent> filter;\n+\n+    /** Topic. */\n+    private static String topics[];\n+\n+    /** Offset. */\n+    private static final Map<String, Long> offset = Collections.singletonMap(\"offset\", 0L);\n+\n+    /** Partition. */\n+    private static final Map<String, String> srcPartition = Collections.singletonMap(\"cache\", null);\n+\n+    /** {@inheritDoc} */\n+    @Override public String version() {\n+        return new IgniteSinkConnector().version();\n+    }\n+\n+    /**\n+     * Filtering is done remotely. Local listener buffers data for injection into Kafka.\n+     *\n+     * @param props Task properties.\n+     */\n+    @Override public void start(Map<String, String> props) {\n+        // Each task has the same parameters -- avoid setting more than once.\n+        if (cacheName != null)\n+            return;\n+\n+        cacheName = props.get(IgniteSourceConstants.CACHE_NAME);\n+        igniteConfigFile = props.get(IgniteSourceConstants.CACHE_CFG_PATH);\n+        topics = props.get(IgniteSourceConstants.TOPIC_NAMES).split(\"\\\\s*,\\\\s*\");\n+\n+        if (props.containsKey(IgniteSourceConstants.INTL_BUF_SIZE))\n+            evtBufSize = Integer.parseInt(props.get(IgniteSourceConstants.INTL_BUF_SIZE));\n+\n+        if (props.containsKey(IgniteSourceConstants.INTL_BATCH_SIZE))\n+            evtBatchSize = Integer.parseInt(props.get(IgniteSourceConstants.INTL_BATCH_SIZE));\n+\n+        if (props.containsKey(IgniteSourceConstants.CACHE_FILTER_CLASS)) {\n+            String filterCls = props.get(IgniteSourceConstants.CACHE_FILTER_CLASS);\n+            if (filterCls != null && !filterCls.isEmpty()) {\n+                try {\n+                    Class<? extends IgnitePredicate<CacheEvent>> clazz =\n+                        (Class<? extends IgnitePredicate<CacheEvent>>)Class.forName(filterCls);\n+\n+                    filter = clazz.newInstance();\n+                }\n+                catch (Exception e) {\n+                    log.error(\"Failed to instantiate the provided filter! \" +\n+                        \"User-enabled filtering is ignored!\", e);\n+                }\n+            }\n+        }\n+\n+        IgniteBiPredicate<UUID, CacheEvent> locLsnr = new IgniteBiPredicate<UUID, CacheEvent>() {\n+            @Override public boolean apply(UUID id, CacheEvent evt) {","path":"modules/kafka/src/main/java/org/apache/ignite/stream/kafka/connect/IgniteSourceTask.java","position":128,"original_position":128,"commit_id":"13e5b23e8b1e14a63e21cad4a0e33aaaca049580","original_commit_id":"13e5b23e8b1e14a63e21cad4a0e33aaaca049580","user":{"login":"dmagda","id":1537233,"avatar_url":"https://avatars.githubusercontent.com/u/1537233?v=3","gravatar_id":"","url":"https://api.github.com/users/dmagda","html_url":"https://github.com/dmagda","followers_url":"https://api.github.com/users/dmagda/followers","following_url":"https://api.github.com/users/dmagda/following{/other_user}","gists_url":"https://api.github.com/users/dmagda/gists{/gist_id}","starred_url":"https://api.github.com/users/dmagda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmagda/subscriptions","organizations_url":"https://api.github.com/users/dmagda/orgs","repos_url":"https://api.github.com/users/dmagda/repos","events_url":"https://api.github.com/users/dmagda/events{/privacy}","received_events_url":"https://api.github.com/users/dmagda/received_events","type":"User","site_admin":false},"body":"Please don't use anonymous classes for both remote and local listener because in that case their enclosing class (IgniteSourceTask) will be serialized and sent over the wire along with them. Just move implementation of the listeners to \"private static class\".","created_at":"2016-03-30T03:19:51Z","updated_at":"2016-03-30T03:19:51Z","html_url":"https://github.com/apache/ignite/pull/560#discussion_r57832627","pull_request_url":"https://api.github.com/repos/apache/ignite/pulls/560","_links":{"self":{"href":"https://api.github.com/repos/apache/ignite/pulls/comments/57832627"},"html":{"href":"https://github.com/apache/ignite/pull/560#discussion_r57832627"},"pull_request":{"href":"https://api.github.com/repos/apache/ignite/pulls/560"}}},"pull_request":{"url":"https://api.github.com/repos/apache/ignite/pulls/560","id":63200729,"html_url":"https://github.com/apache/ignite/pull/560","diff_url":"https://github.com/apache/ignite/pull/560.diff","patch_url":"https://github.com/apache/ignite/pull/560.patch","issue_url":"https://api.github.com/repos/apache/ignite/issues/560","number":560,"state":"open","locked":false,"title":"Ignite-2730: Ignite Events Source Streaming to Kafka.","user":{"login":"shroman","id":3435166,"avatar_url":"https://avatars.githubusercontent.com/u/3435166?v=3","gravatar_id":"","url":"https://api.github.com/users/shroman","html_url":"https://github.com/shroman","followers_url":"https://api.github.com/users/shroman/followers","following_url":"https://api.github.com/users/shroman/following{/other_user}","gists_url":"https://api.github.com/users/shroman/gists{/gist_id}","starred_url":"https://api.github.com/users/shroman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shroman/subscriptions","organizations_url":"https://api.github.com/users/shroman/orgs","repos_url":"https://api.github.com/users/shroman/repos","events_url":"https://api.github.com/users/shroman/events{/privacy}","received_events_url":"https://api.github.com/users/shroman/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-17T10:25:37Z","updated_at":"2016-03-30T03:19:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6b9b056626e67cb1274d652dccf9c2732e539b65","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/ignite/pulls/560/commits","review_comments_url":"https://api.github.com/repos/apache/ignite/pulls/560/comments","review_comment_url":"https://api.github.com/repos/apache/ignite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/ignite/issues/560/comments","statuses_url":"https://api.github.com/repos/apache/ignite/statuses/13e5b23e8b1e14a63e21cad4a0e33aaaca049580","head":{"label":"shroman:ignite-2730","ref":"ignite-2730","sha":"13e5b23e8b1e14a63e21cad4a0e33aaaca049580","user":{"login":"shroman","id":3435166,"avatar_url":"https://avatars.githubusercontent.com/u/3435166?v=3","gravatar_id":"","url":"https://api.github.com/users/shroman","html_url":"https://github.com/shroman","followers_url":"https://api.github.com/users/shroman/followers","following_url":"https://api.github.com/users/shroman/following{/other_user}","gists_url":"https://api.github.com/users/shroman/gists{/gist_id}","starred_url":"https://api.github.com/users/shroman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shroman/subscriptions","organizations_url":"https://api.github.com/users/shroman/orgs","repos_url":"https://api.github.com/users/shroman/repos","events_url":"https://api.github.com/users/shroman/events{/privacy}","received_events_url":"https://api.github.com/users/shroman/received_events","type":"User","site_admin":false},"repo":{"id":44226429,"name":"ignite","full_name":"shroman/ignite","owner":{"login":"shroman","id":3435166,"avatar_url":"https://avatars.githubusercontent.com/u/3435166?v=3","gravatar_id":"","url":"https://api.github.com/users/shroman","html_url":"https://github.com/shroman","followers_url":"https://api.github.com/users/shroman/followers","following_url":"https://api.github.com/users/shroman/following{/other_user}","gists_url":"https://api.github.com/users/shroman/gists{/gist_id}","starred_url":"https://api.github.com/users/shroman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shroman/subscriptions","organizations_url":"https://api.github.com/users/shroman/orgs","repos_url":"https://api.github.com/users/shroman/repos","events_url":"https://api.github.com/users/shroman/events{/privacy}","received_events_url":"https://api.github.com/users/shroman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shroman/ignite","description":"Mirror of Apache Ignite","fork":true,"url":"https://api.github.com/repos/shroman/ignite","forks_url":"https://api.github.com/repos/shroman/ignite/forks","keys_url":"https://api.github.com/repos/shroman/ignite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shroman/ignite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shroman/ignite/teams","hooks_url":"https://api.github.com/repos/shroman/ignite/hooks","issue_events_url":"https://api.github.com/repos/shroman/ignite/issues/events{/number}","events_url":"https://api.github.com/repos/shroman/ignite/events","assignees_url":"https://api.github.com/repos/shroman/ignite/assignees{/user}","branches_url":"https://api.github.com/repos/shroman/ignite/branches{/branch}","tags_url":"https://api.github.com/repos/shroman/ignite/tags","blobs_url":"https://api.github.com/repos/shroman/ignite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shroman/ignite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shroman/ignite/git/refs{/sha}","trees_url":"https://api.github.com/repos/shroman/ignite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shroman/ignite/statuses/{sha}","languages_url":"https://api.github.com/repos/shroman/ignite/languages","stargazers_url":"https://api.github.com/repos/shroman/ignite/stargazers","contributors_url":"https://api.github.com/repos/shroman/ignite/contributors","subscribers_url":"https://api.github.com/repos/shroman/ignite/subscribers","subscription_url":"https://api.github.com/repos/shroman/ignite/subscription","commits_url":"https://api.github.com/repos/shroman/ignite/commits{/sha}","git_commits_url":"https://api.github.com/repos/shroman/ignite/git/commits{/sha}","comments_url":"https://api.github.com/repos/shroman/ignite/comments{/number}","issue_comment_url":"https://api.github.com/repos/shroman/ignite/issues/comments{/number}","contents_url":"https://api.github.com/repos/shroman/ignite/contents/{+path}","compare_url":"https://api.github.com/repos/shroman/ignite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shroman/ignite/merges","archive_url":"https://api.github.com/repos/shroman/ignite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shroman/ignite/downloads","issues_url":"https://api.github.com/repos/shroman/ignite/issues{/number}","pulls_url":"https://api.github.com/repos/shroman/ignite/pulls{/number}","milestones_url":"https://api.github.com/repos/shroman/ignite/milestones{/number}","notifications_url":"https://api.github.com/repos/shroman/ignite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shroman/ignite/labels{/name}","releases_url":"https://api.github.com/repos/shroman/ignite/releases{/id}","deployments_url":"https://api.github.com/repos/shroman/ignite/deployments","created_at":"2015-10-14T05:41:52Z","updated_at":"2016-01-12T07:19:18Z","pushed_at":"2016-03-29T08:49:08Z","git_url":"git://github.com/shroman/ignite.git","ssh_url":"git@github.com:shroman/ignite.git","clone_url":"https://github.com/shroman/ignite.git","svn_url":"https://github.com/shroman/ignite","homepage":"","size":200970,"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":"d3420e6bc5e833a6eb1daaad25b11843f97328d5","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":31006158,"name":"ignite","full_name":"apache/ignite","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/ignite","description":"Mirror of Apache Ignite","fork":false,"url":"https://api.github.com/repos/apache/ignite","forks_url":"https://api.github.com/repos/apache/ignite/forks","keys_url":"https://api.github.com/repos/apache/ignite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/ignite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/ignite/teams","hooks_url":"https://api.github.com/repos/apache/ignite/hooks","issue_events_url":"https://api.github.com/repos/apache/ignite/issues/events{/number}","events_url":"https://api.github.com/repos/apache/ignite/events","assignees_url":"https://api.github.com/repos/apache/ignite/assignees{/user}","branches_url":"https://api.github.com/repos/apache/ignite/branches{/branch}","tags_url":"https://api.github.com/repos/apache/ignite/tags","blobs_url":"https://api.github.com/repos/apache/ignite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/ignite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/ignite/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/ignite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/ignite/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/ignite/languages","stargazers_url":"https://api.github.com/repos/apache/ignite/stargazers","contributors_url":"https://api.github.com/repos/apache/ignite/contributors","subscribers_url":"https://api.github.com/repos/apache/ignite/subscribers","subscription_url":"https://api.github.com/repos/apache/ignite/subscription","commits_url":"https://api.github.com/repos/apache/ignite/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/ignite/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/ignite/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/ignite/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/ignite/contents/{+path}","compare_url":"https://api.github.com/repos/apache/ignite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/ignite/merges","archive_url":"https://api.github.com/repos/apache/ignite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/ignite/downloads","issues_url":"https://api.github.com/repos/apache/ignite/issues{/number}","pulls_url":"https://api.github.com/repos/apache/ignite/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/ignite/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/ignite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/ignite/labels{/name}","releases_url":"https://api.github.com/repos/apache/ignite/releases{/id}","deployments_url":"https://api.github.com/repos/apache/ignite/deployments","created_at":"2015-02-19T08:00:05Z","updated_at":"2016-03-28T12:32:29Z","pushed_at":"2016-03-29T18:01:54Z","git_url":"git://github.com/apache/ignite.git","ssh_url":"git@github.com:apache/ignite.git","clone_url":"https://github.com/apache/ignite.git","svn_url":"https://github.com/apache/ignite","homepage":"","size":276336,"stargazers_count":348,"watchers_count":348,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":227,"mirror_url":"git://git.apache.org/ignite.git","open_issues_count":191,"forks":227,"open_issues":191,"watchers":348,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/ignite/pulls/560"},"html":{"href":"https://github.com/apache/ignite/pull/560"},"issue":{"href":"https://api.github.com/repos/apache/ignite/issues/560"},"comments":{"href":"https://api.github.com/repos/apache/ignite/issues/560/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/ignite/pulls/560/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/ignite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/ignite/pulls/560/commits"},"statuses":{"href":"https://api.github.com/repos/apache/ignite/statuses/13e5b23e8b1e14a63e21cad4a0e33aaaca049580"}}}}