-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sample_09_Registration.java
56 lines (49 loc) · 1.73 KB
/
Sample_09_Registration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import jdk.jfr.Event;
import jdk.jfr.FlightRecorder;
import jdk.jfr.Label;
import jdk.jfr.Name;
import jdk.jfr.Registered;
// Description
// -----------
//
// The sample shows how an event class can be registered and unregistered.
// By default, events are registered when the event class is initialized. It is
// possible to override that behavior using the Registered annotation.
//
// One reason to register manually is to take control of the security context
// the event is being initialized in.
//
// The difference between the Enabled annotation and the Registered annotation,
// is that when an event is unregistered, its metadata, such as the field layout
// , is not available for inspection.
//
// A call to FlightRecorder::register can ensure that an event class is visible
// for configuration, for example to a JMX client
// How to run
// ----------
//
// $ java -XX:StartFlightRecording:filename=09.jfr Sample_08_Allowed_Fields.java
// $ jfr print --events Message 09.jfr
//
//
public class Sample_09_Registration {
@Name("com.sample.Message")
@Label("Message")
@Registered(false)
static class Message extends Event {
String message;
}
public static void main(String... args) {
Message event1 = new Message();
event1.message = "Not registered, so you won't see this";
event1.commit();
FlightRecorder.register(Message.class);
Message event2 = new Message();
event2.message = "Now registered, so you will see this!";
event2.commit();
FlightRecorder.unregister(Message.class);
Message event3 = new Message();
event3.message = "Not registered again, so you won't see this";
event3.commit();
}
}