- All Implemented Interfaces:
AutoCloseable
,EventStream
EventStream
that can serialize events over
the network using an MBeanServerConnection
.
The following example shows how to record garbage collection pauses and CPU usage on a remote host and print the events to standard out.
{ String host = "com.example"; int port = 4711; String url = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"; JMXServiceURL u = new JMXServiceURL(url); JMXConnector c = JMXConnectorFactory.connect(u); MBeanServerConnection conn = c.getMBeanServerConnection(); try (var rs = new RemoteRecordingStream(conn)) { rs.enable("jdk.GCPhasePause").withoutThreshold(); rs.enable("jdk.CPULoad").withPeriod(Duration.ofSeconds(1)); rs.onEvent("jdk.CPULoad", System.out::println); rs.onEvent("jdk.GCPhasePause", System.out::println); rs.start(); }
- Since:
- 16
-
Constructor Summary
ConstructorsConstructorDescriptionRemoteRecordingStream(MBeanServerConnection connection)
Creates an event stream that operates against aMBeanServerConnection
that has a registeredFlightRecorderMXBean
.RemoteRecordingStream(MBeanServerConnection connection, Path directory)
Creates an event stream that operates against aMBeanServerConnection
that has a registeredFlightRecorderMXBean
. -
Method Summary
Modifier and TypeMethodDescriptionDisables event with the specified name.Enables the event with the specified name.void
Determines how far back data is kept for the stream.void
setMaxSize(long maxSize)
Determines how much data is kept for the stream.void
setSettings(Map<String,String> settings)
Replaces all settings for this recording stream.Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface jdk.jfr.consumer.EventStream
awaitTermination, awaitTermination, close, onClose, onError, onEvent, onEvent, onFlush, onMetadata, remove, setEndTime, setOrdered, setReuse, setStartTime, start, startAsync
-
Constructor Details
-
RemoteRecordingStream
Creates an event stream that operates against aMBeanServerConnection
that has a registeredFlightRecorderMXBean
.To configure event settings, use
setSettings(Map)
.- Parameters:
connection
- theMBeanServerConnection
where theFlightRecorderMXBean
is registered, notnull
- Throws:
IOException
- if a stream can't be opened, an I/O error occurs when trying to access the repository or theFlightRecorderMXBean
SecurityException
- if a security manager exists and itscheckRead
method denies read access to the directory, or files in the directory.
-
RemoteRecordingStream
Creates an event stream that operates against aMBeanServerConnection
that has a registeredFlightRecorderMXBean
.To configure event settings, use
setSettings(Map)
.- Parameters:
connection
- theMBeanServerConnection
where theFlightRecorderMXBean
is registered, notnull
directory
- the directory to store event data that is downloaded, notnull
- Throws:
IOException
- if a stream can't be opened, an I/O error occurs when trying to access the repository or theFlightRecorderMXBean
SecurityException
- if a security manager exists and itscheckRead
method denies read access to the directory, or files in the directory.
-
-
Method Details
-
setSettings
Replaces all settings for this recording stream.The following example connects to a remote host and stream events using settings from the "default" configuration.
{ String host = "com.example"; int port = 4711; String url = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"; JMXServiceURL u = new JMXServiceURL(url); JMXConnector c = JMXConnectorFactory.connect(u); MBeanServerConnection conn = c.getMBeanServerConnection(); try (final var rs = new RemoteRecordingStream(conn)) { rs.onMetadata(e -> { for (Configuration c : e.getConfigurations()) { if (c.getName().equals("default")) { rs.setSettings(c.getSettings()); } } }); rs.onEvent(System.out::println); rs.start(); }
- Parameters:
settings
- the settings to set, notnull
- See Also:
Recording.setSettings(Map)
-
disable
Disables event with the specified name.If multiple events with same name (for example, the same class is loaded in different class loaders), then all events that match the name are disabled.
- Parameters:
name
- the settings for the event, notnull
- Returns:
- an event setting for further configuration, not
null
-
enable
Enables the event with the specified name.If multiple events have the same name (for example, the same class is loaded in different class loaders), then all events that match the name are enabled.
- Parameters:
name
- the settings for the event, notnull
- Returns:
- an event setting for further configuration, not
null
- See Also:
EventType
-
setMaxAge
Determines how far back data is kept for the stream.To control the amount of recording data stored on disk, the maximum length of time to retain the data can be specified. Data stored on disk that is older than the specified length of time is removed by the Java Virtual Machine (JVM).
If neither maximum limit or the maximum age is set, the size of the recording may grow indefinitely if events are not consumed.
- Parameters:
maxAge
- the length of time that data is kept, ornull
if infinite- Throws:
IllegalArgumentException
- ifmaxAge
is negativeIllegalStateException
- if the recording is in theCLOSED
state
-
setMaxSize
public void setMaxSize(long maxSize)Determines how much data is kept for the stream.To control the amount of recording data that is stored on disk, the maximum amount of data to retain can be specified. When the maximum limit is exceeded, the Java Virtual Machine (JVM) removes the oldest chunk to make room for a more recent chunk.
If neither maximum limit or the maximum age is set, the size of the recording may grow indefinitely if events are not consumed.
The size is measured in bytes.
- Parameters:
maxSize
- the amount of data to retain,0
if infinite- Throws:
IllegalArgumentException
- ifmaxSize
is negativeIllegalStateException
- if the recording is inCLOSED
state
-