Search in sources :

Example 61 with MBeanOperationInfo

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

the class AMXTest method checkReturnTypes.

/**
 *     Verify:
 *     <ul>
 *     <li>that all return types are suitable for the API</li>
 *     </ul>
 */
public void checkReturnTypes(final ObjectName objectName) throws Exception {
    final AMX proxy = getProxyFactory().getProxy(objectName, AMX.class);
    final MBeanInfo info = Util.getExtra(proxy).getMBeanInfo();
    final MBeanOperationInfo[] operations = info.getOperations();
    boolean emittedName = false;
    for (int i = 0; i < operations.length; ++i) {
        final MBeanOperationInfo opInfo = operations[i];
        final String returnType = opInfo.getReturnType();
        if (!isSuitableReturnTypeForAPI(returnType)) {
            if (!emittedName) {
                emittedName = true;
                trace("\n" + objectName);
            }
            trace("WARNING: unsuitable return type in API: " + returnType + " " + opInfo.getName() + "(...)");
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) AMX(com.sun.appserv.management.base.AMX)

Example 62 with MBeanOperationInfo

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

the class AMXTest method checkCreateRemoveGet.

/**
 *     Verify:
 *     <ul>
 *     <li>each create() or createAbc() method ends in "Config" if it returns an AMXConfig subclass</li>
 *     <li>each remove() or removeAbc() method ends in "Config"</li>
 *     </ul>
 */
public void checkCreateRemoveGet(final ObjectName objectName) throws Exception {
    final AMX proxy = getProxyFactory().getProxy(objectName, AMX.class);
    if (proxy instanceof Container) {
        final Method[] methods = getInterfaceClass(proxy).getMethods();
        final MBeanInfo mbeanInfo = Util.getExtra(proxy).getMBeanInfo();
        final MBeanOperationInfo[] operations = mbeanInfo.getOperations();
        for (int methodIdx = 0; methodIdx < methods.length; ++methodIdx) {
            final Method method = methods[methodIdx];
            final String methodName = method.getName();
            if (methodName.startsWith("create") && !methodName.endsWith("Config")) {
                if (AMXConfig.class.isAssignableFrom(method.getReturnType()) && (!(proxy instanceof SecurityMapConfig))) {
                    trace("WARNING: method " + methodName + " does not end in 'Config': " + objectName);
                }
            } else if (methodName.startsWith("remove") && !methodName.endsWith("Config") && proxy instanceof AMXConfig) {
                if (// method.getReturnType() == Void.class &&
                method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == String.class && !method.getName().equals("removeProperty") && !method.getName().equals("removeSystemProperty") && (!(proxy instanceof SecurityMapConfig))) {
                    trace("WARNING: method " + methodName + " does not end in 'Config': " + methodName);
                }
            }
        }
    }
}
Also used : Container(com.sun.appserv.management.base.Container) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) SecurityMapConfig(com.sun.appserv.management.config.SecurityMapConfig) Method(java.lang.reflect.Method) AMX(com.sun.appserv.management.base.AMX) AMXConfig(com.sun.appserv.management.config.AMXConfig)

Example 63 with MBeanOperationInfo

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

the class AMXTest method checkCompatibleOperationExists.

/**
 *     Verify that the proxy method has a compatible Attribute or operation.
 *     <ul>
 *     <li>a proxy getter must have a corresponding Attribute returning an ObjectName</li>
 *     <li>a proxy operation must have a corresponding operation with matching signature</li>
 *     <li>a proxy operation must have a corresponding operation with compatible return type</li>
 *     </u
 */
private void checkCompatibleOperationExists(final ObjectName objectName, final Method proxyMethod, final String mbeanMethodName, final MBeanInfo mbeanInfo) {
    final Class proxyReturnType = proxyMethod.getReturnType();
    final String proxyMethodName = proxyMethod.getName();
    String mbeanReturnType = null;
    final Class[] parameterTypes = proxyMethod.getParameterTypes();
    if (JMXUtil.isGetter(proxyMethod)) {
        // it's getter
        final Map<String, MBeanAttributeInfo> m = JMXUtil.attributeInfosToMap(mbeanInfo.getAttributes());
        final String attrName = StringUtil.stripPrefix(mbeanMethodName, JMXUtil.GET);
        final MBeanAttributeInfo attrInfo = (MBeanAttributeInfo) m.get(attrName);
        if (attrInfo != null) {
            mbeanReturnType = attrInfo.getType();
        }
    } else {
        // look for an operation that matches
        final MBeanOperationInfo[] operations = mbeanInfo.getOperations();
        final String[] stringSig = ClassUtil.classnamesFromSignature(parameterTypes);
        final MBeanOperationInfo opInfo = JMXUtil.findOperation(operations, mbeanMethodName, stringSig);
        if (opInfo != null) {
            mbeanReturnType = opInfo.getReturnType();
        }
    }
    boolean hasPeer = mbeanReturnType != null;
    if (hasPeer) {
        // a proxy return type of AMX should have an Attribute type of ObjectName
        if (AMX.class.isAssignableFrom(proxyReturnType)) {
            assert (mbeanReturnType.equals(ObjectName.class.getName()));
        } else // return types must match
        {
            assert (mbeanReturnType.equals(proxyReturnType.getName()));
        }
        hasPeer = true;
    }
    if (!hasPeer) {
        trace("MBean " + objectName + " has operation " + proxyMethodName + " without corresponding peer Attribute/operation " + mbeanMethodName);
    }
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 64 with MBeanOperationInfo

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

the class AMXTest method checkMapsHaveCreateRemove.

/**
 *     Verify that all getAbcConfigMgr() calls return a non-null result.
 */
public void checkMapsHaveCreateRemove(final ObjectName objectName) throws Exception {
    final AMX proxy = getProxyFactory().getProxy(objectName, AMX.class);
    if (proxy instanceof Container && proxy.getGroup().equals(AMX.GROUP_CONFIGURATION)) {
        final Extra extra = Util.getExtra(proxy);
        final String[] attrNames = extra.getAttributeNames();
        for (int i = 0; i < attrNames.length; ++i) {
            final String name = attrNames[i];
            final String SUFFIX = "ObjectNameMap";
            final String PREFIX = JMXUtil.GET;
            if (name.endsWith(SUFFIX)) {
                final String base = StringUtil.stripPrefixAndSuffix(name, PREFIX, SUFFIX);
                if (base.endsWith("ConnectorModuleConfig")) {
                    // these are created via deployment not directly
                    continue;
                }
                final String createName = "create" + base;
                final String removeName = "remove" + base;
                final String j2eeType = proxy.getJ2EEType();
                if (ignoreCreateRemove(proxy.getJ2EEType(), createName)) {
                    continue;
                }
                final MBeanOperationInfo[] creates = JMXUtil.findOperations(extra.getMBeanInfo().getOperations(), createName);
                boolean haveCreate = false;
                for (int op = 0; op < creates.length; ++op) {
                    final MBeanOperationInfo info = creates[op];
                    if (info.getReturnType().equals(ObjectName.class.getName())) {
                        haveCreate = true;
                        break;
                    }
                }
                assert (haveCreate) : "Missing operation " + createName + "() for " + objectName;
                final MBeanOperationInfo[] removes = JMXUtil.findOperations(extra.getMBeanInfo().getOperations(), removeName);
                boolean haveRemove = false;
                for (int op = 0; op < removes.length; ++op) {
                    final MBeanOperationInfo info = removes[op];
                    if (info.getReturnType().equals("void") && info.getSignature().length <= 2) {
                        haveRemove = true;
                        break;
                    }
                }
                assert (haveRemove) : "Missing operation " + removeName + "() for " + objectName;
            }
        }
    }
}
Also used : Container(com.sun.appserv.management.base.Container) Extra(com.sun.appserv.management.base.Extra) MBeanOperationInfo(javax.management.MBeanOperationInfo) AMX(com.sun.appserv.management.base.AMX) ObjectName(javax.management.ObjectName)

Example 65 with MBeanOperationInfo

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

the class ConfigBeanJMXSupport method duckTypedToMBeanOperationInfo.

/**
 *    DuckTyped methods are <em>always</em> exposed as operations, never as Attributes.
 */
public MBeanOperationInfo duckTypedToMBeanOperationInfo(final DuckTypedInfo info) {
    final Descriptor descriptor = descriptor(info.duckTyped());
    final String name = info.name();
    final Class<?> type = remoteType(info.returnType());
    final String description = "@DuckTyped " + name + " of " + mIntf.getName();
    // how to tell?
    final int impact = MBeanOperationInfo.UNKNOWN;
    final List<MBeanParameterInfo> paramInfos = new ArrayList<MBeanParameterInfo>();
    int i = 0;
    for (final Class<?> paramClass : info.signature()) {
        final String paramName = "p" + i;
        final String paramType = remoteType(paramClass).getName();
        final String paramDescription = "parameter " + i;
        final MBeanParameterInfo paramInfo = new MBeanParameterInfo(paramName, paramType, paramDescription, null);
        paramInfos.add(paramInfo);
        ++i;
    }
    final MBeanParameterInfo[] paramInfosArray = CollectionUtil.toArray(paramInfos, MBeanParameterInfo.class);
    final MBeanOperationInfo opInfo = new MBeanOperationInfo(name, description, paramInfosArray, type.getName(), impact, descriptor);
    return opInfo;
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) Descriptor(javax.management.Descriptor) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Aggregations

MBeanOperationInfo (javax.management.MBeanOperationInfo)68 MBeanInfo (javax.management.MBeanInfo)39 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)35 MBeanParameterInfo (javax.management.MBeanParameterInfo)25 ObjectName (javax.management.ObjectName)20 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)9 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)8 MBeanServer (javax.management.MBeanServer)8 Method (java.lang.reflect.Method)7 Descriptor (javax.management.Descriptor)7 Attribute (javax.management.Attribute)5 ReflectionException (javax.management.ReflectionException)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)4 AMX (com.sun.appserv.management.base.AMX)3 IOException (java.io.IOException)3 TreeMap (java.util.TreeMap)3 IntrospectionException (javax.management.IntrospectionException)3 MBeanServerConnection (javax.management.MBeanServerConnection)3