Class Event
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
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.
- Since:
- 9
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedEvent()Sole constructor, for invocation by subclass constructors, typically implicit. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidbegin()Starts the timing of this event.final voidcommit()Writes the field values, time stamp, and event duration to the Flight Recorder system.final voidend()Ends the timing of this event.final booleanReturnstrueif at least one recording is running, and the enabled setting for this event is set totrue, otherwisefalseis returned.final voidSets a field value.final booleanReturnstrueif the enabled setting for this event is set totrueand if the duration is within the threshold for the event,falseotherwise.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
Event
protected Event()Sole constructor, for invocation by subclass constructors, typically implicit.
-
-
Method Details
-
begin
public final void begin()Starts the timing of this event. -
end
public final void end()Ends the timing of this event. Theendmethod must be invoked after thebeginmethod. -
commit
public final void commit()Writes the field values, time stamp, and event duration to the Flight Recorder system.If the event starts with an invocation of the
beginmethod, but does not end with an explicit invocation of theendmethod, then the event ends when thecommitmethod is invoked. -
isEnabled
public final boolean isEnabled()Returnstrueif at least one recording is running, and the enabled setting for this event is set totrue, otherwisefalseis returned.- Returns:
trueif event is enabled,falseotherwise
-
shouldCommit
public final boolean shouldCommit()Returnstrueif the enabled setting for this event is set totrueand if the duration is within the threshold for the event,falseotherwise. The threshold is the minimum threshold for all running recordings.- Returns:
trueif the event can be written to the Flight Recorder system,falseotherwise
-
set
Sets a field value.Applicable only if the event is dynamically defined using the
EventFactoryclass.The supplied
indexcorresponds to the index of theValueDescriptorobject passed to the factory method of theEventFactoryclass.- Parameters:
index- the index of the field that is passed toEventFactory.create(java.util.List, java.util.List)value- value to set, can benull- Throws:
UnsupportedOperationException- if it's not a dynamically generated eventIndexOutOfBoundsException- ifindexis less than0or greater than or equal to the number of fields specified for the event- See Also:
-