- java.lang.Object
-
- jdk.jfr.consumer.RecordedObject
-
- Direct Known Subclasses:
RecordedClass,RecordedClassLoader,RecordedEvent,RecordedFrame,RecordedMethod,RecordedStackTrace,RecordedThread,RecordedThreadGroup
public class RecordedObject extends Object
A complex data type that consists of one or more fields.This class provides methods to select and query nested objects by passing a dot
"."delimitedString, for instance"foo.bar". A method will evaluate a nested object from left-to-right, and if a part isnull, it will throwNullPointerException.- Since:
- 9
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleangetBoolean(String name)Returns the value of a field of typeboolean.bytegetByte(String name)Returns the value of a field of typebyte.chargetChar(String name)Returns the value of a field of typechar.RecordedClassgetClass(String name)Returns the value of a field of typeClass.doublegetDouble(String name)Returns the value of a field of typedoubleor of another primitive type convertible to typedoublevia a widening conversion.DurationgetDuration(String name)Returns the value of a timespan field.List<ValueDescriptor>getFields()Returns an immutable list of the fields for this object.floatgetFloat(String name)Returns the value of a field of typefloator of another primitive type convertible to typefloatvia a widening conversion.InstantgetInstant(String name)Returns the value of a timestamp field.intgetInt(String name)Returns the value of a field of typeintor of another primitive type convertible to typeintvia a widening conversion.longgetLong(String name)Returns the value of a field of typelongor of another primitive type convertible to typelongvia a widening conversion.shortgetShort(String name)Returns the value of a field of typeshortor of another primitive type convertible to typeshortvia a widening conversion.StringgetString(String name)Returns the value of a field of typeString.RecordedThreadgetThread(String name)Returns the value of a field of typeThread.<T> TgetValue(String name)Returns the value of the field with the given name.booleanhasField(String name)Returnstrueif a field with given name exists,falseotherwise.StringtoString()Returns a textual representation of this object.
-
-
-
Method Detail
-
hasField
public boolean hasField(String name)
Returnstrueif a field with given name exists,falseotherwise.- Parameters:
name- name of the field to get, notnull- Returns:
trueif the field exists,falseotherwise.- See Also:
getFields()
-
getValue
public final <T> T getValue(String name)
Returns the value of the field with the given name.The return type may be a primitive type or a subclass of
RecordedObject.It's possible to index into a nested object using
".", for instance"thread.group.parent.name"Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice 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.getName()); }- Type Parameters:
T- the return type- Parameters:
name- name of the field to get, notnull- Returns:
- value the value, can be
null - Throws:
IllegalArgumentException- if there is no field calledname- See Also:
hasField(String)
-
getFields
public List<ValueDescriptor> getFields()
Returns an immutable list of the fields for this object.- Returns:
- the fields, not
null
-
getBoolean
public final boolean getBoolean(String name)
Returns the value of a field of typeboolean.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- the value of the field,
trueorfalse - Throws:
IllegalArgumentException- if the field doesn't exist, or the field is not of typeboolean- See Also:
hasField(String),getValue(String)
-
getByte
public final byte getByte(String name)
Returns the value of a field of typebyte.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- the value of the field
- Throws:
IllegalArgumentException- if the field doesn't exist, or the field is not of typebyte- See Also:
hasField(String),getValue(String)
-
getChar
public final char getChar(String name)
Returns the value of a field of typechar.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- the value of the field as a
char - Throws:
IllegalArgumentException- if the field doesn't exist, or the field is not of typechar- See Also:
hasField(String),getValue(String)
-
getShort
public final short getShort(String name)
Returns the value of a field of typeshortor of another primitive type convertible to typeshortvia a widening conversion.This method can be used on fields of type
shortandbyte.If the field has the annotation
@Unsignedand is of a narrower type thanshort, then the value will be returned as an unsigned.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- the value of the field converted to type
short - Throws:
IllegalArgumentException- if the field doesn't exist, or the field value cannot be converted to the typeshortvia a widening conversion- See Also:
hasField(String)
-
getInt
public final int getInt(String name)
Returns the value of a field of typeintor of another primitive type convertible to typeintvia a widening conversion.This method can be used on fields of type
int,short,charandbyte.If the field has the annotation
@Unsignedand is of a narrower type thanint, then the value will be returned as an unsigned.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- the value of the field converted to type
int - Throws:
IllegalArgumentException- if the field doesn't exist, or the field value cannot be converted to the typeintvia a widening conversion- See Also:
hasField(String)
-
getFloat
public final float getFloat(String name)
Returns the value of a field of typefloator of another primitive type convertible to typefloatvia a widening conversion.This method can be used on fields of type
float,long,int,short,charandbyte.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- the value of the field converted to type
float - Throws:
IllegalArgumentException- if the field doesn't exist, or the field value cannot be converted to the typefloatvia a widening conversion- See Also:
hasField(String)
-
getLong
public final long getLong(String name)
Returns the value of a field of typelongor of another primitive type convertible to typelongvia a widening conversion.This method can be used on fields of type
long,int,short,charandbyte.If the field has the annotation
@Unsignedand is of a narrower type thanlong, then the value will be returned as an unsigned.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- the value of the field converted to type
long - Throws:
IllegalArgumentException- if the field doesn't exist, or the field value cannot be converted to the typelongvia a widening conversion- See Also:
hasField(String)
-
getDouble
public final double getDouble(String name)
Returns the value of a field of typedoubleor of another primitive type convertible to typedoublevia a widening conversion.This method can be used on fields of type
double,float,long,int,short,charandbyte.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- the value of the field converted to type
double - Throws:
IllegalArgumentException- if the field doesn't exist, or the field value cannot be converted to the typedoublevia a widening conversion- See Also:
hasField(String)
-
getString
public final String getString(String name)
Returns the value of a field of typeString.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- the value of the field as a
String, can benull - Throws:
IllegalArgumentException- if the field doesn't exist, or the field is not of typeString- See Also:
hasField(String)
-
getDuration
public final Duration getDuration(String name)
Returns the value of a timespan field.This method can be used on fields annotated with
@Timespan, and of typelong,int,short,charandbyte.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- a timespan represented as a
Duration, notnull - Throws:
IllegalArgumentException- if the field doesn't exist, or the field value cannot be converted to aDuration- See Also:
hasField(String)
-
getInstant
public final Instant getInstant(String name)
Returns the value of a timestamp field.This method can be used on fields annotated with
@Timestamp, and of typelong,int,short,charandbyte.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- a timstamp represented as an
Instant, notnull - Throws:
IllegalArgumentException- if the field doesn't exist, or the field value cannot be converted to aInstant- See Also:
hasField(String)
-
getClass
public final RecordedClass getClass(String name)
Returns the value of a field of typeClass.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- the value of the field as a
RecordedClass, can benull - Throws:
IllegalArgumentException- if the field doesn't exist, or the field is not of typeClass- See Also:
hasField(String)
-
getThread
public final RecordedThread getThread(String name)
Returns the value of a field of typeThread.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
- Parameters:
name- name of the field to get, notnull- Returns:
- the value of the field as a
RecordedThread, can benull - Throws:
IllegalArgumentException- if the field doesn't exist, or the field is not of typeThread- See Also:
hasField(String)
-
toString
public final String toString()
Returns a textual representation of this object.It's possible to index into a nested object using
".", for instance"foo.bar".Callers of this method should take into account that a field may change or be removed in a future JDK version. It is good practice to validate the field before attempting access.
-
-