src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java
branchJEP-349-branch
changeset 57449 099789ceff7d
parent 57433 83e4343a6984
child 57452 6fabe73e5d9a
equal deleted inserted replaced
57434:216bf2e3b542 57449:099789ceff7d
    28 import java.io.IOException;
    28 import java.io.IOException;
    29 import java.nio.file.Path;
    29 import java.nio.file.Path;
    30 import java.security.AccessControlContext;
    30 import java.security.AccessControlContext;
    31 import java.security.AccessController;
    31 import java.security.AccessController;
    32 import java.time.Duration;
    32 import java.time.Duration;
       
    33 import java.time.Instant;
    33 import java.util.Arrays;
    34 import java.util.Arrays;
    34 import java.util.Comparator;
    35 import java.util.Comparator;
    35 import java.util.Objects;
    36 import java.util.Objects;
    36 import java.util.function.Consumer;
    37 import java.util.function.Consumer;
    37 
    38 
    38 import jdk.jfr.internal.consumer.EventConsumer;
       
    39 import jdk.jfr.internal.consumer.RecordingInput;
    39 import jdk.jfr.internal.consumer.RecordingInput;
    40 
    40 
    41 /**
    41 /**
    42  * Implementation of an event stream that operates against a recording file.
    42  * Implementation of an event stream that operates against a recording file.
    43  *
    43  *
    44  */
    44  */
    45 final class EventFileStream implements EventStream {
    45 final class EventFileStream implements EventStream {
    46 
    46 
    47     private final static class FileEventConsumer extends EventConsumer {
    47     private final static class FileConsumer extends EventConsumer {
    48         private static final Comparator<? super RecordedEvent> END_TIME = (e1, e2) -> Long.compare(e1.endTime, e2.endTime);
    48         private static final Comparator<? super RecordedEvent> END_TIME = (e1, e2) -> Long.compare(e1.endTime, e2.endTime);
    49         private static final int DEFAULT_ARRAY_SIZE = 100_000;
    49         private static final int DEFAULT_ARRAY_SIZE = 100_000;
    50         private final RecordingInput input;
    50         private final RecordingInput input;
    51         private ChunkParser chunkParser;
    51         private ChunkParser chunkParser;
    52         private boolean reuse = true;
    52         private boolean reuse = true;
    53         private RecordedEvent[] sortedList;
    53         private RecordedEvent[] sortedList;
    54         private boolean ordered;
    54         private boolean ordered;
    55 
    55 
    56         public FileEventConsumer(AccessControlContext acc, RecordingInput input) throws IOException {
    56         public FileConsumer(AccessControlContext acc, RecordingInput input) throws IOException {
    57             super(acc);
    57             super(acc);
    58             this.input = input;
    58             this.input = input;
    59         }
    59         }
    60 
    60 
    61         @Override
    61         @Override
   127 
   127 
   128         @Override
   128         @Override
   129         public void close() {
   129         public void close() {
   130 
   130 
   131         }
   131         }
       
   132 
       
   133 
   132     }
   134     }
   133 
   135 
   134     private final RecordingInput input;
   136     private final RecordingInput input;
   135     private final FileEventConsumer eventConsumer;
   137     private final FileConsumer eventConsumer;
   136 
   138 
   137     public EventFileStream(Path path) throws IOException {
   139     public EventFileStream(Path path, Instant from, Instant to) throws IOException {
   138         Objects.requireNonNull(path);
   140         Objects.requireNonNull(path);
   139         input = new RecordingInput(path.toFile());
   141         input = new RecordingInput(path.toFile());
   140         eventConsumer = new FileEventConsumer(AccessController.getContext(), input);
   142         eventConsumer = new FileConsumer(AccessController.getContext(), input);
   141     }
   143     }
   142 
   144 
   143     @Override
   145     @Override
   144     public void onEvent(Consumer<RecordedEvent> action) {
   146     public void onEvent(Consumer<RecordedEvent> action) {
   145         Objects.requireNonNull(action);
   147         Objects.requireNonNull(action);
   210 
   212 
   211     @Override
   213     @Override
   212     public void setOrdered(boolean ordered) {
   214     public void setOrdered(boolean ordered) {
   213         eventConsumer.setOrdered(ordered);
   215         eventConsumer.setOrdered(ordered);
   214     }
   216     }
       
   217 
       
   218     @Override
       
   219     public void setStartTime(Instant startTime) {
       
   220         eventConsumer.setStartTime(startTime);
       
   221     }
   215 }
   222 }