Skip to content

8365066: RecordingStream and RemoteRecordingStream do not terminate when the associated Recording is stopped or closed externally #26710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import jdk.jfr.internal.consumer.EventDirectoryStream;
import jdk.jfr.internal.consumer.EventFileStream;
import jdk.jfr.internal.consumer.FileEventSource;

/**
* Represents a stream of events.
Expand Down Expand Up @@ -112,7 +113,7 @@ public interface EventStream extends AutoCloseable {
public static EventStream openRepository() throws IOException {
return new EventDirectoryStream(
null,
null,
new FileEventSource(),
Collections.emptyList(),
false
);
Expand All @@ -137,7 +138,7 @@ public static EventStream openRepository(Path directory) throws IOException {
Objects.requireNonNull(directory, "directory");
return new EventDirectoryStream(
directory,
null,
new FileEventSource(),
Collections.emptyList(),
true
);
Expand Down
10 changes: 7 additions & 3 deletions src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordingStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import jdk.jfr.RecordingState;
import jdk.jfr.internal.PlatformRecording;
import jdk.jfr.internal.PrivateAccess;
import jdk.jfr.internal.management.EventSource;
import jdk.jfr.internal.consumer.LocalRecordingEventSource;
import jdk.jfr.internal.util.Utils;
import jdk.jfr.internal.consumer.EventDirectoryStream;
import jdk.jfr.internal.management.StreamBarrier;
Expand Down Expand Up @@ -82,6 +84,7 @@ public void accept(Long endNanos) {
private final EventDirectoryStream directoryStream;
private long maxSize;
private Duration maxAge;
private final EventSource eventSource;

/**
* Creates an event stream for the current JVM (Java Virtual Machine).
Expand All @@ -100,9 +103,10 @@ private RecordingStream(Map<String, String> settings) {
this.recording.setName("Recording Stream: " + creationTime);
try {
PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording);
this.eventSource = new LocalRecordingEventSource(pr);
this.directoryStream = new EventDirectoryStream(
null,
pr,
eventSource,
configurations(),
false
);
Expand Down Expand Up @@ -392,9 +396,9 @@ public boolean stop() {
boolean stopped = false;
try {
try (StreamBarrier sb = directoryStream.activateStreamBarrier()) {
stopped = recording.stop();
stopped = eventSource.stop();
directoryStream.setCloseOnComplete(false);
sb.setStreamEnd(recording.getStopTime().toEpochMilli());
sb.setStreamEnd(eventSource.getStopTime());
}
directoryStream.awaitTermination();
} catch (InterruptedException | IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import jdk.jfr.internal.LogLevel;
import jdk.jfr.internal.LogTag;
import jdk.jfr.internal.Logger;
import jdk.jfr.internal.management.EventSource;

/*
* Purpose of this class is to simplify the implementation of
Expand All @@ -60,10 +61,12 @@ public abstract class AbstractEventStream implements EventStream {
private volatile boolean waitForChunks = true;
private Dispatcher dispatcher;
private boolean daemon = false;
protected final EventSource eventSource;


AbstractEventStream(List<Configuration> configurations) throws IOException {
AbstractEventStream(List<Configuration> configurations, EventSource eventSource) throws IOException {
this.configurations = configurations;
this.eventSource = eventSource;
}

@Override
Expand Down Expand Up @@ -207,8 +210,6 @@ public final void awaitTermination(Duration timeout) throws InterruptedException

protected abstract void process() throws IOException;

protected abstract boolean isRecordingStream();

protected final void closeParser() {
parserState.close();
}
Expand Down Expand Up @@ -250,7 +251,7 @@ private void startInternal(long startNanos) {
if (streamConfiguration.started) {
throw new IllegalStateException("Event stream can only be started once");
}
if (isRecordingStream() && streamConfiguration.startTime == null) {
if (eventSource.requiresStartTime() && streamConfiguration.startTime == null) {
streamConfiguration.setStartNanos(startNanos);
}
streamConfiguration.setStarted(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import jdk.jfr.internal.LogLevel;
import jdk.jfr.internal.LogTag;
import jdk.jfr.internal.Logger;
import jdk.jfr.internal.PlatformRecording;
import jdk.jfr.internal.management.EventSource;
import jdk.jfr.internal.util.Utils;
import jdk.jfr.internal.management.StreamBarrier;

Expand All @@ -55,7 +55,6 @@ public final class EventDirectoryStream extends AbstractEventStream {
private static final Comparator<? super RecordedEvent> EVENT_COMPARATOR = JdkJfrConsumer.instance().eventComparator();

private final RepositoryFiles repositoryFiles;
private final PlatformRecording recording;
private final StreamBarrier barrier = new StreamBarrier();
private final AtomicLong streamId = new AtomicLong();
private ChunkParser currentParser;
Expand All @@ -66,11 +65,10 @@ public final class EventDirectoryStream extends AbstractEventStream {

public EventDirectoryStream(
Path p,
PlatformRecording recording,
EventSource eventSource,
List<Configuration> configurations,
boolean allowSubDirectories) throws IOException {
super(configurations);
this.recording = recording;
super(configurations, eventSource);
this.repositoryFiles = new RepositoryFiles(p, allowSubDirectories);
this.streamId.incrementAndGet();
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Stream " + streamId + " started.");
Expand Down Expand Up @@ -131,7 +129,7 @@ protected void processRecursionSafe() throws IOException {
Dispatcher lastDisp = null;
Dispatcher disp = dispatcher();
Path path;
boolean validStartTime = isRecordingStream() || disp.startTime != null;
boolean validStartTime = eventSource.requiresStartTime() || disp.startTime != null;
if (validStartTime) {
path = repositoryFiles.firstPath(disp.startNanos, true);
} else {
Expand Down Expand Up @@ -169,6 +167,19 @@ protected void processRecursionSafe() throws IOException {
"ns (epoch), parser at " + lastFlush + "ns (epoch).");
return;
}

if(!barrier.used()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!barrier.used()) {
if (!barrier.used()) {

RecordingState state = eventSource.getState();
if (state == RecordingState.CLOSED) {
return;
} else if (state == RecordingState.STOPPED) {
long stopTime = eventSource.getStopTime();
if (lastFlush > stopTime) {
logStreamEnd("stopped at " + stopTime + "ns (epoch), parser at " + lastFlush + "ns (epoch).");
return;
}
}
}
}
long endNanos = currentParser.getStartNanos() + currentParser.getChunkDuration();
long endMillis = Instant.ofEpochSecond(0, endNanos).toEpochMilli();
Expand All @@ -181,9 +192,13 @@ protected void processRecursionSafe() throws IOException {
return;
}

if (isRecordingStream()) {
if (recording.getState() == RecordingState.STOPPED && !barrier.used()) {
logStreamEnd("recording stopped externally.");
if(!barrier.used()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!barrier.used()) {
if (!barrier.used()) {

RecordingState state = eventSource.getState();
if (state == RecordingState.CLOSED){
logStreamEnd("Event source is closed externally");
return;
}else if(state == RecordingState.STOPPED) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}else if(state == RecordingState.STOPPED) {
} else if (state == RecordingState.STOPPED) {

logStreamEnd("Event source is stopped externally");
return;
}
}
Expand Down Expand Up @@ -226,10 +241,6 @@ private void logStreamEnd(String text) {
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, msg);
}

protected boolean isRecordingStream() {
return recording != null;
}

private void processOrdered(Dispatcher c) throws IOException {
if (sortedCache == null) {
sortedCache = new RecordedEvent[100_000];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class EventFileStream extends AbstractEventStream {
private RecordedEvent[] cacheSorted;

public EventFileStream(Path file) throws IOException {
super(Collections.emptyList());
super(Collections.emptyList(), new FileEventSource());
this.input = new RecordingInput(file.toFile());
this.input.setStreamed();
}
Expand All @@ -71,11 +71,6 @@ public void close() {
}
}

@Override
protected boolean isRecordingStream() {
return false;
}

@Override
protected void process() throws IOException {
Dispatcher disp = dispatcher();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*

Check failure on line 1 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 2: carriage return (^M)
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.

Check failure on line 2 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 73: carriage return (^M)
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

Check failure on line 3 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 64: carriage return (^M)
*

Check failure on line 4 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 2: carriage return (^M)
* This code is free software; you can redistribute it and/or modify it

Check failure on line 5 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 71: carriage return (^M)
* under the terms of the GNU General Public License version 2 only, as

Check failure on line 6 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 71: carriage return (^M)
* published by the Free Software Foundation. Oracle designates this

Check failure on line 7 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 69: carriage return (^M)
* particular file as subject to the "Classpath" exception as provided

Check failure on line 8 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 70: carriage return (^M)
* by Oracle in the LICENSE file that accompanied this code.

Check failure on line 9 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 60: carriage return (^M)
*

Check failure on line 10 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 2: carriage return (^M)
* This code is distributed in the hope that it will be useful, but WITHOUT

Check failure on line 11 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 75: carriage return (^M)
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

Check failure on line 12 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 72: carriage return (^M)
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

Check failure on line 13 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 72: carriage return (^M)
* version 2 for more details (a copy is included in the LICENSE file that

Check failure on line 14 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 74: carriage return (^M)
* accompanied this code).

Check failure on line 15 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 26: carriage return (^M)
*

Check failure on line 16 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 2: carriage return (^M)
* You should have received a copy of the GNU General Public License version

Check failure on line 17 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 76: carriage return (^M)
* 2 along with this work; if not, write to the Free Software Foundation,

Check failure on line 18 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 73: carriage return (^M)
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

Check failure on line 19 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 64: carriage return (^M)
*

Check failure on line 20 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 2: carriage return (^M)
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA

Check failure on line 21 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 74: carriage return (^M)
* or visit www.oracle.com if you need additional information or have any

Check failure on line 22 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 73: carriage return (^M)
* questions.

Check failure on line 23 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 13: carriage return (^M)
*/

Check failure on line 24 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 3: carriage return (^M)

Check failure on line 25 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 0: carriage return (^M)
package jdk.jfr.internal.consumer;

Check failure on line 26 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 34: carriage return (^M)

Check failure on line 27 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 0: carriage return (^M)
import jdk.jfr.internal.management.EventSource;

Check failure on line 28 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 47: carriage return (^M)

Check failure on line 29 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 0: carriage return (^M)
public class FileEventSource implements EventSource {

Check failure on line 30 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 53: carriage return (^M)
}

Check failure on line 31 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 1: carriage return (^M)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*

Check failure on line 1 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 2: carriage return (^M)
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.

Check failure on line 2 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 73: carriage return (^M)
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

Check failure on line 3 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 64: carriage return (^M)
*

Check failure on line 4 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 2: carriage return (^M)
* This code is free software; you can redistribute it and/or modify it

Check failure on line 5 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 71: carriage return (^M)
* under the terms of the GNU General Public License version 2 only, as

Check failure on line 6 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 71: carriage return (^M)
* published by the Free Software Foundation. Oracle designates this

Check failure on line 7 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 69: carriage return (^M)
* particular file as subject to the "Classpath" exception as provided

Check failure on line 8 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 70: carriage return (^M)
* by Oracle in the LICENSE file that accompanied this code.

Check failure on line 9 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 60: carriage return (^M)
*

Check failure on line 10 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 2: carriage return (^M)
* This code is distributed in the hope that it will be useful, but WITHOUT

Check failure on line 11 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 75: carriage return (^M)
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

Check failure on line 12 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 72: carriage return (^M)
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

Check failure on line 13 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 72: carriage return (^M)
* version 2 for more details (a copy is included in the LICENSE file that

Check failure on line 14 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 74: carriage return (^M)
* accompanied this code).

Check failure on line 15 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 26: carriage return (^M)
*

Check failure on line 16 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 2: carriage return (^M)
* You should have received a copy of the GNU General Public License version

Check failure on line 17 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 76: carriage return (^M)
* 2 along with this work; if not, write to the Free Software Foundation,

Check failure on line 18 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 73: carriage return (^M)
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

Check failure on line 19 in src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/LocalRecordingEventSource.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-26710

Whitespace error

Column 64: carriage return (^M)
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package jdk.jfr.internal.consumer;

import jdk.jfr.RecordingState;

import jdk.jfr.internal.PlatformRecording;
import jdk.jfr.internal.management.EventSource;

public class LocalRecordingEventSource implements EventSource {

private final PlatformRecording recording;

public LocalRecordingEventSource(PlatformRecording recording) {
this.recording = recording;
}

@Override
public boolean requiresStartTime() {
return true;
}

@Override
public long getStopTime() {
return recording.getStopTime().toEpochMilli();
}

@Override
public boolean stop() {
return recording.stop("stopped by RecordingStream");
}

@Override
public RecordingState getState() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public RecordingState getState() {
public RecordingState getState() {

return recording.getState();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2025, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package jdk.jfr.internal.management;

import jdk.jfr.RecordingState;

public interface EventSource {

default long getStopTime() {
return Long.MAX_VALUE;
}

default boolean stop() {
return true;
}

default boolean requiresStartTime(){
return false;
}

default RecordingState getState() {
return RecordingState.RUNNING;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ public static Configuration newConfiguration(String name, String label, String d
// with configuration objects
public static EventStream newEventDirectoryStream(
Path directory,
List<Configuration> confs) throws IOException {
List<Configuration> confs, EventSource eventSource) throws IOException {
return new EventDirectoryStream(
directory,
null,
eventSource,
confs,
false
);
Expand Down
Loading