Module jdk.jfr

Class RecordedObject

    • Method Detail

      • hasField

        public boolean hasField​(String name)
        Returns true if a field with given name exists, false otherwise.
        Parameters:
        name - name of the field to get, not null
        Returns:
        true if the field exists, false otherwise.
        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, not null
        Returns:
        value the value, can be null
        Throws:
        IllegalArgumentException - if there is no field called name
        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 type boolean.

        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, not null
        Returns:
        the value of the field, true or false
        Throws:
        IllegalArgumentException - if the field doesn't exist, or the field is not of type boolean
        See Also:
        hasField(String), getValue(String)
      • getByte

        public final byte getByte​(String name)
        Returns the value of a field of type byte.

        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, not null
        Returns:
        the value of the field
        Throws:
        IllegalArgumentException - if the field doesn't exist, or the field is not of type byte
        See Also:
        hasField(String), getValue(String)
      • getChar

        public final char getChar​(String name)
        Returns the value of a field of type char.

        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, not null
        Returns:
        the value of the field as a char
        Throws:
        IllegalArgumentException - if the field doesn't exist, or the field is not of type char
        See Also:
        hasField(String), getValue(String)
      • getShort

        public final short getShort​(String name)
        Returns the value of a field of type short or of another primitive type convertible to type short via a widening conversion.

        This method can be used on fields of type short and byte.

        If the field has the annotation @Unsigned and is of a narrower type than short, 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, not null
        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 type short via a widening conversion
        See Also:
        hasField(String)
      • getInt

        public final int getInt​(String name)
        Returns the value of a field of type int or of another primitive type convertible to type int via a widening conversion.

        This method can be used on fields of type int, short, char and byte.

        If the field has the annotation @Unsigned 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 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, not null
        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 type int via a widening conversion
        See Also:
        hasField(String)
      • getFloat

        public final float getFloat​(String name)
        Returns the value of a field of type float or of another primitive type convertible to type float via a widening conversion.

        This method can be used on fields of type float, long, int, short, char and byte.

        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, not null
        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 type float via a widening conversion
        See Also:
        hasField(String)
      • getLong

        public final long getLong​(String name)
        Returns the value of a field of type long or of another primitive type convertible to type long via a widening conversion.

        This method can be used on fields of type long, int, short, char and byte.

        If the field has the annotation @Unsigned 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 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, not null
        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 type long via a widening conversion
        See Also:
        hasField(String)
      • getDouble

        public final double getDouble​(String name)
        Returns the value of a field of type double or of another primitive type convertible to type double via a widening conversion.

        This method can be used on fields of type double, float, long, int, short, char and byte.

        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, not null
        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 type double via a widening conversion
        See Also:
        hasField(String)
      • getString

        public final String getString​(String name)
        Returns the value of a field of type String.

        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, not null
        Returns:
        the value of the field as a String, can be null
        Throws:
        IllegalArgumentException - if the field doesn't exist, or the field is not of type String
        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 type long, int, short, char and byte.

        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, not null
        Returns:
        a timespan represented as a Duration, not null
        Throws:
        IllegalArgumentException - if the field doesn't exist, or the field value cannot be converted to a Duration
        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 type long, int, short, char and byte.

        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, not null
        Returns:
        a timstamp represented as an Instant, not null
        Throws:
        IllegalArgumentException - if the field doesn't exist, or the field value cannot be converted to a Instant
        See Also:
        hasField(String)
      • getClass

        public final RecordedClass getClass​(String name)
        Returns the value of a field of type Class.

        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, not null
        Returns:
        the value of the field as a RecordedClass, can be null
        Throws:
        IllegalArgumentException - if the field doesn't exist, or the field is not of type Class
        See Also:
        hasField(String)
      • getThread

        public final RecordedThread getThread​(String name)
        Returns the value of a field of type Thread.

        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, not null
        Returns:
        the value of the field as a RecordedThread, can be null
        Throws:
        IllegalArgumentException - if the field doesn't exist, or the field is not of type Thread
        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.

        Overrides:
        toString in class Object
        Returns:
        textual description of this object