Search in sources :

Example 51 with Descriptor

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;
}
Also used : Descriptor(javax.management.Descriptor) Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo)

Example 52 with Descriptor

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);
    }
}
Also used : ReflectPermission(java.lang.reflect.ReflectPermission) MBeanPermission(javax.management.MBeanPermission) Permission(java.security.Permission) Descriptor(javax.management.Descriptor)

Example 53 with Descriptor

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);
    }
}
Also used : Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor)

Example 54 with Descriptor

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);
}
Also used : Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 55 with Descriptor

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);
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) OpenMBeanOperationInfo(javax.management.openmbean.OpenMBeanOperationInfo) Descriptor(javax.management.Descriptor) OpenMBeanOperationInfo(javax.management.openmbean.OpenMBeanOperationInfo) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Aggregations

Descriptor (javax.management.Descriptor)73 RuntimeOperationsException (javax.management.RuntimeOperationsException)18 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)16 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)16 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)11 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)11 Method (java.lang.reflect.Method)10 ImmutableDescriptor (javax.management.ImmutableDescriptor)9 MBeanException (javax.management.MBeanException)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)8 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)8 MBeanInfo (javax.management.MBeanInfo)8 MBeanServer (javax.management.MBeanServer)8 ObjectName (javax.management.ObjectName)8 ServiceNotFoundException (javax.management.ServiceNotFoundException)8 ArrayList (java.util.ArrayList)7 InstanceNotFoundException (javax.management.InstanceNotFoundException)7 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 MBeanOperationInfo (javax.management.MBeanOperationInfo)7 MBeanParameterInfo (javax.management.MBeanParameterInfo)7