{"action":"created","comment":{"url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments/81092567","pull_request_review_id":2092074,"id":81092567,"diff_hunk":"@@ -0,0 +1,129 @@\n+/**\n+ * Copyright (c) 2014-2016 by the respective copyright holders.\n+ *\n+ * All rights reserved. This program and the accompanying materials\n+ * are made available under the terms of the Eclipse Public License v1.0\n+ * which accompanies this distribution, and is available at\n+ * http://www.eclipse.org/legal/epl-v10.html\n+ */\n+package org.openhab.binding.fileregexparser.internal;\n+\n+import java.io.File;\n+import java.io.RandomAccessFile;\n+import java.util.concurrent.ExecutorService;\n+import java.util.concurrent.Future;\n+import java.util.concurrent.TimeUnit;\n+import java.util.regex.Matcher;\n+import java.util.regex.Pattern;\n+\n+import org.eclipse.smarthome.core.common.ThreadPoolManager;\n+import org.openhab.binding.fileregexparser.handler.FileRegexParserHandler;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+public class FileRegexParserWorker implements Runnable {\n+    private static final String THING_HANDLER_THREADPOOL_NAME = \"thingHandler\";\n+    private static final String SAFE_CALL_THREADPOOL_NAME = \"saveCall\";\n+    private final Logger logger = LoggerFactory.getLogger(FileRegexParserWorker.class);\n+    private boolean executeWorker = false;\n+\n+    protected final ExecutorService executor = ThreadPoolManager.getPool(SAFE_CALL_THREADPOOL_NAME);\n+    protected Future<?> future = null;\n+\n+    private long filePointer = 0;\n+    private File fileToRead;\n+    private String regEx = \"\";\n+    private String line = \"\";\n+    private FileRegexParserHandler updateCallback;\n+\n+    public FileRegexParserWorker(FileRegexParserHandler caller) {\n+        updateCallback = caller;\n+    }\n+    // TODO Auto-generated constructor stub\n+\n+    public void startWorker(String fileName, String regEx) {\n+        logger.debug(\"Starting Worker thread for \" + fileName);\n+        this.fileToRead = new File(fileName);\n+        this.regEx = regEx;\n+        filePointer = fileToRead.length();\n+        executeWorker = true;\n+        future = executor.submit(this);\n+        logger.debug(\n+                \"Worker started: futureId = \" + System.identityHashCode(future) + \" executor: \" + executor.toString());\n+    }\n+\n+    public void stopWorker() {\n+        executeWorker = false;\n+        logger.debug(\"Stopping Worker thread\");\n+\n+        if (future != null) {\n+            try {\n+                future.get(1000, TimeUnit.MILLISECONDS);\n+                logger.debug(\"Future ended: \" + System.identityHashCode(future) + \": Done: \" + future.isDone()\n+                        + \" executor: \" + \" executor: \" + executor.toString());\n+            } catch (Exception e) {\n+                logger.debug(\"Future exception: \" + e);\n+            }\n+        }\n+\n+        /*\n+         * if (executor != null) {\n+         * executor.shutdown();\n+         * executor.shutdownNow();\n+         * }\n+         */\n+\n+    }\n+\n+    private void parseLine(String pattern, String toParse) {\n+\n+        Pattern p = Pattern.compile(pattern);\n+        Matcher m = p.matcher(toParse);\n+        // String curGroup = new String(\"\");\n+        if (m.matches()) {\n+            for (int i = 1; i <= m.groupCount(); i++) {\n+                updateCallback.updateStateReceived(\"matchingGroup\" + i, m.group(i));\n+\n+            }\n+        } else {\n+            logger.info(toParse + \": no match for \" + p.toString());\n+        }\n+    }\n+\n+    @Override\n+    public void run() {\n+        logger.debug(\"Runner run entered for file\" + fileToRead.getName());\n+        while (executeWorker) {\n+            try {\n+                Thread.sleep(1000);","path":"addons/binding/org.openhab.binding.fileregexparser/src/main/java/org/openhab/binding/fileregexparser/internal/FileRegexParserWorker.java","position":98,"original_position":98,"commit_id":"5def9ee9d3783000b7dafb2173568198dce8fe8a","original_commit_id":"5def9ee9d3783000b7dafb2173568198dce8fe8a","user":{"login":"sjka","id":2592443,"avatar_url":"https://avatars.githubusercontent.com/u/2592443?v=3","gravatar_id":"","url":"https://api.github.com/users/sjka","html_url":"https://github.com/sjka","followers_url":"https://api.github.com/users/sjka/followers","following_url":"https://api.github.com/users/sjka/following{/other_user}","gists_url":"https://api.github.com/users/sjka/gists{/gist_id}","starred_url":"https://api.github.com/users/sjka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjka/subscriptions","organizations_url":"https://api.github.com/users/sjka/orgs","repos_url":"https://api.github.com/users/sjka/repos","events_url":"https://api.github.com/users/sjka/events{/privacy}","received_events_url":"https://api.github.com/users/sjka/received_events","type":"User","site_admin":false},"body":"polling every second is one way of doing it. the other would be to use the WatchService from java.nio (see also AbstractWatchService). Any particular reasons why you didn't use it?","created_at":"2016-09-29T09:00:47Z","updated_at":"2016-09-29T09:00:47Z","html_url":"https://github.com/openhab/openhab2-addons/pull/1028#discussion_r81092567","pull_request_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1028","_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments/81092567"},"html":{"href":"https://github.com/openhab/openhab2-addons/pull/1028#discussion_r81092567"},"pull_request":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1028"}}},"pull_request":{"url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1028","id":74089631,"html_url":"https://github.com/openhab/openhab2-addons/pull/1028","diff_url":"https://github.com/openhab/openhab2-addons/pull/1028.diff","patch_url":"https://github.com/openhab/openhab2-addons/pull/1028.patch","issue_url":"https://api.github.com/repos/openhab/openhab2-addons/issues/1028","number":1028,"state":"open","locked":false,"title":"New Binding Fileregexparser","user":{"login":"meju25","id":19248204,"avatar_url":"https://avatars.githubusercontent.com/u/19248204?v=3","gravatar_id":"","url":"https://api.github.com/users/meju25","html_url":"https://github.com/meju25","followers_url":"https://api.github.com/users/meju25/followers","following_url":"https://api.github.com/users/meju25/following{/other_user}","gists_url":"https://api.github.com/users/meju25/gists{/gist_id}","starred_url":"https://api.github.com/users/meju25/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meju25/subscriptions","organizations_url":"https://api.github.com/users/meju25/orgs","repos_url":"https://api.github.com/users/meju25/repos","events_url":"https://api.github.com/users/meju25/events{/privacy}","received_events_url":"https://api.github.com/users/meju25/received_events","type":"User","site_admin":false},"body":"I have added a new binding \"Fileregexparser\".\r\n\r\n\"The FileRegexParser binding provides thing to read new lines from a file, parse them with a given regular expression and provide channels for each matching group.\"","created_at":"2016-06-16T14:23:31Z","updated_at":"2016-09-29T09:07:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d6d727ad704a107b0deeccbd149f3d1035db99b0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1028/commits","review_comments_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1028/comments","review_comment_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openhab/openhab2-addons/issues/1028/comments","statuses_url":"https://api.github.com/repos/openhab/openhab2-addons/statuses/5def9ee9d3783000b7dafb2173568198dce8fe8a","head":{"label":"meju25:FileRegexParser","ref":"FileRegexParser","sha":"5def9ee9d3783000b7dafb2173568198dce8fe8a","user":{"login":"meju25","id":19248204,"avatar_url":"https://avatars.githubusercontent.com/u/19248204?v=3","gravatar_id":"","url":"https://api.github.com/users/meju25","html_url":"https://github.com/meju25","followers_url":"https://api.github.com/users/meju25/followers","following_url":"https://api.github.com/users/meju25/following{/other_user}","gists_url":"https://api.github.com/users/meju25/gists{/gist_id}","starred_url":"https://api.github.com/users/meju25/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meju25/subscriptions","organizations_url":"https://api.github.com/users/meju25/orgs","repos_url":"https://api.github.com/users/meju25/repos","events_url":"https://api.github.com/users/meju25/events{/privacy}","received_events_url":"https://api.github.com/users/meju25/received_events","type":"User","site_admin":false},"repo":{"id":59930934,"name":"openhab2-addons","full_name":"meju25/openhab2-addons","owner":{"login":"meju25","id":19248204,"avatar_url":"https://avatars.githubusercontent.com/u/19248204?v=3","gravatar_id":"","url":"https://api.github.com/users/meju25","html_url":"https://github.com/meju25","followers_url":"https://api.github.com/users/meju25/followers","following_url":"https://api.github.com/users/meju25/following{/other_user}","gists_url":"https://api.github.com/users/meju25/gists{/gist_id}","starred_url":"https://api.github.com/users/meju25/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meju25/subscriptions","organizations_url":"https://api.github.com/users/meju25/orgs","repos_url":"https://api.github.com/users/meju25/repos","events_url":"https://api.github.com/users/meju25/events{/privacy}","received_events_url":"https://api.github.com/users/meju25/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/meju25/openhab2-addons","description":"The next-generation open Home Automation Bus (openHAB)","fork":true,"url":"https://api.github.com/repos/meju25/openhab2-addons","forks_url":"https://api.github.com/repos/meju25/openhab2-addons/forks","keys_url":"https://api.github.com/repos/meju25/openhab2-addons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/meju25/openhab2-addons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/meju25/openhab2-addons/teams","hooks_url":"https://api.github.com/repos/meju25/openhab2-addons/hooks","issue_events_url":"https://api.github.com/repos/meju25/openhab2-addons/issues/events{/number}","events_url":"https://api.github.com/repos/meju25/openhab2-addons/events","assignees_url":"https://api.github.com/repos/meju25/openhab2-addons/assignees{/user}","branches_url":"https://api.github.com/repos/meju25/openhab2-addons/branches{/branch}","tags_url":"https://api.github.com/repos/meju25/openhab2-addons/tags","blobs_url":"https://api.github.com/repos/meju25/openhab2-addons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/meju25/openhab2-addons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/meju25/openhab2-addons/git/refs{/sha}","trees_url":"https://api.github.com/repos/meju25/openhab2-addons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/meju25/openhab2-addons/statuses/{sha}","languages_url":"https://api.github.com/repos/meju25/openhab2-addons/languages","stargazers_url":"https://api.github.com/repos/meju25/openhab2-addons/stargazers","contributors_url":"https://api.github.com/repos/meju25/openhab2-addons/contributors","subscribers_url":"https://api.github.com/repos/meju25/openhab2-addons/subscribers","subscription_url":"https://api.github.com/repos/meju25/openhab2-addons/subscription","commits_url":"https://api.github.com/repos/meju25/openhab2-addons/commits{/sha}","git_commits_url":"https://api.github.com/repos/meju25/openhab2-addons/git/commits{/sha}","comments_url":"https://api.github.com/repos/meju25/openhab2-addons/comments{/number}","issue_comment_url":"https://api.github.com/repos/meju25/openhab2-addons/issues/comments{/number}","contents_url":"https://api.github.com/repos/meju25/openhab2-addons/contents/{+path}","compare_url":"https://api.github.com/repos/meju25/openhab2-addons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/meju25/openhab2-addons/merges","archive_url":"https://api.github.com/repos/meju25/openhab2-addons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/meju25/openhab2-addons/downloads","issues_url":"https://api.github.com/repos/meju25/openhab2-addons/issues{/number}","pulls_url":"https://api.github.com/repos/meju25/openhab2-addons/pulls{/number}","milestones_url":"https://api.github.com/repos/meju25/openhab2-addons/milestones{/number}","notifications_url":"https://api.github.com/repos/meju25/openhab2-addons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/meju25/openhab2-addons/labels{/name}","releases_url":"https://api.github.com/repos/meju25/openhab2-addons/releases{/id}","deployments_url":"https://api.github.com/repos/meju25/openhab2-addons/deployments","created_at":"2016-05-29T07:09:33Z","updated_at":"2016-05-29T07:09:39Z","pushed_at":"2016-06-21T06:41:41Z","git_url":"git://github.com/meju25/openhab2-addons.git","ssh_url":"git@github.com:meju25/openhab2-addons.git","clone_url":"https://github.com/meju25/openhab2-addons.git","svn_url":"https://github.com/meju25/openhab2-addons","homepage":null,"size":175284,"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":"openhab:master","ref":"master","sha":"c5abe82e0420482bec4899a018f8d1b979178fc3","user":{"login":"openhab","id":1007353,"avatar_url":"https://avatars.githubusercontent.com/u/1007353?v=3","gravatar_id":"","url":"https://api.github.com/users/openhab","html_url":"https://github.com/openhab","followers_url":"https://api.github.com/users/openhab/followers","following_url":"https://api.github.com/users/openhab/following{/other_user}","gists_url":"https://api.github.com/users/openhab/gists{/gist_id}","starred_url":"https://api.github.com/users/openhab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openhab/subscriptions","organizations_url":"https://api.github.com/users/openhab/orgs","repos_url":"https://api.github.com/users/openhab/repos","events_url":"https://api.github.com/users/openhab/events{/privacy}","received_events_url":"https://api.github.com/users/openhab/received_events","type":"Organization","site_admin":false},"repo":{"id":19753195,"name":"openhab2-addons","full_name":"openhab/openhab2-addons","owner":{"login":"openhab","id":1007353,"avatar_url":"https://avatars.githubusercontent.com/u/1007353?v=3","gravatar_id":"","url":"https://api.github.com/users/openhab","html_url":"https://github.com/openhab","followers_url":"https://api.github.com/users/openhab/followers","following_url":"https://api.github.com/users/openhab/following{/other_user}","gists_url":"https://api.github.com/users/openhab/gists{/gist_id}","starred_url":"https://api.github.com/users/openhab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openhab/subscriptions","organizations_url":"https://api.github.com/users/openhab/orgs","repos_url":"https://api.github.com/users/openhab/repos","events_url":"https://api.github.com/users/openhab/events{/privacy}","received_events_url":"https://api.github.com/users/openhab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openhab/openhab2-addons","description":"The next-generation open Home Automation Bus (openHAB)","fork":false,"url":"https://api.github.com/repos/openhab/openhab2-addons","forks_url":"https://api.github.com/repos/openhab/openhab2-addons/forks","keys_url":"https://api.github.com/repos/openhab/openhab2-addons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openhab/openhab2-addons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openhab/openhab2-addons/teams","hooks_url":"https://api.github.com/repos/openhab/openhab2-addons/hooks","issue_events_url":"https://api.github.com/repos/openhab/openhab2-addons/issues/events{/number}","events_url":"https://api.github.com/repos/openhab/openhab2-addons/events","assignees_url":"https://api.github.com/repos/openhab/openhab2-addons/assignees{/user}","branches_url":"https://api.github.com/repos/openhab/openhab2-addons/branches{/branch}","tags_url":"https://api.github.com/repos/openhab/openhab2-addons/tags","blobs_url":"https://api.github.com/repos/openhab/openhab2-addons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openhab/openhab2-addons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openhab/openhab2-addons/git/refs{/sha}","trees_url":"https://api.github.com/repos/openhab/openhab2-addons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openhab/openhab2-addons/statuses/{sha}","languages_url":"https://api.github.com/repos/openhab/openhab2-addons/languages","stargazers_url":"https://api.github.com/repos/openhab/openhab2-addons/stargazers","contributors_url":"https://api.github.com/repos/openhab/openhab2-addons/contributors","subscribers_url":"https://api.github.com/repos/openhab/openhab2-addons/subscribers","subscription_url":"https://api.github.com/repos/openhab/openhab2-addons/subscription","commits_url":"https://api.github.com/repos/openhab/openhab2-addons/commits{/sha}","git_commits_url":"https://api.github.com/repos/openhab/openhab2-addons/git/commits{/sha}","comments_url":"https://api.github.com/repos/openhab/openhab2-addons/comments{/number}","issue_comment_url":"https://api.github.com/repos/openhab/openhab2-addons/issues/comments{/number}","contents_url":"https://api.github.com/repos/openhab/openhab2-addons/contents/{+path}","compare_url":"https://api.github.com/repos/openhab/openhab2-addons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openhab/openhab2-addons/merges","archive_url":"https://api.github.com/repos/openhab/openhab2-addons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openhab/openhab2-addons/downloads","issues_url":"https://api.github.com/repos/openhab/openhab2-addons/issues{/number}","pulls_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls{/number}","milestones_url":"https://api.github.com/repos/openhab/openhab2-addons/milestones{/number}","notifications_url":"https://api.github.com/repos/openhab/openhab2-addons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openhab/openhab2-addons/labels{/name}","releases_url":"https://api.github.com/repos/openhab/openhab2-addons/releases{/id}","deployments_url":"https://api.github.com/repos/openhab/openhab2-addons/deployments","created_at":"2014-05-13T19:41:58Z","updated_at":"2016-09-27T12:57:03Z","pushed_at":"2016-09-28T13:27:02Z","git_url":"git://github.com/openhab/openhab2-addons.git","ssh_url":"git@github.com:openhab/openhab2-addons.git","clone_url":"https://github.com/openhab/openhab2-addons.git","svn_url":"https://github.com/openhab/openhab2-addons","homepage":null,"size":189736,"stargazers_count":415,"watchers_count":415,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":637,"mirror_url":null,"open_issues_count":115,"forks":637,"open_issues":115,"watchers":415,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1028"},"html":{"href":"https://github.com/openhab/openhab2-addons/pull/1028"},"issue":{"href":"https://api.github.com/repos/openhab/openhab2-addons/issues/1028"},"comments":{"href":"https://api.github.com/repos/openhab/openhab2-addons/issues/1028/comments"},"review_comments":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1028/comments"},"review_comment":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1028/commits"},"statuses":{"href":"https://api.github.com/repos/openhab/openhab2-addons/statuses/5def9ee9d3783000b7dafb2173568198dce8fe8a"}}}}
{"actor":{"display_login":"sjka"}}