mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-17 00:50:48 +00:00
8345339: JFR: Missing javadoc for RecordingStream::onMetadata
Reviewed-by: nbenalla, liach
This commit is contained in:
parent
456c71d1ff
commit
97b8a09bda
@ -455,6 +455,27 @@ public final class RecordingStream implements AutoCloseable, EventStream {
|
||||
directoryStream.awaitTermination();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an action to perform when new metadata arrives in the stream.
|
||||
*
|
||||
* The event type of an event always arrives sometime before the actual event.
|
||||
* The action must be registered before the stream is started.
|
||||
* <p>
|
||||
* The following example shows how to listen to new event types, register
|
||||
* an action if the event type name matches a regular expression and increase a
|
||||
* counter if a matching event is found. A benefit of using an action per
|
||||
* event type, instead of the generic {@link #onEvent(Consumer)} method,
|
||||
* is that a stream implementation can avoid reading events that are of no
|
||||
* interest.
|
||||
*
|
||||
* {@snippet class = "Snippets" region = "RecordingStreamMetadata"}
|
||||
*
|
||||
* @param action to perform, not {@code null}
|
||||
*
|
||||
* @throws IllegalStateException if an action is added after the stream has
|
||||
* started
|
||||
* @since 16
|
||||
*/
|
||||
@Override
|
||||
public void onMetadata(Consumer<MetadataEvent> action) {
|
||||
directoryStream.onMetadata(action);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -109,6 +109,27 @@ public class Snippets {
|
||||
// @end
|
||||
}
|
||||
|
||||
class RecordingStreamMetadata {
|
||||
// @start region="RecordingStreamMetadata"
|
||||
static long count = 0;
|
||||
public static void main(String... args) throws Exception {
|
||||
String regExp = args[0];
|
||||
var pr = Pattern.compile(regExp).asMatchPredicate();
|
||||
Configuration c = Configuration.getConfiguration("default");
|
||||
try (var s = new RecordingStream(c)) {
|
||||
s.setOrdered(false);
|
||||
s.onMetadata(metadata -> metadata.getAddedEventTypes()
|
||||
.stream().map(EventType::getName).filter(pr)
|
||||
.forEach(eventName -> s.onEvent(eventName, event -> count++)));
|
||||
s.startAsync();
|
||||
System.out.println("Running recording for 5 s. Please wait.");
|
||||
s.awaitTermination(Duration.ofSeconds(5));
|
||||
System.out.println(count + " events matches " + regExp);
|
||||
}
|
||||
}
|
||||
// @end
|
||||
}
|
||||
|
||||
void RecordingFileOverview() throws Exception {
|
||||
// @start region="RecordingFileOverview"
|
||||
try (RecordingFile recordingFile = new RecordingFile(Paths.get("recording.jfr"))) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user