Add EventStream::openRepository() method JEP-349-branch
authoregahlin
Fri, 02 Aug 2019 20:04:02 +0200
branchJEP-349-branch
changeset 57627 b38c7a822244
parent 57614 b49f5c13baa7
child 57628 f5f590eaecf5
Add EventStream::openRepository() method
src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java	Thu Aug 01 16:48:26 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java	Fri Aug 02 20:04:02 2019 +0200
@@ -32,22 +32,44 @@
 import java.time.Instant;
 import java.util.function.Consumer;
 
+import jdk.jfr.internal.Repository;
+
 /**
  * Represents a stream of event that actions can be performed up on.
  */
 public interface EventStream extends AutoCloseable {
 
     /**
+     * Creates a stream from the disk repository of the current Java Virtual
+     * Machine (JVM).
+     * <p>
+     * By default, the stream starts with the next event flushed by Flight
+     * Recorder.
+     *
+     * @return an event stream, not {@code null}
+     *
+     * @throws IOException if a stream can't be opened, or an I/O error occurs
+     *         when trying to access the repository
+     */
+    public static EventStream openRepository() throws IOException {
+        Repository r = Repository.getRepository();
+        r.ensureRepository();
+        Path path = r.getRepositoryPath().toPath();
+        return new EventDirectoryStream(AccessController.getContext(), path, AbstractEventStream.NEXT_EVENT);
+    }
+
+    /**
      * Creates a stream from a disk repository.
      * <p>
-     * By default, the stream starts with the next event flushed by Flight Recorder.
+     * By default, the stream starts with the next event flushed by Flight
+     * Recorder.
      *
      * @param directory location of the disk repository, not {@code null}
      *
      * @return an event stream, not {@code null}
      *
-     * @throws IOException if a stream can't be opened, or an I/O error occurs
-     *         during reading
+      * @throws IOException if a stream can't be opened, or an I/O error occurs
+     *         when trying to access the repository
      */
     public static EventStream openRepository(Path directory) throws IOException {
         return new EventDirectoryStream(AccessController.getContext(), directory, AbstractEventStream.NEXT_EVENT);