src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java
author egahlin
Fri, 30 Aug 2019 20:39:38 +0200
branchJEP-349-branch
changeset 57971 aa7b1ea52413
parent 57780 d8a436dfa041
child 57985 be121cbf3284
permissions -rw-r--r--
Add onError handler + various cleanup
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
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    28
import java.io.IOException;
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    29
import java.nio.file.Path;
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    30
import java.security.AccessControlContext;
57434
216bf2e3b542 Add support for EventStrem::openRepository
egahlin
parents: 57386
diff changeset
    31
import java.security.AccessController;
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    32
import java.time.Duration;
57372
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
    33
import java.time.Instant;
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    34
import java.util.Objects;
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    35
import java.util.function.Consumer;
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    36
57717
4ce66d271065 Security handling, but two tests fails with driver
egahlin
parents: 57690
diff changeset
    37
import jdk.jfr.internal.SecuritySupport;
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    38
import jdk.jfr.internal.Utils;
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    39
import jdk.jfr.internal.consumer.FileAccess;
57627
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    40
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    41
/**
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    42
 * Represents a stream of events.
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    43
 */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    44
public interface EventStream extends AutoCloseable {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    45
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    46
    /**
57627
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    47
     * Creates a stream from the disk repository of the current Java Virtual
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    48
     * Machine (JVM).
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    49
     * <p>
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    50
     * By default, the stream starts with the next event flushed by Flight
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    51
     * Recorder.
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    52
     *
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    53
     * @return an event stream, not {@code null}
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    54
     *
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    55
     * @throws IOException if a stream can't be opened, or an I/O error occurs
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    56
     *         when trying to access the repository
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    57
     *
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    58
     * @throws SecurityException if a security manager exists and the caller
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    59
     *         does not have
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    60
     *         {@code FlightRecorderPermission("accessFlightRecorder")}
57627
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    61
     */
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    62
    public static EventStream openRepository() throws IOException {
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    63
        Utils.checkAccessFlightRecorder();
57717
4ce66d271065 Security handling, but two tests fails with driver
egahlin
parents: 57690
diff changeset
    64
        return new EventDirectoryStream(AccessController.getContext(), null, SecuritySupport.PRIVILIGED, false);
57627
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    65
    }
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    66
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    67
    /**
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    68
     * Creates an event stream from a disk repository.
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
    69
     * <p>
57627
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    70
     * By default, the stream starts with the next event flushed by Flight
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    71
     * Recorder.
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    72
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    73
     * @param directory location of the disk repository, not {@code null}
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
    74
     *
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    75
     * @return an event stream, not {@code null}
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
    76
     *
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    77
     * @throws IOException if a stream can't be opened, or an I/O error occurs
57627
b38c7a822244 Add EventStream::openRepository() method
egahlin
parents: 57604
diff changeset
    78
     *         when trying to access the repository
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    79
     *
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    80
     * @throws SecurityException if a security manager exists and its
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    81
     *         {@code checkRead} method denies read access to the directory, or
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    82
     *         files in the directory.
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    83
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    84
    public static EventStream openRepository(Path directory) throws IOException {
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    85
        Objects.nonNull(directory);
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    86
        AccessControlContext acc = AccessController.getContext();
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
    87
        return new EventDirectoryStream(acc, directory, FileAccess.UNPRIVILIGED, false);
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    88
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    89
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    90
    /**
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
    91
     * Creates an event stream from a file.
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
    92
     * <p>
57452
6fabe73e5d9a Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents: 57449
diff changeset
    93
     * By default, the stream starts with the first event in the file.
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    94
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    95
     * @param file location of the file, not {@code null}
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
    96
     *
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    97
     * @return an event stream, not {@code null}
57372
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
    98
     *
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
    99
     * @throws IOException if a stream can't be opened, or an I/O error occurs
57376
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57372
diff changeset
   100
     *         during reading
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   101
     *
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   102
     * @throws SecurityException if a security manager exists and its
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   103
     *         {@code checkRead} method denies read access to the file
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   104
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   105
    public static EventStream openFile(Path file) throws IOException {
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   106
        return new EventFileStream(file, null, null);
57372
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
   107
    }
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
   108
50ca040843ea Prepare infrastructure for multiple implementations of EventStream
egahlin
parents: 57361
diff changeset
   109
    /**
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   110
     * Performs an action on all events in the stream.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   111
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   112
     * @param action an action to be performed on each {@code RecordedEvent},
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   113
     *        not {@code null}
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   114
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   115
    void onEvent(Consumer<RecordedEvent> action);
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   116
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   117
    /**
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   118
     * Performs an action on all events in the stream with a specified name.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   119
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   120
     * @param eventName the name of the event, not {@code null}
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   121
     *
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   122
     * @param action an action to be performed on each {@code RecordedEvent}
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   123
     *        that matches the event name, not {@code null}
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   124
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   125
    void onEvent(String eventName, Consumer<RecordedEvent> action);
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   126
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   127
    /**
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   128
     * Performs an action when the event stream has been flushed.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   129
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   130
     * @param action an action to be performed after stream has been flushed,
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   131
     *        not {@code null}
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   132
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   133
    void onFlush(Runnable action);
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   134
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   135
    /**
57971
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   136
     * Performs an action if an exception occurs when processing the stream.
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   137
     * <p>
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   138
     * if an error handler has not been added to the stream, an exception stack
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   139
     * trace is printed to standard error.
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   140
     * <p>
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   141
     * Adding an error handler overrides the default behavior. If multiple error
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   142
     * handlers have been added, they will be executed in the order they were
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   143
     * added.
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   144
     *
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   145
     * @param action an action to be performed if an exception occurs, not
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   146
     *        {@code null}
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   147
     */
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   148
    void onError(Consumer<Throwable> action);
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   149
aa7b1ea52413 Add onError handler + various cleanup
egahlin
parents: 57780
diff changeset
   150
    /**
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   151
     * Performs an action when the event stream is closed.
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   152
     * <p>
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   153
     * If the stream is already closed, the action will be executed immediately
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   154
     * in the current thread.
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   155
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   156
     * @param action an action to be performed after the stream has been closed,
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   157
     *        not {@code null}
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   158
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   159
    void onClose(Runnable action);
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   160
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   161
    /**
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   162
     * Releases all resources associated with this event stream.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   163
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   164
    void close();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   165
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   166
    /**
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   167
     * Removes an action from the stream.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   168
     * <p>
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   169
     * If the action has been added multiple times, all instance of it will be
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   170
     * removed.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   171
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   172
     * @param action the action to remove, not {@code null}
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   173
     *
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   174
     * @return {@code true} if the action was removed, {@code false} otherwise
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   175
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   176
     * @see #onClose(Runnable)
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   177
     * @see #onFlush(Runnable)
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   178
     * @see #onEvent(Consumer)
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   179
     * @see #onEvent(String, Consumer)
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   180
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   181
    boolean remove(Object action);
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   182
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   183
    /**
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   184
     * Specifies that the event object in an {@link #onEvent(Consumer)} action
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   185
     * is to be reused.
57376
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57372
diff changeset
   186
     * <p>
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57377
diff changeset
   187
     * If reuse is set to {@code true), a callback should not keep a reference
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57377
diff changeset
   188
     * to the event object after the callback from {@code onEvent} has returned.
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57377
diff changeset
   189
     *
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   190
     * @param resuse if event objects can be reused between calls to
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   191
     * {@code #onEvent(Consumer)}
57376
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57372
diff changeset
   192
     *
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57372
diff changeset
   193
     */
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57372
diff changeset
   194
    public void setReuse(boolean reuse);
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57372
diff changeset
   195
8e8a06a3059c Add foundation for event object reuse
egahlin
parents: 57372
diff changeset
   196
    /**
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   197
     * Specifies that events arrives in chronological order, sorted by the time
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   198
     * they were committed to the event stream.
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57377
diff changeset
   199
     *
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   200
     * @param ordered if event objects arrive in chronological order to
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   201
     *        {@code #onEvent(Consumer)}
57380
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57377
diff changeset
   202
     */
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57377
diff changeset
   203
    public void setOrdered(boolean ordered);
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57377
diff changeset
   204
6a7e7743b82f setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents: 57377
diff changeset
   205
    /**
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   206
     * Specifies start time of the event stream.
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   207
     * <p>
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   208
     * The start time must be set before the stream is started.
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   209
     *
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   210
     * @param startTime the start time, not {@code null}
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   211
     *
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   212
     * @throws IllegalStateException if the stream has already been started
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   213
     */
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   214
    public void setStartTime(Instant startTime);
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   215
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   216
    /**
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   217
     * Specifies end time of the event stream.
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   218
     * <p>
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   219
     * The end time must be set before the stream is started.
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   220
     * <p>
57780
d8a436dfa041 Minor docs fix
egahlin
parents: 57717
diff changeset
   221
     * When the end time is reached the stream is closed.
57690
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   222
     *
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   223
     * @param endTime the end time, not {@code null}
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   224
     *
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   225
     * @throws IllegalStateException if the stream has already been started
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   226
     */
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   227
    public void setEndTime(Instant endTime);
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   228
9316d02dd4a5 Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents: 57627
diff changeset
   229
    /**
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   230
     * Start processing events in the stream.
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   231
     * <p>
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   232
     * All actions performed on this stream will happen in the current thread.
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   233
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   234
     * @throws IllegalStateException if the stream is already started or if it
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   235
     *         has been closed
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   236
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   237
    void start();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   238
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   239
    /**
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   240
     * Start processing events in the stream asynchronously.
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   241
     * <p>
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   242
     * All actions on this stream will be performed in a separate thread.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   243
     *
57449
099789ceff7d Provide implementation for all added API methods
egahlin
parents: 57434
diff changeset
   244
     * @throws IllegalStateException if the stream is already started, or if it
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   245
     *         has been closed
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   246
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   247
    void startAsync();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   248
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   249
    /**
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   250
     * Blocks the current thread until the stream is finished, closed, or it
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   251
     * times out.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   252
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   253
     * @param timeout the maximum time to wait, not {@code null}
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   254
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   255
     * @see #start()
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   256
     * @see #startAsync()
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   257
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   258
    void awaitTermination(Duration timeout);
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   259
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   260
    /**
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   261
     * Blocks the current thread until the stream is finished or closed.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   262
     *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   263
     * @see #start()
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   264
     * @see #startAsync()
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   265
     */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   266
    void awaitTermination();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
   267
}