This package contains the service to control the flight recorder, and all classes related to that service.
The following example will print the names of all ongoing recordings:
IConnectionManager manager = RJMXPlugin.getDefault().getConnectionManager();
ConnectionDescriptorBuilder builder = new ConnectionDescriptorBuilder();
IConnectionDescriptor descriptor = builder.hostName("localhost").port(0).build();
IConnectionHandle handle = manager.connect(descriptor);
IFlightRecorderService flr = handle.getServiceOrDummy(IFlightRecorderService.class);
for (IRecordingDescriptor desc : flr.getAvailableRecordings()) {
System.out.println(desc.getName());
}
manager.disconnect(handle);
The following will start a time bound recording, and then transfer the recording to a local file when completed:
IConnectionManager manager = RJMXPlugin.getDefault().getConnectionManager();
ConnectionDescriptorBuilder builder = new ConnectionDescriptorBuilder();
IConnectionDescriptor descriptor = builder.hostName("localhost").port(0).build();
IConnectionHandle handle = manager.connect(descriptor);
IFlightRecorderService flr = handle.getServiceOrDummy(IFlightRecorderService.class);
long duration = 5000;
Map recordingOptions = new RecordingOptionsBuilder().name("MyRecording").duration(duration).build();
IRecordingDescriptor recording = flr.start(recordingOptions, null);
Thread.sleep(duration);
while (recording.getState() != IRecordingDescriptor.RecordingState.STOPPED) {
Thread.sleep(1000);
recording = flr.getUpdatedRecordingDescripton(recording);
}
InputStream is = flr.openStream(recording, true);
writeStreamToFile(is);
manager.disconnect(handle);