Skip to content

Commit f555024

Browse files
author
David Grieve
committed
Recording close should not throw exception
1 parent 9117be4 commit f555024

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

jfr-connection/src/main/java/io/opentelemetry/contrib/jfr/connection/FlightRecorderDiagnosticCommandConnection.java

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,6 @@ private static Object[] formOptions(
156156
return mkParamsArray(params);
157157
}
158158

159-
/**
160-
* Stop a recording. This method is called from the {@link Recording#stop()} method.
161-
*
162-
* @param id The id of the recording.
163-
* @throws JfrConnectionException Wraps an {@code javax.management.InstanceNotFoundException}, a
164-
* {@code javax.management.MBeanException} or a {@code javax.management.ReflectionException}
165-
* and indicates an issue with the FlightRecorderMXBean in the JVM.
166-
*/
167159
@Override
168160
public void stopRecording(long id) throws JfrConnectionException {
169161
try {
@@ -174,14 +166,6 @@ public void stopRecording(long id) throws JfrConnectionException {
174166
}
175167
}
176168

177-
/**
178-
* Writes recording data to the specified file. The recording must be started, but not necessarily
179-
* stopped. The {@code outputFile} argument is relevant to the machine where the JVM is running.
180-
*
181-
* @param id The id of the recording.
182-
* @param outputFile the system-dependent file name where data is written, not {@code null}
183-
* @throws JfrConnectionException Wraps a {@code javax.management.JMException}.
184-
*/
185169
@Override
186170
public void dumpRecording(long id, String outputFile) throws IOException, JfrConnectionException {
187171
try {
@@ -192,28 +176,25 @@ public void dumpRecording(long id, String outputFile) throws IOException, JfrCon
192176
}
193177
}
194178

195-
/**
196-
* Not supported on Java 8
197-
*
198-
* @param id The id of the recording being cloned.
199-
* @param stop Whether to stop the cloned recording.
200-
* @return id of the recording
201-
*/
179+
/** Not available through the DiagnosticCommand MBean. {@inheritDoc} */
202180
@Override
203181
public long cloneRecording(long id, boolean stop) {
204-
throw new UnsupportedOperationException("Clone not supported on Java 8");
182+
throw new UnsupportedOperationException(
183+
"cloneRecording not available through the DiagnosticCommand connection");
205184
}
206185

207-
/** Not supported on Java 8 */
186+
/** Not available through the DiagnosticCommand MBean. {@inheritDoc} */
208187
@Override
209188
public InputStream getStream(long id, Instant startTime, Instant endTime, long blockSize) {
210-
throw new UnsupportedOperationException("getStream not supported on Java 8");
189+
throw new UnsupportedOperationException(
190+
"getStream not available through the DiagnosticCommand connection");
211191
}
212192

213-
/** Not supported on Java 8 */
193+
/** Not available through the DiagnosticCommand MBean. {@inheritDoc} */
214194
@Override
215195
public void closeRecording(long id) {
216-
throw new UnsupportedOperationException("closeRecording not supported on Java 8");
196+
throw new UnsupportedOperationException(
197+
"closeRecording not available through the DiagnosticCommand connection");
217198
}
218199

219200
// Do this check separate from assertCommercialFeatures because reliance

jfr-connection/src/main/java/io/opentelemetry/contrib/jfr/connection/Recording.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,14 @@ public void close() throws IOException, JfrConnectionException {
270270
connection.stopRecording(id);
271271
} catch (IOException | JfrConnectionException ignored) {
272272
// Stopping the recording is best-effort
273-
} finally {
273+
}
274+
}
275+
if (oldState == State.STOPPED || oldState == State.RECORDING) {
276+
try {
274277
connection.closeRecording(id);
278+
} catch (IOException | JfrConnectionException | UnsupportedOperationException ignored) {
279+
// Closing the recording is best-effort
280+
// FlightRecorderDiagnosticCommandConnection close throws UnsupportedOperationException
275281
}
276282
}
277283
}

0 commit comments

Comments
 (0)