APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.jfr

public final Class EventType

extends Object
Class Inheritance
Imports
java.lang.annotation.Annotation, java.util.Collections, .LinkedHashMap, .List, .Map, .Objects, jdk.jfr.internal.JVMSupport, .MetadataRepository, .PlatformEventType, .Type, jdk.jfr.internal.util.Utils

Describes an event, its fields, settings and annotations.

The following example shows how the EventType class can be used to print metadata about an event.

for (EventType eventType : FlightRecorder.getFlightRecorder().getEventTypes()) { System.out.println("Event Type: " + eventType.getName()); if (eventType.getLabel() != null) { System.out.println("Label: " + eventType.getLabel()); } if (eventType.getDescription() != null) { System.out.println("Description: " + eventType.getDescription()); } StringJoiner s = new StringJoiner(" / "); for (String category : eventType.getCategoryNames()) { s.add(category); } System.out.println("Category: " + s); System.out.println("Fields: " + eventType.getFields().size()); System.out.println("Annotations: " + eventType.getAnnotationElements().size()); System.out.println("Settings: " + eventType.getSettingDescriptors().size()); System.out.println("Enabled: " + eventType.isEnabled()); System.out.println(); }
for (EventType eventType : FlightRecorder.getFlightRecorder().getEventTypes()) {
    System.out.println("Event Type: " + eventType.getName());
    if (eventType.getLabel() != null) {
        System.out.println("Label: " + eventType.getLabel());
    }
    if (eventType.getDescription() != null) {
        System.out.println("Description: " + eventType.getDescription());
    }
    StringJoiner s = new StringJoiner(" / ");
    for (String category : eventType.getCategoryNames()) {
        s.add(category);
    }
    System.out.println("Category: " + s);
    System.out.println("Fields: " + eventType.getFields().size());
    System.out.println("Annotations: " + eventType.getAnnotationElements().size());
    System.out.println("Settings: " + eventType.getSettingDescriptors().size());
    System.out.println("Enabled: " + eventType.isEnabled());
    System.out.println();
}
Since
9

Field Summary

Modifier and TypeField and Description
private Map<String, ValueDescriptor>
private String
private final PlatformEventType
private static final String[]
private static final String

Constructor Summary

AccessConstructor and Description
pack-priv
EventType(PlatformEventType platformEventType)

Method Summary

Modifier and TypeMethod and Description
public <
the type of the annotation to query for and return if present
A extends Annotation
>
A

Returns:

this element's annotation for the specified annotation type if directly present, else null
getAnnotation
(Class<A>
the Class object that corresponds to the annotation type, not null
annotationClass
)

Returns the first annotation for the specified type if an annotation element with the same name is directly present, otherwise null.

public List<AnnotationElement>

Returns:

an immutable list of annotations or an empty list if no annotations exists, not null
getAnnotationElements
()

Returns an immutable list of annotation elements for this event type.

public List<String>

Returns:

an immutable list of category names, or a list with the name "Uncategorized" if no category is set
getCategoryNames
()

Returns the list of human-readable names that make up the categories for this event type (for example, "Java Application", "Statistics").

public String

Returns:

the description, or null if no description exists
getDescription
()

Returns a short sentence that describes the event class.

public static EventType

Returns:

the event class, or null if class doesn't exist
getEventType
(Class<? extends Event>
the event class, not null
eventClass
)

Returns the event type for an event class, or null if it doesn't exist.

public ValueDescriptor

Returns:

a value descriptor that describes the field, or null if the field with the specified name doesn't exist
getField
(String
of the field to get, not null
name
)

Returns the field with the specified name, or null if it doesn't exist.

public List<ValueDescriptor>

Returns:

the list of field descriptors, not null
getFields
()

Returns an immutable list of descriptors that describe the event fields of this event type.

public long

Returns:

the ID that is used in the JVM
getId
()

Returns a unique ID for this event type in the Java Virtual Machine (JVM).

public String

Returns:

the label, or null if a label is not set
getLabel
()

Returns a human-readable name (for example, "CPU Load").

public String

Returns:

the name, not null
getName
()

Returns an identifier for the event (for example, "jdk.CPULoad").

pack-priv PlatformEventType
public List<SettingDescriptor>

Returns:

the list of setting descriptors for this event type, not null
getSettingDescriptors
()

Returns an immutable list of the setting descriptors that describe the available event settings for this event type.

pack-priv Type
public boolean

Returns:

true if event is enabled, false otherwise
isEnabled
()

Returns true if the event is enabled and at least one recording is running, false otherwise.

pack-priv boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private Map<String, ValueDescriptor> cache
labelback to summary
private String label
platformEventTypeback to summary
private final PlatformEventType platformEventType
UNCATEGORIZEDback to summary
private static final String[] UNCATEGORIZED
UNKNOWNback to summary
private static final String UNKNOWN

Constructor Detail

EventTypeback to summary
pack-priv EventType(PlatformEventType platformEventType)

Method Detail

getAnnotationback to summary
public <A extends Annotation> A getAnnotation(Class<A> annotationClass)

Returns the first annotation for the specified type if an annotation element with the same name is directly present, otherwise null.

Parameters
<A>
the type of the annotation to query for and return if present
annotationClass:Class<A>

the Class object that corresponds to the annotation type, not null

Returns:A

this element's annotation for the specified annotation type if directly present, else null

getAnnotationElementsback to summary
public List<AnnotationElement> getAnnotationElements()

Returns an immutable list of annotation elements for this event type.

Returns:List<AnnotationElement>

an immutable list of annotations or an empty list if no annotations exists, not null

getCategoryNamesback to summary
public List<String> getCategoryNames()

Returns the list of human-readable names that make up the categories for this event type (for example, "Java Application", "Statistics").

Returns:List<String>

an immutable list of category names, or a list with the name "Uncategorized" if no category is set

See Also
Category
getDescriptionback to summary
public String getDescription()

Returns a short sentence that describes the event class.

The description of an event class can be set with Description.

Returns:String

the description, or null if no description exists

See Also
Description
getEventTypeback to summary
public static EventType getEventType(Class<? extends Event> eventClass)

Returns the event type for an event class, or null if it doesn't exist.

Parameters
eventClass:Class<? extends Event>

the event class, not null

Returns:EventType

the event class, or null if class doesn't exist

Exceptions
IllegalArgumentException:
if eventClass is an abstract class
IllegalStateException:
if the class is annotated with Registered(false), but not manually registered
getFieldback to summary
public ValueDescriptor getField(String name)

Returns the field with the specified name, or null if it doesn't exist.

It's possible to index into a nested field by using "." (for instance "thread.group.parent.name").

Parameters
name:String

of the field to get, not null

Returns:ValueDescriptor

a value descriptor that describes the field, or null if the field with the specified name doesn't exist

getFieldsback to summary
public List<ValueDescriptor> getFields()

Returns an immutable list of descriptors that describe the event fields of this event type.

Returns:List<ValueDescriptor>

the list of field descriptors, not null

getIdback to summary
public long getId()

Returns a unique ID for this event type in the Java Virtual Machine (JVM).

Returns:long

the ID that is used in the JVM

getLabelback to summary
public String getLabel()

Returns a human-readable name (for example, "CPU Load").

The label of an event class can be set with Label.

Returns:String

the label, or null if a label is not set

See Also
Label
getNameback to summary
public String getName()

Returns an identifier for the event (for example, "jdk.CPULoad").

The identifier is the fully qualified name of the event class, if not set using the Name annotation.

Returns:String

the name, not null

See Also
Name
getPlatformEventTypeback to summary
pack-priv PlatformEventType getPlatformEventType()
getSettingDescriptorsback to summary
public List<SettingDescriptor> getSettingDescriptors()

Returns an immutable list of the setting descriptors that describe the available event settings for this event type.

Returns:List<SettingDescriptor>

the list of setting descriptors for this event type, not null

getTypeback to summary
pack-priv Type getType()
isEnabledback to summary
public boolean isEnabled()

Returns true if the event is enabled and at least one recording is running, false otherwise.

By default, the event is enabled. The event can be enabled or disabled by setting the enabled setting to true or false, programmatically or by using a configuration file. The event can also be disabled by annotating event with the @Enabled(false) annotation.

Returns:boolean

true if event is enabled, false otherwise

See Also
Enabled, Recording#enable(Class)
isVisibleback to summary
pack-priv boolean isVisible()