use of javax.management.Descriptor in project geode by apache.
the class MX4JModelMBean method getModelMBeanLogger.
private Logger getModelMBeanLogger(String notificationType) throws MBeanException {
// Get a copy to avoid synchronization
ModelMBeanInfo info = getModelMBeanInfo();
// First look if there is a suitable notification descriptor, otherwise use MBean descriptor
Descriptor descriptor = null;
Logger modelMBeanLogger = null;
if (notificationType != null) {
descriptor = info.getDescriptor(notificationType, "notification");
modelMBeanLogger = findLogger(descriptor);
}
if (modelMBeanLogger == null) {
descriptor = info.getMBeanDescriptor();
modelMBeanLogger = findLogger(descriptor);
if (modelMBeanLogger != null)
return modelMBeanLogger;
}
return null;
}
use of javax.management.Descriptor in project jdk8u_jdk by JetBrains.
the class DcmdMBeanPermissionsTest method testOperation.
static void testOperation(MBeanServer mbs, CustomSecurityManager sm, ObjectName on, MBeanOperationInfo opInfo) {
System.out.println("Testing " + opInfo.getName());
Descriptor desc = opInfo.getDescriptor();
if (desc.getFieldValue("dcmd.permissionClass") == null) {
// any security exception
if (invokeOperation(mbs, on, opInfo)) {
throw new RuntimeException("TEST FAILED");
}
} else {
// Building the required permission
Permission reqPerm = createPermission((String) desc.getFieldValue("dcmd.permissionClass"), (String) desc.getFieldValue("dcmd.permissionName"), (String) desc.getFieldValue("dcmd.permissionAction"));
// Paranoid mode: check that the SecurityManager has not already
// been granted the permission
sm.denyPermission(reqPerm);
// a security exception
if (!invokeOperation(mbs, on, opInfo)) {
throw new RuntimeException("TEST FAILED");
}
// grant the permission and re-try invoking the operation
sm.grantPermission(reqPerm);
if (invokeOperation(mbs, on, opInfo)) {
throw new RuntimeException("TEST FAILED");
}
// Clean up
sm.denyPermission(reqPerm);
}
}
use of javax.management.Descriptor in project jdk8u_jdk by JetBrains.
the class AnnotationTest method check.
private static void check(Object x, Descriptor d, Descriptor expect) {
String fail = null;
try {
Descriptor u = ImmutableDescriptor.union(d, expect);
if (!u.equals(d))
fail = "should contain " + expect + "; is " + d;
} catch (IllegalArgumentException e) {
fail = e.getMessage();
}
if (fail == null) {
System.out.println("OK: " + x);
} else {
failed = "NOT OK: Incorrect descriptor for: " + x;
System.out.println(failed);
System.out.println("..." + fail);
}
}
use of javax.management.Descriptor in project jdk8u_jdk by JetBrains.
the class AnnotationTest method main.
public static void main(String[] args) throws Exception {
System.out.println("Testing that annotations are correctly " + "reflected in Descriptor entries");
MBeanServer mbs = java.lang.management.ManagementFactory.getPlatformMBeanServer();
ObjectName on = new ObjectName("a:b=c");
Thing thing = new Thing();
mbs.registerMBean(thing, on);
check(mbs, on);
mbs.unregisterMBean(on);
ThingImpl thingImpl = new ThingImpl();
mbs.registerMBean(thingImpl, on);
Descriptor d = mbs.getMBeanInfo(on).getDescriptor();
if (!d.getFieldValue("mxbean").equals("true")) {
System.out.println("NOT OK: expected MXBean");
failed = "Expected MXBean";
}
check(mbs, on);
if (failed == null)
System.out.println("Test passed");
else
throw new Exception("TEST FAILED: " + failed);
}
use of javax.management.Descriptor in project jdk8u_jdk by JetBrains.
the class TooManyFooTest method test.
private static void test(Object child, String name, boolean mxbean) throws Exception {
final ObjectName childName = new ObjectName("test:type=Child,name=" + name);
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child, childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name + ": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name + ": OK, only " + OPCOUNT + " operations here...");
} else {
final String qual = (len > OPCOUNT) ? "many" : "few";
System.err.println(name + ": Too " + qual + " foos! Found " + len + ", expected " + OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public " + op.getReturnType() + " " + op.getName() + "();");
}
throw new RuntimeException("Too " + qual + " foos for " + name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb = (mxstr == null) ? false : Boolean.valueOf(mxstr).booleanValue();
System.out.println(name + ": mxbean=" + mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation " + mboi.getName() + "() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String) mboi.getDescriptor().getFieldValue("originalType");
if (type == null)
type = mboi.getReturnType();
if (type.equals(exp))
continue;
System.err.println("Bad return type for " + mboi.getName() + "! Found " + type + ", expected " + exp);
throw new RuntimeException("Bad return type for " + mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
Aggregations