src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java
author egahlin
Fri, 09 Aug 2019 01:18:18 +0200
branchJEP-349-branch
changeset 57690 9316d02dd4a5
parent 57604 838f9a7635b6
child 57861 86022e34ba63
permissions -rw-r--r--
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     1
/*
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     4
 *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    10
 *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    15
 * accompanied this code).
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    16
 *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    20
 *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    23
 * questions.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    24
 */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    25
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    26
package jdk.jfr.consumer;
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    27
57372
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
    28
import java.io.IOException;
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    29
import java.nio.file.Path;
57372
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
    30
import java.security.AccessControlContext;
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
    31
import java.security.AccessController;
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    32
import java.time.Duration;
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57433
diff changeset
    33
import java.time.Instant;
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    34
import java.util.Arrays;
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    35
import java.util.Objects;
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    36
import java.util.function.Consumer;
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    37
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    38
import jdk.jfr.internal.consumer.FileAccess;
57372
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
    39
import jdk.jfr.internal.consumer.RecordingInput;
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
    40
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    41
/**
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    42
 * Implementation of an event stream that operates against a recording file.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    43
 *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    44
 */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    45
final class EventFileStream implements EventStream {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    46
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    47
    private final static class FileStream extends AbstractEventStream {
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    48
        private static final int DEFAULT_ARRAY_SIZE = 100_000;
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    49
57372
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
    50
        private final RecordingInput input;
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    51
57374
41f0051285e0 First stab at EventFileStream
egahlin
parents: 57372
diff changeset
    52
        private ChunkParser chunkParser;
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    53
        private RecordedEvent[] sortedList;
57385
7d9d4f629f6e Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents: 57380
diff changeset
    54
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    55
        public FileStream(AccessControlContext acc, Path path) throws IOException {
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    56
            super(acc, false);
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    57
            this.input = new RecordingInput(path.toFile(), FileAccess.UNPRIVILIGED);
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    58
;        }
57372
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
    59
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
    60
        @Override
57385
7d9d4f629f6e Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents: 57380
diff changeset
    61
        public void process() throws IOException {
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    62
            final StreamConfiguration c1 = configuration;
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    63
            long start = 0;
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    64
            long end = Long.MAX_VALUE;
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    65
            if (c1.getStartTime() != null) {
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    66
                start = c1.getStartNanos();
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    67
            }
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    68
            if (c1.getEndTime() != null) {
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    69
                end = c1.getEndNanos();
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    70
            }
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    71
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    72
            chunkParser = new ChunkParser(input, c1.getReuse());
57385
7d9d4f629f6e Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents: 57380
diff changeset
    73
            while (!isClosed()) {
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    74
                if (chunkParser.getStartNanos() > end) {
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    75
                    close();
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    76
                    return;
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    77
                }
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    78
                StreamConfiguration c2 = configuration;
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    79
                boolean ordered = c2.getOrdered();
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    80
                chunkParser.setFirstNanos(start);
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
    81
                chunkParser.setLastNanos(end);
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    82
                chunkParser.setReuse(c2.getReuse());
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    83
                chunkParser.setOrdered(ordered);
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    84
                chunkParser.resetEventCache();
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    85
                chunkParser.setParserFilter(c2.getFiler());
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    86
                chunkParser.updateEventParsers();
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    87
                clearLastDispatch();
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    88
                if (ordered) {
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    89
                    processOrdered();
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    90
                } else {
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    91
                    processUnordered();
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    92
                }
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
    93
                runFlushActions();
57385
7d9d4f629f6e Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents: 57380
diff changeset
    94
                if (chunkParser.isLastChunk()) {
7d9d4f629f6e Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents: 57380
diff changeset
    95
                    return;
7d9d4f629f6e Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents: 57380
diff changeset
    96
                }
7d9d4f629f6e Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents: 57380
diff changeset
    97
                chunkParser = chunkParser.nextChunkParser();
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    98
            }
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
    99
        }
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   100
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   101
        private void processOrdered() throws IOException {
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   102
            if (sortedList == null) {
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   103
                sortedList = new RecordedEvent[DEFAULT_ARRAY_SIZE];
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   104
            }
57376
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57374
diff changeset
   105
            RecordedEvent event;
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   106
            int index = 0;
57376
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57374
diff changeset
   107
            while (true) {
57374
41f0051285e0 First stab at EventFileStream
egahlin
parents: 57372
diff changeset
   108
                event = chunkParser.readEvent();
41f0051285e0 First stab at EventFileStream
egahlin
parents: 57372
diff changeset
   109
                if (event == null) {
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   110
                    Arrays.sort(sortedList, 0, index, END_TIME);
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   111
                    for (int i = 0; i < index; i++) {
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   112
                        dispatch(sortedList[i]);
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   113
                    }
57385
7d9d4f629f6e Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents: 57380
diff changeset
   114
                    return;
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   115
                }
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   116
                if (index == sortedList.length) {
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   117
                    RecordedEvent[] tmp = sortedList;
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   118
                    sortedList = new RecordedEvent[2 * tmp.length];
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   119
                    System.arraycopy(tmp, 0, sortedList, 0, tmp.length);
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   120
                }
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   121
                sortedList[index++] = event;
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   122
            }
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   123
        }
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   124
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   125
        private void processUnordered() throws IOException {
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   126
            RecordedEvent event;
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   127
            while (!isClosed()) {
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   128
                event = chunkParser.readEvent();
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   129
                if (event == null) {
57385
7d9d4f629f6e Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents: 57380
diff changeset
   130
                    return;
57374
41f0051285e0 First stab at EventFileStream
egahlin
parents: 57372
diff changeset
   131
                }
41f0051285e0 First stab at EventFileStream
egahlin
parents: 57372
diff changeset
   132
                dispatch(event);
41f0051285e0 First stab at EventFileStream
egahlin
parents: 57372
diff changeset
   133
            }
41f0051285e0 First stab at EventFileStream
egahlin
parents: 57372
diff changeset
   134
        }
41f0051285e0 First stab at EventFileStream
egahlin
parents: 57372
diff changeset
   135
57386
acdd0dbe37ee First parts of unshared parser + updated javadoc
egahlin
parents: 57385
diff changeset
   136
        @Override
acdd0dbe37ee First parts of unshared parser + updated javadoc
egahlin
parents: 57385
diff changeset
   137
        public void close() {
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   138
            setClosed(true);;
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   139
            runCloseActions();
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   140
            try {
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   141
                input.close();
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   142
            } catch (IOException e) {
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   143
                // ignore
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   144
            }
57386
acdd0dbe37ee First parts of unshared parser + updated javadoc
egahlin
parents: 57385
diff changeset
   145
        }
57372
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
   146
    }
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
   147
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   148
    private final FileStream eventStream;
57372
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
   149
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57433
diff changeset
   150
    public EventFileStream(Path path, Instant from, Instant to) throws IOException {
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   151
        Objects.requireNonNull(path);
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   152
        eventStream = new FileStream(AccessController.getContext(), path);
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   153
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   154
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   155
    @Override
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   156
    public void onEvent(Consumer<RecordedEvent> action) {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   157
        Objects.requireNonNull(action);
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   158
        eventStream.onEvent(action);
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   159
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   160
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   161
    @Override
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   162
    public void onEvent(String eventName, Consumer<RecordedEvent> action) {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   163
        Objects.requireNonNull(eventName);
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   164
        Objects.requireNonNull(action);
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   165
        eventStream.onEvent(eventName, action);
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   166
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   167
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   168
    @Override
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   169
    public void onFlush(Runnable action) {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   170
        Objects.requireNonNull(action);
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   171
        eventStream.onFlush(action);
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   172
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   173
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   174
    @Override
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   175
    public void onClose(Runnable action) {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   176
        Objects.requireNonNull(action);
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   177
        eventStream.addCloseAction(action);
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   178
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   179
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   180
    @Override
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   181
    public void close() {
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   182
        eventStream.close();
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   183
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   184
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   185
    @Override
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   186
    public boolean remove(Object action) {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   187
        Objects.requireNonNull(action);
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   188
        return eventStream.remove(action);
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   189
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   190
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   191
    @Override
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   192
    public void start() {
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   193
        eventStream.start(0);
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   194
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   195
57433
83e4343a6984 Clean up and fix parser level filtering
egahlin
parents: 57432
diff changeset
   196
    @Override
57376
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57374
diff changeset
   197
    public void setReuse(boolean reuse) {
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   198
        eventStream.setReuse(reuse);
57376
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57374
diff changeset
   199
    }
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57374
diff changeset
   200
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   201
    @Override
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   202
    public void startAsync() {
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   203
        eventStream.startAsync(0);
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   204
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   205
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   206
    @Override
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   207
    public void awaitTermination(Duration timeout) {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   208
        Objects.requireNonNull(timeout);
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   209
        eventStream.awaitTermination(timeout);
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   210
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   211
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   212
    @Override
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   213
    public void awaitTermination() {
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   214
        eventStream.awaitTermination();
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   215
    }
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   216
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   217
    @Override
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   218
    public void setOrdered(boolean ordered) {
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   219
        eventStream.setOrdered(ordered);
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57376
diff changeset
   220
    }
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57433
diff changeset
   221
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57433
diff changeset
   222
    @Override
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57433
diff changeset
   223
    public void setStartTime(Instant startTime) {
57604
838f9a7635b6 Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents: 57452
diff changeset
   224
        eventStream.setStartTime(startTime);
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57433
diff changeset
   225
    }
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
   226
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
   227
    @Override
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
   228
    public void setEndTime(Instant endTime) {
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
   229
        eventStream.setEndTime(endTime);
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57604
diff changeset
   230
    }
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   231
}