Skip to content
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

jfr-connection: Recording close should not throw exception #1412

Merged
merged 1 commit into from
Aug 16, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,6 @@ private static Object[] formOptions(
return mkParamsArray(params);
}

/**
* Stop a recording. This method is called from the {@link Recording#stop()} method.
*
* @param id The id of the recording.
* @throws JfrConnectionException Wraps an {@code javax.management.InstanceNotFoundException}, a
* {@code javax.management.MBeanException} or a {@code javax.management.ReflectionException}
* and indicates an issue with the FlightRecorderMXBean in the JVM.
*/
@Override
public void stopRecording(long id) throws JfrConnectionException {
try {
Expand All @@ -174,14 +166,6 @@ public void stopRecording(long id) throws JfrConnectionException {
}
}

/**
* Writes recording data to the specified file. The recording must be started, but not necessarily
* stopped. The {@code outputFile} argument is relevant to the machine where the JVM is running.
*
* @param id The id of the recording.
* @param outputFile the system-dependent file name where data is written, not {@code null}
* @throws JfrConnectionException Wraps a {@code javax.management.JMException}.
*/
@Override
public void dumpRecording(long id, String outputFile) throws IOException, JfrConnectionException {
try {
Expand All @@ -192,28 +176,25 @@ public void dumpRecording(long id, String outputFile) throws IOException, JfrCon
}
}

/**
* Not supported on Java 8
*
* @param id The id of the recording being cloned.
* @param stop Whether to stop the cloned recording.
* @return id of the recording
*/
/** Not available through the DiagnosticCommand MBean. {@inheritDoc} */
@Override
public long cloneRecording(long id, boolean stop) {
throw new UnsupportedOperationException("Clone not supported on Java 8");
throw new UnsupportedOperationException(
"cloneRecording not available through the DiagnosticCommand connection");
}

/** Not supported on Java 8 */
/** Not available through the DiagnosticCommand MBean. {@inheritDoc} */
@Override
public InputStream getStream(long id, Instant startTime, Instant endTime, long blockSize) {
throw new UnsupportedOperationException("getStream not supported on Java 8");
throw new UnsupportedOperationException(
"getStream not available through the DiagnosticCommand connection");
}

/** Not supported on Java 8 */
/** Not available through the DiagnosticCommand MBean. {@inheritDoc} */
@Override
public void closeRecording(long id) {
throw new UnsupportedOperationException("closeRecording not supported on Java 8");
throw new UnsupportedOperationException(
"closeRecording not available through the DiagnosticCommand connection");
}

// Do this check separate from assertCommercialFeatures because reliance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,14 @@ public void close() throws IOException, JfrConnectionException {
connection.stopRecording(id);
} catch (IOException | JfrConnectionException ignored) {
// Stopping the recording is best-effort
} finally {
}
}
if (oldState == State.STOPPED || oldState == State.RECORDING) {
try {
connection.closeRecording(id);
} catch (IOException | JfrConnectionException | UnsupportedOperationException ignored) {
// Closing the recording is best-effort
// FlightRecorderDiagnosticCommandConnection close throws UnsupportedOperationException
dsgrieve marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
Loading