author | egahlin |
Mon, 27 May 2019 18:33:13 +0200 | |
branch | JEP-349-branch |
changeset 57376 | 8e8a06a3059c |
parent 57372 | 50ca040843ea |
child 57377 | 528d85d2fce5 |
permissions | -rw-r--r-- |
57361 | 1 |
/* |
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.jfr.consumer; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.nio.file.Path; |
|
30 |
import java.time.Duration; |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
31 |
import java.time.Instant; |
57361 | 32 |
import java.util.function.Consumer; |
33 |
||
34 |
/** |
|
35 |
* Represents a stream of event that actions can be performed up on. |
|
36 |
*/ |
|
37 |
public interface EventStream extends AutoCloseable { |
|
38 |
||
39 |
/** |
|
40 |
* Creates a stream starting from the next written event in a disk |
|
41 |
* repository. |
|
42 |
* |
|
43 |
* @param directory location of the disk repository, not {@code null} |
|
44 |
* @return an event stream, not {@code null} |
|
45 |
*/ |
|
46 |
public static EventStream openRepository(Path directory) throws IOException { |
|
47 |
throw new UnsupportedOperationException("Not yet implemented"); |
|
57376 | 48 |
// AccessControlContext acc = AccessController.getContext(); |
49 |
// return new EventDirectoryStream(acc); |
|
57361 | 50 |
} |
51 |
||
52 |
/** |
|
53 |
* Creates an event stream starting from the first event in a file. |
|
54 |
* |
|
55 |
* @param file location of the file, not {@code null} |
|
56 |
* @return an event stream, not {@code null} |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
57 |
* |
57376 | 58 |
* @throws IOException if a stream can't be opened,or an I/O error occurs |
59 |
* during reading |
|
57361 | 60 |
*/ |
61 |
public static EventStream openFile(Path file) throws IOException { |
|
62 |
throw new UnsupportedOperationException("Not yet implemented"); |
|
57376 | 63 |
// return new EventFileStream(file); |
57361 | 64 |
} |
65 |
||
66 |
/** |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
67 |
* Creates an event stream starting start time and end time in a file. |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
68 |
* |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
69 |
* @param file location of the file, not {@code null} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
70 |
* |
57376 | 71 |
* @param the start start time for the stream, or {@code null} to get data |
72 |
* from the beginning of the |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
73 |
* |
57376 | 74 |
* @param the end end time for the stream, or {@code null} to get data until |
75 |
* the end. |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
76 |
* |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
77 |
* @throws IllegalArgumentException if {@code end} happens before |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
78 |
* {@code start} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
79 |
* |
57376 | 80 |
* @throws IOException if a stream can't be opened,or an I/O error occurs |
81 |
* during reading |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
82 |
*/ |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
83 |
public static EventStream openFile(Path file, Instant from, Instant to) throws IOException { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
84 |
throw new UnsupportedOperationException("Not yet implemented"); |
57376 | 85 |
// return new EventFileStream(file); |
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
86 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
87 |
|
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
88 |
/** |
57361 | 89 |
* Performs an action on all events in the stream. |
90 |
* |
|
91 |
* @param action an action to be performed on each {@code RecordedEvent}, |
|
92 |
* not {@code null} |
|
93 |
*/ |
|
94 |
void onEvent(Consumer<RecordedEvent> action); |
|
95 |
||
96 |
/** |
|
97 |
* Performs an action on all events in the stream with a specified name. |
|
98 |
* |
|
99 |
* @param eventName the name of the event, not {@code null} |
|
100 |
* @param action an action to be performed on each {@code RecordedEvent} |
|
101 |
* that matches the event name, not {@code null} |
|
102 |
*/ |
|
103 |
void onEvent(String eventName, Consumer<RecordedEvent> action); |
|
104 |
||
105 |
/** |
|
106 |
* Performs an action when the event stream has been flushed. |
|
107 |
* |
|
108 |
* @param action an action to be performed after stream has been flushed, |
|
109 |
* not {@code null} |
|
110 |
*/ |
|
111 |
void onFlush(Runnable action); |
|
112 |
||
113 |
/** |
|
114 |
* Performs an action when the event stream is closed. |
|
115 |
* |
|
116 |
* @param action an action to be performed after the stream has been closed, |
|
117 |
* not {@code null} |
|
118 |
*/ |
|
119 |
void onClose(Runnable action); |
|
120 |
||
121 |
/** |
|
122 |
* Releases all resources associated with this event stream. |
|
123 |
*/ |
|
124 |
void close(); |
|
125 |
||
126 |
/** |
|
127 |
* Removes an action from the stream. |
|
128 |
* <p> |
|
129 |
* If the action has been added multiple times, all instance of it will be |
|
130 |
* removed. |
|
131 |
* |
|
132 |
* @param action the action to remove, not {@code null} |
|
133 |
* @return {@code true} if the action was removed, {@code false} otherwise |
|
134 |
* |
|
135 |
* @see #onClose(Runnable) |
|
136 |
* @see #onFlush(Runnable) |
|
137 |
* @see #onEvent(Consumer) |
|
138 |
* @see #onEvent(String, Consumer) |
|
139 |
*/ |
|
140 |
boolean remove(Object action); |
|
141 |
||
142 |
/** |
|
57376 | 143 |
* Hint that the the event object in an {@link #onEvent(Consumer)} action |
144 |
* may be reused. |
|
145 |
* <p> |
|
146 |
* If reuse is set to |
|
147 |
* {@code true), a callback should not keep a reference to the event object |
|
148 |
* after the callback from {@code onEvent} has returned. |
|
149 |
* <p> |
|
150 |
* By default reuse is {@code true} |
|
151 |
* |
|
152 |
*/ |
|
153 |
public void setReuse(boolean reuse); |
|
154 |
||
155 |
/** |
|
57361 | 156 |
* Starts processing events in the stream. |
157 |
* <p> |
|
158 |
* All actions will performed on this stream will happen in the current |
|
159 |
* thread. |
|
160 |
* |
|
161 |
* @throws IllegalStateException if the stream is already started or if it |
|
162 |
* has been closed |
|
163 |
*/ |
|
164 |
void start(); |
|
165 |
||
166 |
/** |
|
167 |
* Starts processing events in the stream asynchronously. |
|
168 |
* <p> |
|
169 |
* All actions on this stream will be performed in a separate thread. |
|
170 |
* |
|
171 |
* @throws IllegalStateException if the stream is already started or if it |
|
172 |
* has been closed |
|
173 |
*/ |
|
174 |
void startAsync(); |
|
175 |
||
176 |
/** |
|
177 |
* Blocks the current thread until the stream is finished, closed, or it |
|
178 |
* times out. |
|
179 |
* |
|
180 |
* @param timeout the maximum time to wait, not {@code null} |
|
181 |
* |
|
182 |
* @see #start() |
|
183 |
* @see #startAsync() |
|
184 |
*/ |
|
185 |
void awaitTermination(Duration timeout); |
|
186 |
||
187 |
/** |
|
188 |
* Blocks the current thread until the stream is finished or closed. |
|
189 |
* |
|
190 |
* @see #start() |
|
191 |
* @see #startAsync() |
|
192 |
*/ |
|
193 |
void awaitTermination(); |
|
194 |
} |