RecordedClass
, RecordedClassLoader
, RecordedEvent
, RecordedFrame
, RecordedMethod
, RecordedStackTrace
, RecordedThread
, RecordedThreadGroup
public sealed class RecordedObject extends Object permits RecordedEvent, RecordedClassLoader, RecordedClass, RecordedMethod, RecordedStackTrace, RecordedFrame, RecordedThread, RecordedThreadGroup
This class provides methods to select and query nested objects by passing a dot "."
delimited String
object (for instance, "aaa.bbb"
). A method evaluates a nested object from left to right, and if a part is null
, it throws NullPointerException
.
Modifier and Type | Method | Description |
---|---|---|
final boolean |
getBoolean |
Returns the value of a field of type boolean . |
final byte |
getByte |
Returns the value of a field of type byte . |
final char |
getChar |
Returns the value of a field of type char . |
final RecordedClass |
getClass |
Returns the value of a field of type Class . |
final double |
getDouble |
Returns the value of a field of type double or of another primitive type that is convertible to type double by a widening conversion. |
final Duration |
getDuration |
Returns the value of a timespan field. |
List |
getFields() |
Returns an immutable list of the fields for this object. |
final float |
getFloat |
Returns the value of a field of type float or of another primitive type convertible to type float by a widening conversion. |
final Instant |
getInstant |
Returns the value of a timestamp field. |
final int |
getInt |
Returns the value of a field of type int or of another primitive type that is convertible to type int by a widening conversion. |
final long |
getLong |
Returns the value of a field of type long or of another primitive type that is convertible to type long by a widening conversion. |
final short |
getShort |
Returns the value of a field of type short or of another primitive type convertible to type short by a widening conversion. |
final String |
getString |
Returns the value of a field of type String . |
final RecordedThread |
getThread |
Returns the value of a field of type Thread . |
final <T> T |
getValue |
Returns the value of the field with the given name. |
boolean |
hasField |
Returns true if a field with the given name exists, false otherwise. |
final String |
toString() |
Returns a textual representation of this object. |
public boolean hasField(String name)
true
if a field with the given name exists, false
otherwise. It's possible to index into a nested field by using "."
(for instance "thread.group.parent.name
").
name
- name of the field to get, not null
true
if the field exists, false
otherwisepublic final <T> T getValue(String name)
The return type may be a primitive type or a subclass of RecordedObject
.
It's possible to index into a nested object by using "."
(for instance "thread.group.parent.name
").
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
Example
if (event.hasField("intValue")) {
int intValue = event.getValue("intValue");
System.out.println("Int value: " + intValue);
}
if (event.hasField("objectClass")) {
RecordedClass clazz = event.getValue("objectClass");
System.out.println("Class name: " + clazz.getName());
}
if (event.hasField("sampledThread")) {
RecordedThread sampledThread = event.getValue("sampledThread");
System.out.println("Sampled thread: " + sampledThread.getJavaName());
}
T
- the return typename
- of the field to get, not null
null
IllegalArgumentException
- if no field called name
existspublic List<ValueDescriptor> getFields()
null
public final boolean getBoolean(String name)
boolean
. It's possible to index into a nested object using "."
(for example, "aaa.bbb"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- name of the field to get, not null
true
or false
IllegalArgumentException
- if the field doesn't exist, or the field is not of type boolean
public final byte getByte(String name)
byte
. It's possible to index into a nested object using "."
(for example, "foo.bar"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
IllegalArgumentException
- if the field doesn't exist, or the field is not of type byte
public final char getChar(String name)
char
. It's possible to index into a nested object using "."
(for example, "aaa.bbb"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
char
IllegalArgumentException
- if the field doesn't exist, or the field is not of type char
public final short getShort(String name)
short
or of another primitive type convertible to type short
by a widening conversion. This method can be used on the following types: short
and byte
.
If the field has the @Unsigned
annotation and is of a narrower type than short
, then the value is returned as an unsigned.
It's possible to index into a nested object using "."
(for example, "aaa.bbb"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
short
IllegalArgumentException
- if the field doesn't exist, or the field value can't be converted to the type short
by a widening conversionpublic final int getInt(String name)
int
or of another primitive type that is convertible to type int
by a widening conversion. This method can be used on fields of the following types: int
, short
, char
, and byte
.
If the field has the @Unsigned
annotation and is of a narrower type than int
, then the value will be returned as an unsigned.
It's possible to index into a nested object using "."
(for example, "aaa.bbb"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
int
IllegalArgumentException
- if the field doesn't exist, or the field value can't be converted to the type int
by a widening conversionpublic final float getFloat(String name)
float
or of another primitive type convertible to type float
by a widening conversion. This method can be used on fields of the following types: float
, long
, int
, short
, char
, and byte
.
It's possible to index into a nested object using "."
(for example, "aaa.bbb"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
float
IllegalArgumentException
- if the field doesn't exist, or the field value can't be converted to the type float
by a widening conversionpublic final long getLong(String name)
long
or of another primitive type that is convertible to type long
by a widening conversion. This method can be used on fields of the following types: long
, int
, short
, char
, and byte
.
If the field has the @Unsigned
annotation and is of a narrower type than long
, then the value will be returned as an unsigned.
It's possible to index into a nested object using "."
(for example, "aaa.bbb"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
long
IllegalArgumentException
- if the field doesn't exist, or the field value can't be converted to the type long
via a widening conversionpublic final double getDouble(String name)
double
or of another primitive type that is convertible to type double
by a widening conversion. This method can be used on fields of the following types: double
, float
, long
, int
, short
, char
, and byte
.
It's possible to index into a nested object using "."
(for example, "aaa.bbb"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
double
IllegalArgumentException
- if the field doesn't exist, or the field value can't be converted to the type double
by a widening conversionpublic final String getString(String name)
String
. It's possible to index into a nested object using "."
(for example, "foo.bar"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
String
, can be null
IllegalArgumentException
- if the field doesn't exist, or the field isn't of type String
public final Duration getDuration(String name)
This method can be used on fields annotated with @Timespan
, and of the following types: long
, int
, short
, char
, and byte
.
If the committed event value was Long.MAX_VALUE
, regardless of the unit set by @Timespan
, this method returns ChronoUnit.FOREVER
.
It's possible to index into a nested object using "."
(for example, "aaa.bbb"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
Duration
, not null
IllegalArgumentException
- if the field doesn't exist, or the field value can't be converted to a Duration
objectpublic final Instant getInstant(String name)
This method can be used on fields annotated with @Timestamp
, and of the following types: long
, int
, short
, char
and byte
.
It's possible to index into a nested object using "."
(for example, "aaa.bbb"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
Instant
, not null
IllegalArgumentException
- if the field doesn't exist, or the field value can't be converted to an Instant
objectpublic final RecordedClass getClass(String name)
Class
. It's possible to index into a nested object using "."
(for example, "aaa.bbb"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
RecordedClass
, can be null
IllegalArgumentException
- if the field doesn't exist, or the field isn't of type Class
public final RecordedThread getThread(String name)
Thread
. It's possible to index into a nested object using "."
(for example, "foo.bar"
).
A field might change or be removed in a future JDK release. A best practice for callers of this method is to validate the field before attempting access.
name
- of the field to get, not null
RecordedThread
object, can be null
IllegalArgumentException
- if the field doesn't exist, or the field isn't of type Thread
public final String toString()
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.jfr/jdk/jfr/consumer/RecordedObject.html