The following example shows how to implement an Event class.
public class Example { @Label("Hello World") @Description("Helps programmer getting started") static class HelloWorld extends Event { @Label("Message") String message; } public static void main(String... args) { HelloWorld event = new HelloWorld(); event.message = "hello, world!"; event.commit(); } }
After an event is allocated and its field members are populated, it can be
written to the Flight Recorder system by using the commit() method.
By default, an event is enabled. To disable an event annotate the
Event class with @Enabled(false).
Supported field types are the Java primitives: boolean, char,
byte, short, int, long, float, and
double. Supported reference types are: String, Thread
and Class. Arrays, enums, and other reference types are silently
ignored and not included. Fields that are of the supported types can be
excluded by using the transient modifier. Static fields, even of the
supported types, are not included.
Tools can visualize data in a meaningful way when annotations are used (for
example, Label, Description, and Timespan).
Annotations applied to an Event class or its fields are included if
they are present (indirectly, directly, or associated), have the
MetadataDefinition annotation, and they do not contain enums, arrays,
or classes.
Gathering data to store in an event can be expensive. The
Event#shouldCommit() method can be used to verify whether an event
instance would actually be written to the system when the
commit() method is invoked. If
shouldCommit() returns false, then those operations can be
avoided.
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public final void | |
| public final void | commit()
Overrides jdk. Writes the field values, time stamp, and event duration to the Flight Recorder system. |
| public final void | |
| public final boolean | Returns: true if event is enabled, false otherwiseOverrides jdk. Returns |
| public final void | set(int
the index of the field that is passed to
index, Object EventFactory#create(java.value to set, can be value)nullOverrides jdk. Sets a field value. |
| public final boolean | Returns: true if the event can be written to the Flight Recorder
system, false otherwiseOverrides jdk. Returns |
| Event | back to summary |
|---|---|
| protected Event() Sole constructor, for invocation by subclass constructors, typically implicit. | |
| begin | back to summary |
|---|---|
| public final void begin() Overrides jdk. Starts the timing of this event.
| |
| commit | back to summary |
|---|---|
| public final void commit() Overrides jdk. Writes the field values, time stamp, and event duration to the Flight Recorder system.
If the event starts with an invocation of the
| |
| end | back to summary |
|---|---|
| public final void end() Overrides jdk. Ends the timing of this event.
The
| |
| isEnabled | back to summary |
|---|---|
| public final boolean isEnabled() Overrides jdk. Returns
| |
| set | back to summary |
|---|---|
| public final void set(int index, Object value) Overrides jdk. Sets a field value.
Applicable only if the event is dynamically defined using the
The supplied
| |
| shouldCommit | back to summary |
|---|---|
| public final boolean shouldCommit() Overrides jdk. Returns
| |