jdk.jfr.Name Java Examples
The following examples show how to use
jdk.jfr.Name.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeLibrary.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static Type defineType(Class<?> clazz, String superType, boolean eventType) { if (!isDefined(clazz)) { Name name = clazz.getAnnotation(Name.class); String typeName = name != null ? name.value() : clazz.getName(); long id = Type.getTypeId(clazz); Type t; if (eventType) { t = new PlatformEventType(typeName, id, clazz.getClassLoader() == null, true); } else { t = new Type(typeName, superType, id); } types.put(t.getId(), t); return t; } return null; }
Example #2
Source File: TypeLibrary.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static Type defineType(Class<?> clazz, String superType, boolean eventType) { if (!isDefined(clazz)) { Name name = clazz.getAnnotation(Name.class); String typeName = name != null ? name.value() : clazz.getName(); long id = Type.getTypeId(clazz); Type t; if (eventType) { t = new PlatformEventType(typeName, id, clazz.getClassLoader() == null, true); } else { t = new Type(typeName, superType, id); } types.put(t.getId(), t); return t; } return null; }
Example #3
Source File: TestName.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { EventType t = EventType.getEventType(NamedEvent.class); ValueDescriptor testField = t.getField("testField"); SettingDescriptor setting = getSetting(t, "name"); AnnotationElement a = Events.getAnnotationByName(t, "com.oracle.TestAnnotation"); // Check that names are overridden Asserts.assertNotNull(testField, "Can't find expected field testField"); Asserts.assertEquals(t.getName(), "com.oracle.TestEvent", "Incorrect name for event"); Asserts.assertEquals(a.getTypeName(), "com.oracle.TestAnnotation", "Incorrect name for annotation"); Asserts.assertEquals(a.getTypeName(), "com.oracle.TestAnnotation", "Incorrect name for annotation"); Asserts.assertEquals(setting.getName(), "name", "Incorrect name for setting"); // Check that @Name is persisted assertAnnotation(t.getAnnotation(Name.class), "@Name should be persisted on event"); assertAnnotation(testField.getAnnotation(Name.class), "@Name should be persisted on field"); assertAnnotation(a.getAnnotation(Name.class), "@Name should be persisted on annotations"); assertAnnotation(setting.getAnnotation(Name.class), "@Name should be persisted on setting"); }
Example #4
Source File: TestDynamicAnnotations.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void testEventFactoryExample() throws IOException { List<ValueDescriptor> fields = new ArrayList<>(); List<AnnotationElement> messageAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Message")); fields.add(new ValueDescriptor(String.class, "message", messageAnnotations)); List<AnnotationElement> numberAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Number")); fields.add(new ValueDescriptor(int.class, "number", numberAnnotations)); String[] category = { "Example", "Getting Started" }; List<AnnotationElement> eventAnnotations = new ArrayList<>(); eventAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld")); eventAnnotations.add(new AnnotationElement(Label.class, "Hello World")); eventAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started")); eventAnnotations.add(new AnnotationElement(Category.class, category)); EventFactory f = EventFactory.create(eventAnnotations, fields); Event event = f.newEvent(); event.set(0, "hello, world!"); event.set(1, 4711); event.commit(); }
Example #5
Source File: TypeLibrary.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static Type defineType(Class<?> clazz, String superType, boolean eventType) { if (!isDefined(clazz)) { Name name = clazz.getAnnotation(Name.class); String typeName = name != null ? name.value() : clazz.getName(); long id = Type.getTypeId(clazz); Type t; if (eventType) { t = new PlatformEventType(typeName, id, clazz.getClassLoader() == null, true); } else { t = new Type(typeName, superType, id); } types.put(t.getId(), t); return t; } return null; }
Example #6
Source File: TestDynamicAnnotations.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void testEventFactoryExample() throws IOException { List<ValueDescriptor> fields = new ArrayList<>(); List<AnnotationElement> messageAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Message")); fields.add(new ValueDescriptor(String.class, "message", messageAnnotations)); List<AnnotationElement> numberAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Number")); fields.add(new ValueDescriptor(int.class, "number", numberAnnotations)); String[] category = { "Example", "Getting Started" }; List<AnnotationElement> eventAnnotations = new ArrayList<>(); eventAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld")); eventAnnotations.add(new AnnotationElement(Label.class, "Hello World")); eventAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started")); eventAnnotations.add(new AnnotationElement(Category.class, category)); EventFactory f = EventFactory.create(eventAnnotations, fields); Event event = f.newEvent(); event.set(0, "hello, world!"); event.set(1, 4711); event.commit(); }
Example #7
Source File: TestName.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { EventType t = EventType.getEventType(NamedEvent.class); ValueDescriptor testField = t.getField("testField"); SettingDescriptor setting = getSetting(t, "name"); AnnotationElement a = Events.getAnnotationByName(t, "com.oracle.TestAnnotation"); // Check that names are overridden Asserts.assertNotNull(testField, "Can't find expected field testField"); Asserts.assertEquals(t.getName(), "com.oracle.TestEvent", "Incorrect name for event"); Asserts.assertEquals(a.getTypeName(), "com.oracle.TestAnnotation", "Incorrect name for annotation"); Asserts.assertEquals(a.getTypeName(), "com.oracle.TestAnnotation", "Incorrect name for annotation"); Asserts.assertEquals(setting.getName(), "name", "Incorrect name for setting"); // Check that @Name is persisted assertAnnotation(t.getAnnotation(Name.class), "@Name should be persisted on event"); assertAnnotation(testField.getAnnotation(Name.class), "@Name should be persisted on field"); assertAnnotation(a.getAnnotation(Name.class), "@Name should be persisted on annotations"); assertAnnotation(setting.getAnnotation(Name.class), "@Name should be persisted on setting"); }
Example #8
Source File: TestName.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { EventType t = EventType.getEventType(NamedEvent.class); ValueDescriptor testField = t.getField("testField"); SettingDescriptor setting = getSetting(t, "name"); AnnotationElement a = Events.getAnnotationByName(t, "com.oracle.TestAnnotation"); // Check that names are overridden Asserts.assertNotNull(testField, "Can't find expected field testField"); Asserts.assertEquals(t.getName(), "com.oracle.TestEvent", "Incorrect name for event"); Asserts.assertEquals(a.getTypeName(), "com.oracle.TestAnnotation", "Incorrect name for annotation"); Asserts.assertEquals(a.getTypeName(), "com.oracle.TestAnnotation", "Incorrect name for annotation"); Asserts.assertEquals(setting.getName(), "name", "Incorrect name for setting"); // Check that @Name is persisted assertAnnotation(t.getAnnotation(Name.class), "@Name should be persisted on event"); assertAnnotation(testField.getAnnotation(Name.class), "@Name should be persisted on field"); assertAnnotation(a.getAnnotation(Name.class), "@Name should be persisted on annotations"); assertAnnotation(setting.getAnnotation(Name.class), "@Name should be persisted on setting"); }
Example #9
Source File: TestDynamicAnnotations.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void testEventFactoryExample() throws IOException { List<ValueDescriptor> fields = new ArrayList<>(); List<AnnotationElement> messageAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Message")); fields.add(new ValueDescriptor(String.class, "message", messageAnnotations)); List<AnnotationElement> numberAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Number")); fields.add(new ValueDescriptor(int.class, "number", numberAnnotations)); String[] category = { "Example", "Getting Started" }; List<AnnotationElement> eventAnnotations = new ArrayList<>(); eventAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld")); eventAnnotations.add(new AnnotationElement(Label.class, "Hello World")); eventAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started")); eventAnnotations.add(new AnnotationElement(Category.class, category)); EventFactory f = EventFactory.create(eventAnnotations, fields); Event event = f.newEvent(); event.set(0, "hello, world!"); event.set(1, 4711); event.commit(); }
Example #10
Source File: EventControl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") private void defineSettings(Class<?> eventClass) { // Iterate up the class hierarchy and let // subclasses shadow base classes. boolean allowPrivateMethod = true; while (eventClass != null) { for (Method m : eventClass.getDeclaredMethods()) { boolean isPrivate = Modifier.isPrivate(m.getModifiers()); if (m.getReturnType() == Boolean.TYPE && m.getParameterCount() == 1 && (!isPrivate || allowPrivateMethod)) { SettingDefinition se = m.getDeclaredAnnotation(SettingDefinition.class); if (se != null) { Class<?> settingClass = m.getParameters()[0].getType(); if (!Modifier.isAbstract(settingClass.getModifiers()) && SettingControl.class.isAssignableFrom(settingClass)) { String name = m.getName(); Name n = m.getAnnotation(Name.class); if (n != null) { name = n.value(); } if (!eventControls.containsKey(name)) { defineSetting((Class<? extends SettingControl>) settingClass, m, type, name); } } } } } eventClass = eventClass.getSuperclass(); allowPrivateMethod = false; } }
Example #11
Source File: CustomEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@SettingDefinition @Name("newName") @Label(ANNOTATED_METHOD) @Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD) @Timespan(Timespan.NANOSECONDS) public boolean whatever(AnnotatedSetting s) { return true; }
Example #12
Source File: BaseEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@SettingDefinition @Name("protectedBase") @Label("Protected Base") @Description("Description of protected base") @Frequency protected boolean something(PlainSetting control) { return true; }
Example #13
Source File: TypeLibrary.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static ValueDescriptor createField(Field field) { int mod = field.getModifiers(); if (Modifier.isTransient(mod)) { return null; } if (Modifier.isStatic(mod)) { return null; } Class<?> fieldType = field.getType(); if (!Type.isKnownType(fieldType)) { return null; } boolean constantPool = Thread.class == fieldType || fieldType == Class.class; Type type = createType(fieldType); String fieldName = field.getName(); Name name = field.getAnnotation(Name.class); String useName = fieldName; if (name != null) { useName = name.value(); } List<jdk.jfr.AnnotationElement> ans = new ArrayList<>(); for (Annotation a : resolveRepeatedAnnotations(field.getAnnotations())) { AnnotationElement ae = createAnnotation(a); if (ae != null) { ans.add(ae); } } return PrivateAccess.getInstance().newValueDescriptor(useName, type, ans, 0, constantPool, fieldName); }
Example #14
Source File: BaseEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Name("baseName") @Label("Base Label") @Description("Base description") @SettingDefinition public boolean overridden(AnnotatedSetting control) { return true; }
Example #15
Source File: TypeLibrary.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static ValueDescriptor createField(Field field) { int mod = field.getModifiers(); if (Modifier.isTransient(mod)) { return null; } if (Modifier.isStatic(mod)) { return null; } Class<?> fieldType = field.getType(); if (!Type.isKnownType(fieldType)) { return null; } boolean constantPool = Thread.class == fieldType || fieldType == Class.class; Type type = createType(fieldType); String fieldName = field.getName(); Name name = field.getAnnotation(Name.class); String useName = fieldName; if (name != null) { useName = name.value(); } List<jdk.jfr.AnnotationElement> ans = new ArrayList<>(); for (Annotation a : resolveRepeatedAnnotations(field.getAnnotations())) { AnnotationElement ae = createAnnotation(a); if (ae != null) { ans.add(ae); } } return PrivateAccess.getInstance().newValueDescriptor(useName, type, ans, 0, constantPool, fieldName); }
Example #16
Source File: BaseEvent.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Name("baseName") @Label("Base Label") @Description("Base description") @SettingDefinition public boolean overridden(AnnotatedSetting control) { return true; }
Example #17
Source File: BaseEvent.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@SettingDefinition @Name("protectedBase") @Label("Protected Base") @Description("Description of protected base") @Frequency protected boolean something(PlainSetting control) { return true; }
Example #18
Source File: CustomEvent.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@SettingDefinition @Name("newName") @Label(ANNOTATED_METHOD) @Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD) @Timespan(Timespan.NANOSECONDS) public boolean whatever(AnnotatedSetting s) { return true; }
Example #19
Source File: EventControl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") private void defineSettings(Class<?> eventClass) { // Iterate up the class hierarchy and let // subclasses shadow base classes. boolean allowPrivateMethod = true; while (eventClass != null) { for (Method m : eventClass.getDeclaredMethods()) { boolean isPrivate = Modifier.isPrivate(m.getModifiers()); if (m.getReturnType() == Boolean.TYPE && m.getParameterCount() == 1 && (!isPrivate || allowPrivateMethod)) { SettingDefinition se = m.getDeclaredAnnotation(SettingDefinition.class); if (se != null) { Class<?> settingClass = m.getParameters()[0].getType(); if (!Modifier.isAbstract(settingClass.getModifiers()) && SettingControl.class.isAssignableFrom(settingClass)) { String name = m.getName(); Name n = m.getAnnotation(Name.class); if (n != null) { name = n.value(); } if (!eventControls.containsKey(name)) { defineSetting((Class<? extends SettingControl>) settingClass, m, type, name); } } } } } eventClass = eventClass.getSuperclass(); allowPrivateMethod = false; } }
Example #20
Source File: TypeLibrary.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static ValueDescriptor createField(Field field) { int mod = field.getModifiers(); if (Modifier.isTransient(mod)) { return null; } if (Modifier.isStatic(mod)) { return null; } Class<?> fieldType = field.getType(); if (!Type.isKnownType(fieldType)) { return null; } boolean constantPool = Thread.class == fieldType || fieldType == Class.class; Type type = createType(fieldType); String fieldName = field.getName(); Name name = field.getAnnotation(Name.class); String useName = fieldName; if (name != null) { useName = name.value(); } List<jdk.jfr.AnnotationElement> ans = new ArrayList<>(); for (Annotation a : resolveRepeatedAnnotations(field.getAnnotations())) { AnnotationElement ae = createAnnotation(a); if (ae != null) { ans.add(ae); } } return PrivateAccess.getInstance().newValueDescriptor(useName, type, ans, 0, constantPool, fieldName); }
Example #21
Source File: EventControl.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") private void defineSettings(Class<?> eventClass) { // Iterate up the class hierarchy and let // subclasses shadow base classes. boolean allowPrivateMethod = true; while (eventClass != null) { for (Method m : eventClass.getDeclaredMethods()) { boolean isPrivate = Modifier.isPrivate(m.getModifiers()); if (m.getReturnType() == Boolean.TYPE && m.getParameterCount() == 1 && (!isPrivate || allowPrivateMethod)) { SettingDefinition se = m.getDeclaredAnnotation(SettingDefinition.class); if (se != null) { Class<?> settingClass = m.getParameters()[0].getType(); if (!Modifier.isAbstract(settingClass.getModifiers()) && SettingControl.class.isAssignableFrom(settingClass)) { String name = m.getName(); Name n = m.getAnnotation(Name.class); if (n != null) { name = n.value(); } if (!eventControls.containsKey(name)) { defineSetting((Class<? extends SettingControl>) settingClass, m, type, name); } } } } } eventClass = eventClass.getSuperclass(); allowPrivateMethod = false; } }
Example #22
Source File: BaseEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Name("baseName") @Label("Base Label") @Description("Base description") @SettingDefinition public boolean overridden(AnnotatedSetting control) { return true; }
Example #23
Source File: BaseEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@SettingDefinition @Name("protectedBase") @Label("Protected Base") @Description("Description of protected base") @Frequency protected boolean something(PlainSetting control) { return true; }
Example #24
Source File: CustomEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@SettingDefinition @Name("newName") @Label(ANNOTATED_METHOD) @Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD) @Timespan(Timespan.NANOSECONDS) public boolean whatever(AnnotatedSetting s) { return true; }
Example #25
Source File: CustomEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@SettingDefinition @Name("newName") @Label(ANNOTATED_METHOD) @Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD) @Timespan(Timespan.NANOSECONDS) public boolean whatever(AnnotatedSetting s) { return true; }
Example #26
Source File: BaseEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@SettingDefinition @Name("protectedBase") @Label("Protected Base") @Description("Description of protected base") @Frequency protected boolean something(PlainSetting control) { return true; }
Example #27
Source File: BaseEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Name("baseName") @Label("Base Label") @Description("Base description") @SettingDefinition public boolean overridden(AnnotatedSetting control) { return true; }
Example #28
Source File: EventTypePrototype.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public EventTypePrototype(String name, List<AnnotationElement> as, List<ValueDescriptor> fields) { this.annotations = new ArrayList<>(as); this.annotations.add(new AnnotationElement(Name.class, name)); this.fields = fields; this.name = name; }
Example #29
Source File: JFRSecurityTestSuite.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static void doInConstrainedEnvironment() throws Throwable { checkNoDirectAccess(); assertPermission(() -> { FlightRecorder.getFlightRecorder(); }, FlightRecorderPermission.class, "accessFlightRecorder", false); assertPermission(() -> { FlightRecorder.register(MyEvent.class); }, FlightRecorderPermission.class, "registerEvent", false); assertPermission(() -> { FlightRecorder.unregister(MyEvent.class); }, FlightRecorderPermission.class, "registerEvent", false); assertPermission(() -> { FlightRecorder.addPeriodicEvent(MyEvent.class, periodicEvent); }, FlightRecorderPermission.class, "registerEvent", false); assertPermission(() -> { FlightRecorder.removePeriodicEvent(periodicEvent); }, FlightRecorderPermission.class, "registerEvent", false); assertPermission(() -> { FlightRecorder.addListener(frl); }, FlightRecorderPermission.class, "accessFlightRecorder", false); assertPermission(() -> { FlightRecorder.removeListener(frl); }, FlightRecorderPermission.class, "accessFlightRecorder", false); assertPermission(() -> { new MyEvent().commit(); }, FlightRecorderPermission.class, "registerEvent", true); assertPermission(() -> { Configuration.create(Paths.get(protectedLocationPath)); }, FilePermission.class, protectedLocationPath, false); assertPermission(() -> { EventFactory.create(new ArrayList<AnnotationElement>(), new ArrayList<ValueDescriptor>()); }, FlightRecorderPermission.class, "registerEvent", false); assertPermission(() -> { new AnnotationElement(Name.class, "com.example.HelloWorld"); }, FlightRecorderPermission.class, "registerEvent", false); assertPermission(() -> { new ValueDescriptor(MyEvent.class, "", new ArrayList<AnnotationElement>()); }, FlightRecorderPermission.class, "registerEvent", false); assertPermission(() -> { new Recording(); }, FlightRecorderPermission.class, "accessFlightRecorder", false); assertPermission(() -> { new RecordingFile(Paths.get(protectedLocationPath)); }, FilePermission.class, protectedLocationPath, false); assertPermission(() -> { RecordingFile.readAllEvents(Paths.get(protectedLocationPath)); }, FilePermission.class, protectedLocationPath, false); assertPermission(() -> { EventType.getEventType(MyEvent2.class); }, FlightRecorderPermission.class, "registerEvent", true); }
Example #30
Source File: TestName.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@SettingDefinition @Name("name") boolean dummy(SimpleSetting ds) { return true; }