author | egahlin |
Tue, 25 Jun 2019 13:32:03 +0200 | |
branch | JEP-349-branch |
changeset 57427 | 596f839ce88f |
parent 57425 | 1da8552f0b59 |
child 57428 | ef3e241c420f |
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; |
|
57386 | 29 |
import java.nio.file.DirectoryStream; |
30 |
import java.nio.file.Files; |
|
31 |
import java.nio.file.Path; |
|
57361 | 32 |
import java.security.AccessControlContext; |
33 |
import java.time.Duration; |
|
34 |
import java.time.Instant; |
|
57386 | 35 |
import java.util.ArrayList; |
36 |
import java.util.Arrays; |
|
37 |
import java.util.Collections; |
|
38 |
import java.util.Comparator; |
|
39 |
import java.util.HashMap; |
|
40 |
import java.util.HashSet; |
|
41 |
import java.util.List; |
|
42 |
import java.util.Map; |
|
57361 | 43 |
import java.util.Objects; |
57386 | 44 |
import java.util.Set; |
45 |
import java.util.SortedMap; |
|
46 |
import java.util.TreeMap; |
|
57361 | 47 |
import java.util.function.Consumer; |
48 |
||
57386 | 49 |
import jdk.jfr.internal.LogLevel; |
50 |
import jdk.jfr.internal.LogTag; |
|
51 |
import jdk.jfr.internal.Logger; |
|
52 |
import jdk.jfr.internal.Repository; |
|
53 |
import jdk.jfr.internal.consumer.ChunkHeader; |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
54 |
import jdk.jfr.internal.consumer.EventConsumer; |
57386 | 55 |
import jdk.jfr.internal.consumer.RecordingInput; |
57361 | 56 |
|
57 |
final class EventDirectoryStream implements EventStream { |
|
58 |
||
57386 | 59 |
private static final class RepositoryFiles { |
60 |
private final Path repostory; |
|
61 |
private final SortedMap<Long, Path> pathSet = new TreeMap<>(); |
|
62 |
private final Map<Path, Long> pathLookup = new HashMap<>(); |
|
63 |
private volatile boolean closed; |
|
64 |
||
65 |
public RepositoryFiles(Path repostory) { |
|
66 |
this.repostory = repostory; |
|
67 |
} |
|
68 |
||
57425 | 69 |
long getTimestamp(Path p) { |
70 |
return pathLookup.get(p); |
|
71 |
} |
|
72 |
||
73 |
Path nextPath(long startTimeNanos) { |
|
57386 | 74 |
while (!closed) { |
57425 | 75 |
SortedMap<Long, Path> after = pathSet.tailMap(startTimeNanos); |
76 |
if (!after.isEmpty()) { |
|
77 |
Path path = after.get(after.firstKey()); |
|
78 |
Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.TRACE, "Return path " + path + " for start time nanos " + startTimeNanos); |
|
79 |
return path; |
|
80 |
} |
|
57386 | 81 |
try { |
57425 | 82 |
if (updatePaths(repostory)) { |
57386 | 83 |
continue; |
84 |
} |
|
85 |
} catch (IOException e) { |
|
86 |
Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.DEBUG, "IOException during repository file scan " + e.getMessage()); |
|
87 |
// This can happen if a chunk is being removed |
|
88 |
// between the file was discovered and an instance |
|
89 |
// of an EventSet was constructed. Just ignore, |
|
90 |
// and retry later. |
|
91 |
} |
|
92 |
try { |
|
57425 | 93 |
synchronized (pathSet) { |
94 |
pathSet.wait(1000); |
|
95 |
} |
|
57386 | 96 |
} catch (InterruptedException e) { |
97 |
// ignore |
|
98 |
} |
|
99 |
} |
|
100 |
return null; |
|
101 |
} |
|
102 |
||
57425 | 103 |
private boolean updatePaths(Path repo) throws IOException { |
104 |
if (repo == null) { |
|
105 |
repo = Repository.getRepository().getRepositoryPath().toPath(); |
|
106 |
} |
|
57386 | 107 |
boolean foundNew = false; |
108 |
List<Path> added = new ArrayList<>(); |
|
109 |
Set<Path> current = new HashSet<>(); |
|
57425 | 110 |
if (!Files.exists(repo)) { |
57386 | 111 |
// Repository removed, probably due to shutdown |
112 |
return true; |
|
113 |
} |
|
57425 | 114 |
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(repo, "*.jfr")) { |
57386 | 115 |
for (Path p : dirStream) { |
116 |
if (!pathLookup.containsKey(p)) { |
|
117 |
added.add(p); |
|
118 |
Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.DEBUG, "New file found: " + p.toAbsolutePath()); |
|
119 |
} |
|
120 |
current.add(p); |
|
121 |
} |
|
122 |
} |
|
123 |
List<Path> removed = new ArrayList<>(); |
|
124 |
for (Path p : pathLookup.keySet()) { |
|
125 |
if (!current.contains(p)) { |
|
126 |
removed.add(p); |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
for (Path remove : removed) { |
|
131 |
Long time = pathLookup.get(remove); |
|
132 |
pathSet.remove(time); |
|
133 |
pathLookup.remove(remove); |
|
134 |
} |
|
135 |
Collections.sort(added, (p1, p2) -> p1.compareTo(p2)); |
|
136 |
for (Path p : added) { |
|
137 |
// Only add files that have a complete header |
|
138 |
// as the JVM may be in progress writing the file |
|
139 |
long size = Files.size(p); |
|
140 |
if (size >= ChunkHeader.HEADER_SIZE) { |
|
141 |
long startNanos = readStartTime(p); |
|
142 |
pathSet.put(startNanos, p); |
|
143 |
pathLookup.put(p, startNanos); |
|
144 |
foundNew = true; |
|
145 |
} |
|
146 |
} |
|
147 |
return foundNew; |
|
148 |
} |
|
149 |
||
150 |
private long readStartTime(Path p) throws IOException { |
|
151 |
try (RecordingInput in = new RecordingInput(p.toFile(), 100)) { |
|
152 |
ChunkHeader c = new ChunkHeader(in); |
|
153 |
return c.getStartNanos(); |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
public void close() { |
|
158 |
synchronized (pathSet) { |
|
57425 | 159 |
this.closed = true; |
57386 | 160 |
pathSet.notify(); |
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
||
165 |
static final class ParserConsumer extends EventConsumer { |
|
166 |
||
167 |
private static final Comparator<? super RecordedEvent> END_TIME = (e1, e2) -> Long.compare(e1.endTime, e2.endTime); |
|
168 |
private static final int DEFAULT_ARRAY_SIZE = 10_000; |
|
169 |
private final RepositoryFiles repositoryFiles; |
|
170 |
private ChunkParser chunkParser; |
|
171 |
private boolean reuse = true; |
|
172 |
private RecordedEvent[] sortedList; |
|
57425 | 173 |
private boolean ordered = true; |
57386 | 174 |
|
175 |
public ParserConsumer(AccessControlContext acc, Path p) throws IOException { |
|
176 |
super(acc); |
|
177 |
repositoryFiles = new RepositoryFiles(p); |
|
178 |
} |
|
179 |
||
180 |
@Override |
|
181 |
public void process() throws IOException { |
|
57425 | 182 |
Path path = repositoryFiles.nextPath(startNanos); |
183 |
startNanos = repositoryFiles.getTimestamp(path) + 1; |
|
57386 | 184 |
try (RecordingInput input = new RecordingInput(path.toFile())) { |
57427 | 185 |
chunkParser = new ChunkParser(input, this.reuse); |
57386 | 186 |
while (!isClosed()) { |
57425 | 187 |
boolean awaitnewEvent = false; |
188 |
while (!isClosed() && !chunkParser.isChunkFinished()) { |
|
189 |
chunkParser.setReuse(this.reuse); |
|
190 |
chunkParser.setOrdered(this.ordered); |
|
191 |
chunkParser.resetEventCache(); |
|
192 |
chunkParser.updateEventParsers(); |
|
193 |
if (ordered) { |
|
194 |
awaitnewEvent = processOrdered(awaitnewEvent); |
|
195 |
} else { |
|
196 |
awaitnewEvent = processUnordered(awaitnewEvent); |
|
197 |
} |
|
198 |
runFlushActions(); |
|
199 |
} |
|
57386 | 200 |
|
57425 | 201 |
path = repositoryFiles.nextPath(startNanos); |
202 |
startNanos = repositoryFiles.getTimestamp(path) + 1; |
|
203 |
input.setFile(path); |
|
57427 | 204 |
chunkParser = chunkParser.newChunkParser(); |
57386 | 205 |
} |
206 |
} |
|
207 |
} |
|
208 |
||
57425 | 209 |
private boolean processOrdered(boolean awaitNewEvents) throws IOException { |
57386 | 210 |
if (sortedList == null) { |
211 |
sortedList = new RecordedEvent[DEFAULT_ARRAY_SIZE]; |
|
212 |
} |
|
57425 | 213 |
int index = 0; |
57386 | 214 |
while (true) { |
57425 | 215 |
RecordedEvent e = chunkParser.readStreamingEvent(awaitNewEvents); |
216 |
if (e == null) { |
|
217 |
// wait for new event with next call to |
|
218 |
// readStreamingEvent() |
|
219 |
awaitNewEvents = true; |
|
220 |
break; |
|
221 |
} |
|
222 |
awaitNewEvents = false; |
|
223 |
if (index == sortedList.length) { |
|
224 |
sortedList = Arrays.copyOf(sortedList, sortedList.length * 2); |
|
57386 | 225 |
} |
57425 | 226 |
sortedList[index++] = e; |
227 |
} |
|
57386 | 228 |
|
57425 | 229 |
// no events found |
230 |
if (index == 0 && chunkParser.isChunkFinished()) { |
|
231 |
return awaitNewEvents; |
|
57386 | 232 |
} |
57425 | 233 |
// at least 2 events, sort them |
234 |
if (index > 1) { |
|
235 |
Arrays.sort(sortedList, 0, index, END_TIME); |
|
236 |
} |
|
237 |
for (int i = 0; i < index; i++) { |
|
238 |
dispatch(sortedList[i]); |
|
239 |
} |
|
240 |
return awaitNewEvents; |
|
57386 | 241 |
} |
242 |
||
57425 | 243 |
private boolean processUnordered(boolean awaitNewEvents) throws IOException { |
57386 | 244 |
while (true) { |
57425 | 245 |
RecordedEvent e = chunkParser.readStreamingEvent(awaitNewEvents); |
246 |
if (e == null) { |
|
247 |
awaitNewEvents = true; |
|
248 |
break; |
|
249 |
} else { |
|
57386 | 250 |
dispatch(e); |
251 |
} |
|
252 |
} |
|
57425 | 253 |
return awaitNewEvents; |
57386 | 254 |
} |
255 |
||
256 |
public void setReuse(boolean reuse) { |
|
257 |
this.reuse = reuse; |
|
258 |
} |
|
259 |
||
260 |
public void setOrdered(boolean ordered) { |
|
261 |
this.ordered = ordered; |
|
262 |
} |
|
263 |
||
264 |
@Override |
|
265 |
public void close() { |
|
266 |
repositoryFiles.close(); |
|
267 |
} |
|
268 |
} |
|
269 |
||
270 |
static final class SharedParserConsumer extends EventConsumer { |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
271 |
private EventSetLocation location; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
272 |
private EventSet eventSet; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
273 |
private int eventSetIndex; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
274 |
private int eventArrayIndex; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
275 |
private RecordedEvent[] currentEventArray = new RecordedEvent[0]; |
57361 | 276 |
|
57386 | 277 |
public SharedParserConsumer(AccessControlContext acc) throws IOException { |
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
278 |
super(acc); |
57361 | 279 |
} |
280 |
||
57385
7d9d4f629f6e
Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents:
57380
diff
changeset
|
281 |
public void process() throws IOException { |
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
282 |
this.location = EventSetLocation.current(); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
283 |
this.eventSet = location.acquire(startNanos, null); // use timestamp |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
284 |
// from |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
285 |
if (eventSet == null) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
286 |
return; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
287 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
288 |
while (!isClosed()) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
289 |
processSegment(); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
290 |
runFlushActions(); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
291 |
do { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
292 |
if (isClosed()) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
293 |
return; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
294 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
295 |
currentEventArray = eventSet.readEvents(eventSetIndex); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
296 |
if (currentEventArray == EventSet.END_OF_SET) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
297 |
eventSet = eventSet.next(eventFilter); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
298 |
if (eventSet == null || isClosed()) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
299 |
return; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
300 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
301 |
eventSetIndex = 0; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
302 |
continue; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
303 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
304 |
if (currentEventArray == null) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
305 |
return; // no more events |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
306 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
307 |
eventSetIndex++; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
308 |
} while (currentEventArray.length == 0); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
309 |
eventArrayIndex = 0; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
310 |
} |
57361 | 311 |
} |
312 |
||
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
313 |
private void processSegment() { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
314 |
while (eventArrayIndex < currentEventArray.length) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
315 |
RecordedEvent e = currentEventArray[eventArrayIndex++]; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
316 |
if (e == null) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
317 |
return; |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
318 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
319 |
dispatch(e); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
320 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
321 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
322 |
|
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
323 |
public void close() { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
324 |
setClosed(true); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
325 |
// TODO: Data races here, must fix |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
326 |
synchronized (this) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
327 |
if (eventSet != null) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
328 |
eventSet.release(null); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
329 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
330 |
if (location != null) { |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
331 |
location.release(); |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
332 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
333 |
} |
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
334 |
runCloseActions(); |
57361 | 335 |
} |
57376 | 336 |
|
337 |
public void setReuse(boolean reuse) { |
|
338 |
// ignore hint |
|
339 |
} |
|
57361 | 340 |
} |
341 |
||
57386 | 342 |
private final EventConsumer eventConsumer; |
57361 | 343 |
|
57425 | 344 |
public EventDirectoryStream(AccessControlContext acc, Path p) throws IOException { |
345 |
eventConsumer = new ParserConsumer(acc, p); |
|
57361 | 346 |
} |
347 |
||
348 |
public void close() { |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
349 |
eventConsumer.close(); |
57361 | 350 |
} |
351 |
||
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
352 |
public void onFlush(Runnable action) { |
57361 | 353 |
Objects.requireNonNull(action); |
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
354 |
eventConsumer.onFlush(action); |
57361 | 355 |
} |
356 |
||
357 |
void start(long startNanos) { |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
358 |
eventConsumer.start(startNanos); |
57361 | 359 |
} |
360 |
||
361 |
@Override |
|
362 |
public void start() { |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
363 |
start(Instant.now().toEpochMilli() * 1000 * 1000L); |
57361 | 364 |
} |
365 |
||
366 |
@Override |
|
367 |
public void startAsync() { |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
368 |
startAsync(Instant.now().toEpochMilli() * 1000 * 1000L); |
57361 | 369 |
} |
370 |
||
371 |
void startAsync(long startNanos) { |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
372 |
eventConsumer.startAsync(startNanos); |
57361 | 373 |
} |
374 |
||
375 |
@Override |
|
376 |
public void onEvent(Consumer<RecordedEvent> action) { |
|
377 |
Objects.requireNonNull(action); |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
378 |
eventConsumer.onEvent(action); |
57361 | 379 |
} |
380 |
||
381 |
@Override |
|
382 |
public void onEvent(String eventName, Consumer<RecordedEvent> action) { |
|
383 |
Objects.requireNonNull(eventName); |
|
384 |
Objects.requireNonNull(action); |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
385 |
eventConsumer.onEvent(eventName, action); |
57361 | 386 |
} |
387 |
||
388 |
@Override |
|
389 |
public void onClose(Runnable action) { |
|
390 |
Objects.requireNonNull(action); |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
391 |
eventConsumer.addCloseAction(action); |
57361 | 392 |
} |
393 |
||
394 |
@Override |
|
395 |
public boolean remove(Object action) { |
|
396 |
Objects.requireNonNull(action); |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
397 |
return eventConsumer.remove(action); |
57361 | 398 |
} |
399 |
||
400 |
@Override |
|
401 |
public void awaitTermination(Duration timeout) { |
|
402 |
Objects.requireNonNull(timeout); |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
403 |
eventConsumer.awaitTermination(timeout); |
57361 | 404 |
} |
405 |
||
406 |
@Override |
|
407 |
public void awaitTermination() { |
|
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57361
diff
changeset
|
408 |
eventConsumer.awaitTermination(Duration.ofMillis(0)); |
57361 | 409 |
} |
57376 | 410 |
|
411 |
@Override |
|
412 |
public void setReuse(boolean reuse) { |
|
413 |
eventConsumer.setReuse(reuse); |
|
414 |
} |
|
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57376
diff
changeset
|
415 |
|
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57376
diff
changeset
|
416 |
@Override |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57376
diff
changeset
|
417 |
public void setOrdered(boolean ordered) { |
57386 | 418 |
eventConsumer.setOrdered(ordered); |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57376
diff
changeset
|
419 |
} |
57361 | 420 |
} |