--- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java Mon Aug 05 23:57:47 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java Fri Aug 09 01:18:18 2019 +0200
@@ -27,15 +27,18 @@
import java.io.IOException;
import java.nio.file.Path;
+import java.security.AccessControlContext;
import java.security.AccessController;
import java.time.Duration;
import java.time.Instant;
+import java.util.Objects;
import java.util.function.Consumer;
-import jdk.jfr.internal.Repository;
+import jdk.jfr.internal.Utils;
+import jdk.jfr.internal.consumer.FileAccess;
/**
- * Represents a stream of event that actions can be performed up on.
+ * Represents a stream of events.
*/
public interface EventStream extends AutoCloseable {
@@ -50,16 +53,18 @@
*
* @throws IOException if a stream can't be opened, or an I/O error occurs
* when trying to access the repository
+ *
+ * @throws SecurityException if a security manager exists and the caller
+ * does not have
+ * {@code FlightRecorderPermission("accessFlightRecorder")}
*/
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);
+ Utils.checkAccessFlightRecorder();
+ return new EventDirectoryStream(AccessController.getContext(), null, FileAccess.PRIVILIGED, false);
}
/**
- * Creates a stream from a disk repository.
+ * Creates an event stream from a disk repository.
* <p>
* By default, the stream starts with the next event flushed by Flight
* Recorder.
@@ -68,11 +73,17 @@
*
* @return an event stream, not {@code null}
*
- * @throws IOException if a stream can't be opened, or an I/O error occurs
+ * @throws IOException if a stream can't be opened, or an I/O error occurs
* when trying to access the repository
+ *
+ * @throws SecurityException if a security manager exists and its
+ * {@code checkRead} method denies read access to the directory, or
+ * files in the directory.
*/
public static EventStream openRepository(Path directory) throws IOException {
- return new EventDirectoryStream(AccessController.getContext(), directory, AbstractEventStream.NEXT_EVENT);
+ Objects.nonNull(directory);
+ AccessControlContext acc = AccessController.getContext();
+ return new EventDirectoryStream(acc, directory, FileAccess.UNPRIVILIGED, false);
}
/**
@@ -86,6 +97,9 @@
*
* @throws IOException if a stream can't be opened, or an I/O error occurs
* during reading
+ *
+ * @throws SecurityException if a security manager exists and its
+ * {@code checkRead} method denies read access to the file
*/
public static EventStream openFile(Path file) throws IOException {
return new EventFileStream(file, null, null);
@@ -174,6 +188,8 @@
/**
* Specifies start time of the event stream.
+ * <p>
+ * The start time must be set before the stream is started.
*
* @param startTime the start time, not {@code null}
*
@@ -182,6 +198,20 @@
public void setStartTime(Instant startTime);
/**
+ * Specifies end time of the event stream.
+ * <p>
+ * The end time must be set before the stream is started.
+ * <p>
+ * When the end time is reached the stream is terminated.
+ *
+ * @param endTime the end time, not {@code null}
+ *
+ * @throws IllegalStateException if the stream has already been started
+ */
+ public void setEndTime(Instant endTime);
+
+
+ /**
* Start processing events in the stream.
* <p>
* All actions performed on this stream will happen in the current thread.