Problem Statement
Problem
Currently, Jafar's typed API requires users to define interfaces annotated with @JfrType to parse JFR events. This creates friction when working with existing JFR event classes that extend jdk.jfr.Event.
Current limitation:
// This fails with: "JFR type handler must be an interface"
@Name("com.example.MyCustomEvent")
public class MyCustomEvent extends Event {
@Label("Request ID")
public String requestId;
@Label("Duration")
public long duration;
}
// User must create a separate interface
@JfrType("com.example.MyCustomEvent")
public interface MyCustomEventHandler {
@JfrField("requestId") String requestId();
@JfrField("duration") long duration();
}
Proposed Solution
Allow the typed API to accept concrete JFR event classes directly by:
- Detecting JFR event classes: Check if the class extends
jdk.jfr.Event and has @Name annotation
- Automatic field mapping: Map public fields annotated with
@Label to JFR field names
- Fallback to interface requirement: Maintain current behavior for non-JFR classes
Example usage:
@Name("com.example.MyCustomEvent")
public class MyCustomEvent extends Event {
@Label("Request ID")
public String requestId;
@Label("Duration")
public long duration;
}
// Direct usage without interface
try (TypedJafarParser p = JafarParser.newTypedParser(path)) {
p.handle(MyCustomEvent.class, (e, ctl) -> {
System.out.println("Request: " + e.requestId);
System.out.println("Duration: " + e.duration);
});
p.run();
}
Benefits
- Reduced boilerplate: No need to duplicate event structure as interfaces
- Better integration: Works seamlessly with existing JFR instrumentation code
- Consistency: Event definition and parsing use the same class
- Backward compatible: Existing interface-based code continues to work
Workarounds (Current)
Users must use the untyped API or EventIterator for concrete event classes:
// Untyped API
try (UntypedJafarParser p = JafarParser.newUntypedParser(path)) {
p.handle((type, event, ctl) -> {
if ("com.example.MyCustomEvent".equals(type.getName())) {
String requestId = (String) event.get("requestId");
}
});
p.run();
}
Proposed Solution
TBD
Alternatives Considered
No response
API Example
Breaking Change?
No - Additive change only
Priority
Important
Additional Context
No response
Checklist
Problem Statement
Problem
Currently, Jafar's typed API requires users to define interfaces annotated with
@JfrTypeto parse JFR events. This creates friction when working with existing JFR event classes that extendjdk.jfr.Event.Current limitation:
Proposed Solution
Allow the typed API to accept concrete JFR event classes directly by:
jdk.jfr.Eventand has@Nameannotation@Labelto JFR field namesExample usage:
Benefits
Workarounds (Current)
Users must use the untyped API or EventIterator for concrete event classes:
Proposed Solution
TBD
Alternatives Considered
No response
API Example
Breaking Change?
No - Additive change only
Priority
Important
Additional Context
No response
Checklist