{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-reef/pulls/comments/41154167","id":41154167,"diff_hunk":"@@ -0,0 +1,94 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with 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,\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+package org.apache.reef.io.watcher;\n+\n+import org.apache.reef.io.watcher.param.Path;\n+import org.apache.reef.io.watcher.util.RunnableExecutingHandler;\n+import org.apache.reef.tang.annotations.Parameter;\n+import org.apache.reef.wake.EStage;\n+import org.apache.reef.wake.impl.ThreadPoolStage;\n+\n+import javax.inject.Inject;\n+import java.io.File;\n+import java.io.FileOutputStream;\n+import java.io.PrintWriter;\n+import java.text.DateFormat;\n+import java.text.SimpleDateFormat;\n+import java.util.Date;\n+\n+/**\n+ * Write events to a file in the root directory of the driver.\n+ */\n+public final class FileEventStream implements EventStream {\n+\n+  private final DateFormat dateFormat;\n+  private final PrintWriter printWriter;\n+  private final EStage<Runnable> singleThreadedExecutor;\n+\n+  @Inject\n+  private FileEventStream(@Parameter(Path.class) final String path) {\n+    this.dateFormat = new SimpleDateFormat(\"[yyyy.MM.dd HH:mm:ss.SSSS]\");\n+    this.singleThreadedExecutor = new ThreadPoolStage<>(new RunnableExecutingHandler(), 1);\n+\n+    try {\n+      this.printWriter = new PrintWriter(new FileOutputStream(createFileWithPath(path)));\n+    } catch (final Exception e) {\n+      throw new RuntimeException(e);\n+    }\n+  }\n+\n+  private File createFileWithPath(final String path) throws Exception {\n+    final File file = new File(path);\n+    final File parent = file.getParentFile();\n+    if (parent != null && !parent.exists()){\n+      parent.mkdirs();\n+    }\n+\n+    file.createNewFile();\n+    return file;\n+  }\n+\n+  @Override\n+  public void onEvent(final EventType type, final String jsonEncodedEvent) {\n+    final long timestamp = System.currentTimeMillis();\n+    singleThreadedExecutor.onNext(new Runnable() {\n+      @Override\n+      public void run() {\n+        final String eventDescription = new StringBuilder()\n+            .append(dateFormat.format(new Date(timestamp)))\n+            .append(\" [\")\n+            .append(type)\n+            .append(\"] \")\n+            .append(jsonEncodedEvent)\n+            .toString();\n+\n+        printWriter.println(eventDescription);\n+        printWriter.flush();","path":"lang/java/reef-io/src/main/java/org/apache/reef/io/watcher/FileEventStream.java","position":83,"original_position":82,"commit_id":"eebdec6e7ce800f15d180b4697fbf333ea5b5890","original_commit_id":"7c2c5bee6f24410cb79b1d24d41b70d3b6b488ea","user":{"login":"bgchun","id":359137,"avatar_url":"https://avatars.githubusercontent.com/u/359137?v=3","gravatar_id":"","url":"https://api.github.com/users/bgchun","html_url":"https://github.com/bgchun","followers_url":"https://api.github.com/users/bgchun/followers","following_url":"https://api.github.com/users/bgchun/following{/other_user}","gists_url":"https://api.github.com/users/bgchun/gists{/gist_id}","starred_url":"https://api.github.com/users/bgchun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bgchun/subscriptions","organizations_url":"https://api.github.com/users/bgchun/orgs","repos_url":"https://api.github.com/users/bgchun/repos","events_url":"https://api.github.com/users/bgchun/events{/privacy}","received_events_url":"https://api.github.com/users/bgchun/received_events","type":"User","site_admin":false},"body":"Yes. This can cause performance problems. Please fix it.\n\nOn Mon, Oct 5, 2015 at 5:45 PM, gwsshs22 <notifications@github.com> wrote:\n\n> In\n> lang/java/reef-io/src/main/java/org/apache/reef/io/watcher/FileEventStream.java\n> <https://github.com/apache/incubator-reef/pull/522#discussion_r41121531>:\n>\n> > +  @Override\n> > +  public void onEvent(final EventType type, final String jsonEncodedEvent) {\n> > +    final long timestamp = System.currentTimeMillis();\n> > +    singleThreadedExecutor.onNext(new Runnable() {\n> > +      @Override\n> > +      public void run() {\n> > +        final String eventDescription = new StringBuilder()\n> > +            .append(dateFormat.format(new Date(timestamp)))\n> > +            .append(\" [\")\n> > +            .append(type)\n> > +            .append(\"] \")\n> > +            .append(jsonEncodedEvent)\n> > +            .toString();\n> > +\n> > +        printWriter.println(eventDescription);\n> > +        printWriter.flush();\n>\n> I intentionally called flush() every time since some events possibly got\n> lost where the driver went through a catastrophic failure ( e.g. closed\n> without RuntimeStop event ). Please let me know if the multiple calls make\n> a critical performance issue or there is a better way to handle this case.\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/apache/incubator-reef/pull/522/files#r41121531>.\n>\n\n\n\n-- \nByung-Gon Chun\n","created_at":"2015-10-05T15:02:58Z","updated_at":"2015-10-05T15:02:58Z","html_url":"https://github.com/apache/incubator-reef/pull/522#discussion_r41154167","pull_request_url":"https://api.github.com/repos/apache/incubator-reef/pulls/522","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/comments/41154167"},"html":{"href":"https://github.com/apache/incubator-reef/pull/522#discussion_r41154167"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/522"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-reef/pulls/522","id":45899752,"html_url":"https://github.com/apache/incubator-reef/pull/522","diff_url":"https://github.com/apache/incubator-reef/pull/522.diff","patch_url":"https://github.com/apache/incubator-reef/pull/522.patch","issue_url":"https://api.github.com/repos/apache/incubator-reef/issues/522","number":522,"state":"open","locked":false,"title":"[REEF-714] Service to report REEF events","user":{"login":"gwsshs22","id":4763030,"avatar_url":"https://avatars.githubusercontent.com/u/4763030?v=3","gravatar_id":"","url":"https://api.github.com/users/gwsshs22","html_url":"https://github.com/gwsshs22","followers_url":"https://api.github.com/users/gwsshs22/followers","following_url":"https://api.github.com/users/gwsshs22/following{/other_user}","gists_url":"https://api.github.com/users/gwsshs22/gists{/gist_id}","starred_url":"https://api.github.com/users/gwsshs22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwsshs22/subscriptions","organizations_url":"https://api.github.com/users/gwsshs22/orgs","repos_url":"https://api.github.com/users/gwsshs22/repos","events_url":"https://api.github.com/users/gwsshs22/events{/privacy}","received_events_url":"https://api.github.com/users/gwsshs22/received_events","type":"User","site_admin":false},"body":"This addressed the issue by\r\n * Create avro schema which wrap all driver-side event types of REEF control flow\r\n * Create Watcher that subscribes control flow events and transfer them to EventStream\r\n * Create LogEventStream and FileEventStream\r\n\r\nJIRA:\r\n[REEF-714](https://issues.apache.org/jira/browse/REEF-714)","created_at":"2015-09-24T13:56:03Z","updated_at":"2015-10-05T15:02:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aa61e4f7ee0c0d21620143f18a074264bda26408","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-reef/pulls/522/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-reef/pulls/522/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-reef/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-reef/issues/522/comments","statuses_url":"https://api.github.com/repos/apache/incubator-reef/statuses/eebdec6e7ce800f15d180b4697fbf333ea5b5890","head":{"label":"gwsshs22:REEF-714","ref":"REEF-714","sha":"eebdec6e7ce800f15d180b4697fbf333ea5b5890","user":{"login":"gwsshs22","id":4763030,"avatar_url":"https://avatars.githubusercontent.com/u/4763030?v=3","gravatar_id":"","url":"https://api.github.com/users/gwsshs22","html_url":"https://github.com/gwsshs22","followers_url":"https://api.github.com/users/gwsshs22/followers","following_url":"https://api.github.com/users/gwsshs22/following{/other_user}","gists_url":"https://api.github.com/users/gwsshs22/gists{/gist_id}","starred_url":"https://api.github.com/users/gwsshs22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwsshs22/subscriptions","organizations_url":"https://api.github.com/users/gwsshs22/orgs","repos_url":"https://api.github.com/users/gwsshs22/repos","events_url":"https://api.github.com/users/gwsshs22/events{/privacy}","received_events_url":"https://api.github.com/users/gwsshs22/received_events","type":"User","site_admin":false},"repo":{"id":39988274,"name":"incubator-reef","full_name":"gwsshs22/incubator-reef","owner":{"login":"gwsshs22","id":4763030,"avatar_url":"https://avatars.githubusercontent.com/u/4763030?v=3","gravatar_id":"","url":"https://api.github.com/users/gwsshs22","html_url":"https://github.com/gwsshs22","followers_url":"https://api.github.com/users/gwsshs22/followers","following_url":"https://api.github.com/users/gwsshs22/following{/other_user}","gists_url":"https://api.github.com/users/gwsshs22/gists{/gist_id}","starred_url":"https://api.github.com/users/gwsshs22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwsshs22/subscriptions","organizations_url":"https://api.github.com/users/gwsshs22/orgs","repos_url":"https://api.github.com/users/gwsshs22/repos","events_url":"https://api.github.com/users/gwsshs22/events{/privacy}","received_events_url":"https://api.github.com/users/gwsshs22/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gwsshs22/incubator-reef","description":"Mirror of Apache REEF (Incubating)","fork":true,"url":"https://api.github.com/repos/gwsshs22/incubator-reef","forks_url":"https://api.github.com/repos/gwsshs22/incubator-reef/forks","keys_url":"https://api.github.com/repos/gwsshs22/incubator-reef/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gwsshs22/incubator-reef/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gwsshs22/incubator-reef/teams","hooks_url":"https://api.github.com/repos/gwsshs22/incubator-reef/hooks","issue_events_url":"https://api.github.com/repos/gwsshs22/incubator-reef/issues/events{/number}","events_url":"https://api.github.com/repos/gwsshs22/incubator-reef/events","assignees_url":"https://api.github.com/repos/gwsshs22/incubator-reef/assignees{/user}","branches_url":"https://api.github.com/repos/gwsshs22/incubator-reef/branches{/branch}","tags_url":"https://api.github.com/repos/gwsshs22/incubator-reef/tags","blobs_url":"https://api.github.com/repos/gwsshs22/incubator-reef/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gwsshs22/incubator-reef/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gwsshs22/incubator-reef/git/refs{/sha}","trees_url":"https://api.github.com/repos/gwsshs22/incubator-reef/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gwsshs22/incubator-reef/statuses/{sha}","languages_url":"https://api.github.com/repos/gwsshs22/incubator-reef/languages","stargazers_url":"https://api.github.com/repos/gwsshs22/incubator-reef/stargazers","contributors_url":"https://api.github.com/repos/gwsshs22/incubator-reef/contributors","subscribers_url":"https://api.github.com/repos/gwsshs22/incubator-reef/subscribers","subscription_url":"https://api.github.com/repos/gwsshs22/incubator-reef/subscription","commits_url":"https://api.github.com/repos/gwsshs22/incubator-reef/commits{/sha}","git_commits_url":"https://api.github.com/repos/gwsshs22/incubator-reef/git/commits{/sha}","comments_url":"https://api.github.com/repos/gwsshs22/incubator-reef/comments{/number}","issue_comment_url":"https://api.github.com/repos/gwsshs22/incubator-reef/issues/comments{/number}","contents_url":"https://api.github.com/repos/gwsshs22/incubator-reef/contents/{+path}","compare_url":"https://api.github.com/repos/gwsshs22/incubator-reef/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gwsshs22/incubator-reef/merges","archive_url":"https://api.github.com/repos/gwsshs22/incubator-reef/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gwsshs22/incubator-reef/downloads","issues_url":"https://api.github.com/repos/gwsshs22/incubator-reef/issues{/number}","pulls_url":"https://api.github.com/repos/gwsshs22/incubator-reef/pulls{/number}","milestones_url":"https://api.github.com/repos/gwsshs22/incubator-reef/milestones{/number}","notifications_url":"https://api.github.com/repos/gwsshs22/incubator-reef/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gwsshs22/incubator-reef/labels{/name}","releases_url":"https://api.github.com/repos/gwsshs22/incubator-reef/releases{/id}","created_at":"2015-07-31T05:27:17Z","updated_at":"2015-07-31T05:27:23Z","pushed_at":"2015-10-05T08:39:51Z","git_url":"git://github.com/gwsshs22/incubator-reef.git","ssh_url":"git@github.com:gwsshs22/incubator-reef.git","clone_url":"https://github.com/gwsshs22/incubator-reef.git","svn_url":"https://github.com/gwsshs22/incubator-reef","homepage":null,"size":31639,"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":"db8dd549f60bbeee12b632b75187ab52914ada0f","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":25623941,"name":"incubator-reef","full_name":"apache/incubator-reef","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/incubator-reef","description":"Mirror of Apache REEF (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-reef","forks_url":"https://api.github.com/repos/apache/incubator-reef/forks","keys_url":"https://api.github.com/repos/apache/incubator-reef/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-reef/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-reef/teams","hooks_url":"https://api.github.com/repos/apache/incubator-reef/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-reef/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-reef/events","assignees_url":"https://api.github.com/repos/apache/incubator-reef/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-reef/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-reef/tags","blobs_url":"https://api.github.com/repos/apache/incubator-reef/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-reef/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-reef/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-reef/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-reef/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-reef/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-reef/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-reef/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-reef/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-reef/subscription","commits_url":"https://api.github.com/repos/apache/incubator-reef/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-reef/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-reef/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-reef/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-reef/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-reef/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-reef/merges","archive_url":"https://api.github.com/repos/apache/incubator-reef/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-reef/downloads","issues_url":"https://api.github.com/repos/apache/incubator-reef/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-reef/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-reef/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-reef/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-reef/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-reef/releases{/id}","created_at":"2014-10-23T07:00:10Z","updated_at":"2015-09-14T06:39:15Z","pushed_at":"2015-10-05T10:23:58Z","git_url":"git://github.com/apache/incubator-reef.git","ssh_url":"git@github.com:apache/incubator-reef.git","clone_url":"https://github.com/apache/incubator-reef.git","svn_url":"https://github.com/apache/incubator-reef","homepage":null,"size":45048,"stargazers_count":26,"watchers_count":26,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":36,"mirror_url":"git://git.apache.org/incubator-reef.git","open_issues_count":11,"forks":36,"open_issues":11,"watchers":26,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/522"},"html":{"href":"https://github.com/apache/incubator-reef/pull/522"},"issue":{"href":"https://api.github.com/repos/apache/incubator-reef/issues/522"},"comments":{"href":"https://api.github.com/repos/apache/incubator-reef/issues/522/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/522/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/522/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-reef/statuses/eebdec6e7ce800f15d180b4697fbf333ea5b5890"}}}}