Search in sources :

Example 16 with MBeanConstructorInfo

use of javax.management.MBeanConstructorInfo in project felix by apache.

the class MBeanIntrospector method createMBeanConstructorInfo.

private MBeanConstructorInfo[] createMBeanConstructorInfo(MBeanMetaData metadata, MBeanDescription descrs) {
    Class mbeanClass = metadata.mbean.getClass();
    Constructor[] ctors = mbeanClass.getConstructors();
    MBeanConstructorInfo[] constructors = new MBeanConstructorInfo[ctors.length];
    for (int i = 0; i < ctors.length; ++i) {
        Constructor constructor = ctors[i];
        String descr = descrs == null ? null : descrs.getConstructorDescription(constructor);
        Class[] params = constructor.getParameterTypes();
        MBeanParameterInfo[] paramsInfo = new MBeanParameterInfo[params.length];
        for (int j = 0; j < params.length; ++j) {
            Class param = params[j];
            String paramName = descrs == null ? null : descrs.getConstructorParameterName(constructor, j);
            String paramDescr = descrs == null ? null : descrs.getConstructorParameterDescription(constructor, j);
            paramsInfo[j] = new MBeanParameterInfo(paramName, param.getName(), paramDescr);
        }
        String ctorName = constructor.getName();
        MBeanConstructorInfo info = new MBeanConstructorInfo(ctorName.substring(ctorName.lastIndexOf('.') + 1), descr, paramsInfo);
        constructors[i] = info;
    }
    return constructors;
}
Also used : MBeanConstructorInfo(javax.management.MBeanConstructorInfo) Constructor(java.lang.reflect.Constructor) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 17 with MBeanConstructorInfo

use of javax.management.MBeanConstructorInfo in project jdk8u_jdk by JetBrains.

the class MBeanIntrospector method findConstructors.

private static MBeanConstructorInfo[] findConstructors(Class<?> c) {
    Constructor<?>[] cons = c.getConstructors();
    MBeanConstructorInfo[] mbc = new MBeanConstructorInfo[cons.length];
    for (int i = 0; i < cons.length; i++) {
        final String descr = "Public constructor of the MBean";
        mbc[i] = new MBeanConstructorInfo(descr, cons[i]);
    }
    return mbc;
}
Also used : MBeanConstructorInfo(javax.management.MBeanConstructorInfo) Constructor(java.lang.reflect.Constructor)

Example 18 with MBeanConstructorInfo

use of javax.management.MBeanConstructorInfo in project Payara by payara.

the class MBeanConstructorInfoStringifier method stringify.

@Override
public String stringify(Object o) {
    final MBeanConstructorInfo constructor = (MBeanConstructorInfo) o;
    final String name = constructor.getName();
    final int lastDot = name.lastIndexOf('.');
    final String abbreviatedName = name.substring(lastDot + 1, name.length());
    final String params = "(" + paramsToString(constructor.getSignature(), mOptions) + ")";
    return (abbreviatedName + params);
}
Also used : MBeanConstructorInfo(javax.management.MBeanConstructorInfo)

Example 19 with MBeanConstructorInfo

use of javax.management.MBeanConstructorInfo in project tomcat by apache.

the class ManagedBean method getMBeanInfo.

/**
 * Create and return a <code>ModelMBeanInfo</code> object that
 * describes this entire managed bean.
 * @return the MBean info
 */
MBeanInfo getMBeanInfo() {
    // Return our cached information (if any)
    mBeanInfoLock.readLock().lock();
    try {
        if (info != null) {
            return info;
        }
    } finally {
        mBeanInfoLock.readLock().unlock();
    }
    mBeanInfoLock.writeLock().lock();
    try {
        if (info == null) {
            // Create subordinate information descriptors as required
            AttributeInfo[] attrs = getAttributes();
            MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[attrs.length];
            for (int i = 0; i < attrs.length; i++) {
                attributes[i] = attrs[i].createAttributeInfo();
            }
            OperationInfo[] opers = getOperations();
            MBeanOperationInfo[] operations = new MBeanOperationInfo[opers.length];
            for (int i = 0; i < opers.length; i++) {
                operations[i] = opers[i].createOperationInfo();
            }
            NotificationInfo[] notifs = getNotifications();
            MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[notifs.length];
            for (int i = 0; i < notifs.length; i++) {
                notifications[i] = notifs[i].createNotificationInfo();
            }
            // Construct and return a new ModelMBeanInfo object
            info = new MBeanInfo(getClassName(), getDescription(), attributes, new MBeanConstructorInfo[] {}, operations, notifications);
        }
        return info;
    } finally {
        mBeanInfoLock.writeLock().unlock();
    }
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanConstructorInfo(javax.management.MBeanConstructorInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo)

Example 20 with MBeanConstructorInfo

use of javax.management.MBeanConstructorInfo in project openj9 by eclipse.

the class TestLoggingMXBean method testGetMBeanInfo.

@Test
public final void testGetMBeanInfo() {
    MBeanInfo mbi;
    try {
        mbi = mbs.getMBeanInfo(objName);
    } catch (InstanceNotFoundException e) {
        Assert.fail("Unexpected InstanceNotFoundException: " + e.getMessage());
        return;
    } catch (ReflectionException e) {
        Assert.fail("Unexpected ReflectionException: " + e.getMessage());
        return;
    } catch (IntrospectionException e) {
        Assert.fail("Unexpected IntrospectionException: " + e.getMessage());
        return;
    }
    AssertJUnit.assertNotNull(mbi);
    // Now make sure that what we got back is what we expected.
    // Class name
    AssertJUnit.assertEquals(lb.getClass().getName(), mbi.getClassName());
    // No public constructors
    MBeanConstructorInfo[] constructors = mbi.getConstructors();
    AssertJUnit.assertNotNull(constructors);
    AssertJUnit.assertEquals(0, constructors.length);
    // Three public operations
    MBeanOperationInfo[] operations = mbi.getOperations();
    AssertJUnit.assertNotNull(operations);
    AssertJUnit.assertEquals(3, operations.length);
    // No notifications
    MBeanNotificationInfo[] notifications = mbi.getNotifications();
    AssertJUnit.assertNotNull(notifications);
    AssertJUnit.assertEquals(0, notifications.length);
    // Print out the description here.
    logger.debug("MBean description for " + lb.getClass().getName() + ": " + mbi.getDescription());
    // One attribute - not writable.
    MBeanAttributeInfo[] attributes = mbi.getAttributes();
    AssertJUnit.assertNotNull(attributes);
    AssertJUnit.assertEquals(2, attributes.length);
    for (MBeanAttributeInfo attribute : attributes) {
        String attributeName = attribute.getName();
        String attributeType = attribute.getType();
        switch(attributeName) {
            case "LoggerNames":
                AssertJUnit.assertEquals(String[].class.getName(), attributeType);
                break;
            case "ObjectName":
                AssertJUnit.assertEquals(ObjectName.class.getName(), attributeType);
                break;
            default:
                Assert.fail("Unexpected attribute: " + attributeName + " of type " + attributeType);
                break;
        }
        AssertJUnit.assertTrue(attribute.isReadable());
        AssertJUnit.assertFalse(attribute.isWritable());
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) MBeanConstructorInfo(javax.management.MBeanConstructorInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) Test(org.testng.annotations.Test)

Aggregations

MBeanConstructorInfo (javax.management.MBeanConstructorInfo)25 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)21 MBeanInfo (javax.management.MBeanInfo)21 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)20 MBeanOperationInfo (javax.management.MBeanOperationInfo)20 InstanceNotFoundException (javax.management.InstanceNotFoundException)10 IntrospectionException (javax.management.IntrospectionException)10 ReflectionException (javax.management.ReflectionException)10 Test (org.testng.annotations.Test)10 MBeanParameterInfo (javax.management.MBeanParameterInfo)5 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)3 Constructor (java.lang.reflect.Constructor)2 MemoryManagerMXBean (java.lang.management.MemoryManagerMXBean)1 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Lock (java.util.concurrent.locks.Lock)1