use of javax.management.MBeanFeatureInfo in project geode by apache.
the class MBeanServerWrapper method getOperationContext.
// TODO: cache this
private ResourcePermission getOperationContext(ObjectName objectName, String featureName, boolean isOp) throws InstanceNotFoundException, ReflectionException {
MBeanInfo beanInfo = null;
try {
beanInfo = mbs.getMBeanInfo(objectName);
} catch (IntrospectionException e) {
throw new GemFireSecurityException("error getting beanInfo of " + objectName, e);
}
// If there is no annotation defined either in the class level or method level, we should
// consider this operation/attribute freely accessible
ResourcePermission result = null;
// find the context in the beanInfo if defined in the class level
result = getOperationContext(beanInfo.getDescriptor(), result);
MBeanFeatureInfo[] featureInfos = null;
if (isOp) {
featureInfos = beanInfo.getOperations();
} else {
featureInfos = beanInfo.getAttributes();
}
// still look into the attributes/operations to see if it's defined in the method level
for (MBeanFeatureInfo info : featureInfos) {
if (info.getName().equals(featureName)) {
// found the featureInfo of this method on the bean
result = getOperationContext(info.getDescriptor(), result);
break;
}
}
return result;
}
use of javax.management.MBeanFeatureInfo in project jdk8u_jdk by JetBrains.
the class MBeanInfoEqualsNPETest method main.
public static void main(String[] args) throws Exception {
System.out.println("---MBeanInfoEqualsNPETest-main ...");
// ----
System.out.println("\n---Testing on MBeanAttributeInfo...");
MBeanAttributeInfo mbeanAttributeInfo0 = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), "description", true, true, false);
MBeanAttributeInfo mbeanAttributeInfo = new MBeanAttributeInfo(null, SimpleType.INTEGER.getClassName(), "description", true, true, false);
test(mbeanAttributeInfo0, mbeanAttributeInfo, "class name");
mbeanAttributeInfo = new MBeanAttributeInfo("name", null, "description", true, true, false);
test(mbeanAttributeInfo0, mbeanAttributeInfo, "type");
mbeanAttributeInfo = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), null, true, true, false);
test(mbeanAttributeInfo0, mbeanAttributeInfo, "description");
// ----
System.out.println("\n---Testing on MBeanConstructorInfo...");
MBeanConstructorInfo mbeanConstructorInfo0 = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, new DescriptorSupport());
MBeanConstructorInfo mbeanConstructorInfo = new MBeanConstructorInfo(null, "", new MBeanParameterInfo[] {}, new DescriptorSupport());
test(mbeanConstructorInfo0, mbeanConstructorInfo, "name");
mbeanConstructorInfo = new MBeanConstructorInfo("", null, new MBeanParameterInfo[] {}, new DescriptorSupport());
test(mbeanConstructorInfo0, mbeanConstructorInfo, "description");
mbeanConstructorInfo = new MBeanConstructorInfo("", "", null, new DescriptorSupport());
test(mbeanConstructorInfo0, mbeanConstructorInfo, "MBeanParameterInfo");
mbeanConstructorInfo = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, null);
test(mbeanConstructorInfo0, mbeanConstructorInfo, "descriptor");
// ----
System.out.println("\n---Testing on MBeanOperationInfo...");
MBeanOperationInfo mbeanOperationInfo0 = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo(null, "description", new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "name");
mbeanOperationInfo = new MBeanOperationInfo("name", null, new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "description");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", null, "type", 1, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "MBeanParameterInfo");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "type");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, MBeanOperationInfo.UNKNOWN, null);
test(mbeanOperationInfo0, mbeanOperationInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanParameterInfo...");
MBeanParameterInfo mbeanParameterInfo0 = new MBeanParameterInfo("name", "type", "description", new DescriptorSupport());
MBeanParameterInfo mbeanParameterInfo = new MBeanParameterInfo(null, "type", "description", new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "name");
mbeanParameterInfo = new MBeanParameterInfo("name", null, "description", new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "type");
mbeanParameterInfo = new MBeanParameterInfo("name", "type", null, new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "description");
mbeanParameterInfo = new MBeanParameterInfo("name", "type", "description", null);
test(mbeanParameterInfo0, mbeanParameterInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanFeatureInfo ...");
MBeanFeatureInfo mbeanFeatureInfo0 = new MBeanFeatureInfo("name", "description", new DescriptorSupport());
MBeanFeatureInfo mbeanFeatureInfo = new MBeanFeatureInfo(null, "description", new DescriptorSupport());
test(mbeanFeatureInfo0, mbeanFeatureInfo, "name");
mbeanFeatureInfo = new MBeanFeatureInfo("name", null, new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "description");
mbeanFeatureInfo = new MBeanFeatureInfo("name", "description", null);
test(mbeanParameterInfo0, mbeanParameterInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanInfo...");
String className = "toto";
String description = "titi";
MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[] {};
MBeanConstructorInfo[] constrInfos = new MBeanConstructorInfo[] {};
MBeanOperationInfo[] operaInfos = new MBeanOperationInfo[] {};
MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[] {};
MBeanInfo minfo0 = new MBeanInfo("toto", description, attrInfos, constrInfos, operaInfos, notifInfos);
MBeanInfo minfo = new MBeanInfo(null, description, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo0, minfo, "class name");
minfo = new MBeanInfo(className, null, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo0, minfo, "description");
minfo = new MBeanInfo(className, description, null, constrInfos, operaInfos, notifInfos);
test(minfo0, minfo, "attrInfos");
minfo = new MBeanInfo(className, description, attrInfos, null, operaInfos, notifInfos);
test(minfo0, minfo, "constrInfos");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, null, notifInfos);
test(minfo0, minfo, "operaInfos");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, null);
test(minfo0, minfo, "notifInfos");
if (failed > 0) {
throw new RuntimeException("Test failed: " + failed);
} else {
System.out.println("---Test: PASSED");
}
}
use of javax.management.MBeanFeatureInfo in project ignite by apache.
the class JmxExporterSpiTest method testSysJmxMetrics.
/**
*/
@Test
public void testSysJmxMetrics() throws Exception {
DynamicMBean sysMBean = metricRegistry(ignite.name(), null, SYS_METRICS);
Set<String> res = stream(sysMBean.getMBeanInfo().getAttributes()).map(MBeanFeatureInfo::getName).collect(toSet());
assertTrue(res.contains(CPU_LOAD));
assertTrue(res.contains(GC_CPU_LOAD));
assertTrue(res.contains(metricName("memory", "heap", "init")));
assertTrue(res.contains(metricName("memory", "heap", "used")));
assertTrue(res.contains(metricName("memory", "nonheap", "committed")));
assertTrue(res.contains(metricName("memory", "nonheap", "max")));
Optional<MBeanAttributeInfo> cpuLoad = stream(sysMBean.getMBeanInfo().getAttributes()).filter(a -> a.getName().equals(CPU_LOAD)).findFirst();
assertTrue(cpuLoad.isPresent());
assertEquals(CPU_LOAD_DESCRIPTION, cpuLoad.get().getDescription());
Optional<MBeanAttributeInfo> gcCpuLoad = stream(sysMBean.getMBeanInfo().getAttributes()).filter(a -> a.getName().equals(GC_CPU_LOAD)).findFirst();
assertTrue(gcCpuLoad.isPresent());
assertEquals(GC_CPU_LOAD_DESCRIPTION, gcCpuLoad.get().getDescription());
}
Aggregations