Search in sources :

Example 81 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 82 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 83 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo in project tomcat70 by apache.

the class JMXProxyServlet method invokeOperationInternal.

/**
 * Invokes an operation on an MBean.
 * @param onameStr The name of the MBean.
 * @param operation The name of the operation to invoke.
 * @param parameters An array of Strings containing the parameters to the
 *                   operation. They will be converted to the appropriate
 *                   types to call the requested operation.
 * @return The value returned by the requested operation.
 */
private Object invokeOperationInternal(String onameStr, String operation, String[] parameters) throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname = new ObjectName(onameStr);
    MBeanOperationInfo methodInfo = registry.getMethodInfo(oname, operation);
    MBeanParameterInfo[] signature = methodInfo.getSignature();
    String[] signatureTypes = new String[signature.length];
    Object[] values = new Object[signature.length];
    for (int i = 0; i < signature.length; i++) {
        MBeanParameterInfo pi = signature[i];
        signatureTypes[i] = pi.getType();
        values[i] = registry.convertValue(pi.getType(), parameters[i]);
    }
    return mBeanServer.invoke(oname, operation, values, signatureTypes);
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) ObjectName(javax.management.ObjectName) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 84 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo in project tomcat70 by apache.

the class OperationInfo method createOperationInfo.

/**
 * Create and return a <code>ModelMBeanOperationInfo</code> object that
 * corresponds to the attribute described by this instance.
 */
MBeanOperationInfo createOperationInfo() {
    // Return our cached information (if any)
    if (info == null) {
        // Create and return a new information object
        int impact = MBeanOperationInfo.UNKNOWN;
        if ("ACTION".equals(getImpact()))
            impact = MBeanOperationInfo.ACTION;
        else if ("ACTION_INFO".equals(getImpact()))
            impact = MBeanOperationInfo.ACTION_INFO;
        else if ("INFO".equals(getImpact()))
            impact = MBeanOperationInfo.INFO;
        info = new MBeanOperationInfo(getName(), getDescription(), getMBeanParameterInfo(), getReturnType(), impact);
    }
    return (MBeanOperationInfo) info;
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo)

Example 85 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo in project tomcat70 by apache.

the class Registry method getMethodInfo.

/**
 * Find the operation info for a method
 *
 * @param oname
 * @param opName
 * @return the operation info for the specified operation
 */
public MBeanOperationInfo getMethodInfo(ObjectName oname, String opName) {
    MBeanInfo info = null;
    try {
        info = server.getMBeanInfo(oname);
    } catch (Exception e) {
        log.info("Can't find metadata " + oname);
        return null;
    }
    MBeanOperationInfo[] attInfo = info.getOperations();
    for (int i = 0; i < attInfo.length; i++) {
        if (opName.equals(attInfo[i].getName())) {
            return attInfo[i];
        }
    }
    return null;
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Aggregations

MBeanOperationInfo (javax.management.MBeanOperationInfo)117 MBeanInfo (javax.management.MBeanInfo)76 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)59 MBeanParameterInfo (javax.management.MBeanParameterInfo)38 ObjectName (javax.management.ObjectName)33 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)23 ArrayList (java.util.ArrayList)22 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)20 InstanceNotFoundException (javax.management.InstanceNotFoundException)19 ReflectionException (javax.management.ReflectionException)17 Test (org.junit.Test)16 IntrospectionException (javax.management.IntrospectionException)13 MBeanServer (javax.management.MBeanServer)13 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 Test (org.testng.annotations.Test)9 Method (java.lang.reflect.Method)8 Attribute (javax.management.Attribute)8 Descriptor (javax.management.Descriptor)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)5