Search in sources :

Example 46 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project spf4j by zolyfarkas.

the class ExportedValuesMBean method createBeanInfo.

private MBeanInfo createBeanInfo() {
    MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[exportedValues.size()];
    int i = 0;
    for (ExportedValue<?> val : exportedValues.values()) {
        attrs[i++] = createAttributeInfo(val);
    }
    MBeanOperationInfo[] operations = new MBeanOperationInfo[exportedOperations.size()];
    i = 0;
    for (ExportedOperation op : exportedOperations.values()) {
        MBeanParameterInfo[] paramInfos = op.getParameterInfos();
        String description = op.getDescription();
        if (description == null || description.isEmpty()) {
            description = op.getName();
        }
        OpenType<?> openType = op.getReturnOpenType();
        operations[i++] = new MBeanOperationInfo(op.getName(), description, paramInfos, op.getReturnType().getName(), 0, openType == null ? null : new ImmutableDescriptor(new String[] { "openType", "originalType" }, new Object[] { openType, op.getReturnType().getName() }));
    }
    return new MBeanInfo(objectName.toString(), "spf4j exported", attrs, null, operations, null);
}
Also used : ImmutableDescriptor(javax.management.ImmutableDescriptor) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 47 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project neo4j-documentation by neo4j.

the class JmxBeanDocumenter method operationRow.

private void operationRow(PrintStream out, MBeanOperationInfo operInfo, boolean nonHtml) {
    String type = getType(operInfo.getReturnType());
    Descriptor descriptor = operInfo.getDescriptor();
    type = getCompositeType(type, descriptor, nonHtml);
    out.printf("|%s|%s|%s|", operInfo.getName(), operInfo.getDescription().replace('\n', ' '), type);
    MBeanParameterInfo[] params = operInfo.getSignature();
    if (params.length > 0) {
        for (int i = 0; i < params.length; i++) {
            MBeanParameterInfo param = params[i];
            out.print(param.getType());
            if (i != (params.length - 1)) {
                out.print(",");
            }
        }
    } else {
        out.print("(no parameters)");
    }
    out.println();
}
Also used : Descriptor(javax.management.Descriptor) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 48 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project spring-framework by spring-projects.

the class AbstractMetadataAssemblerTests method testOperationParameterMetadata.

@Test
public void testOperationParameterMetadata() throws Exception {
    ModelMBeanInfo info = getMBeanInfoFromAssembler();
    ModelMBeanOperationInfo oper = info.getOperation("add");
    MBeanParameterInfo[] params = oper.getSignature();
    assertThat(params.length).as("Invalid number of params").isEqualTo(2);
    assertThat(params[0].getName()).as("Incorrect name for x param").isEqualTo("x");
    assertThat(params[0].getType()).as("Incorrect type for x param").isEqualTo(int.class.getName());
    assertThat(params[1].getName()).as("Incorrect name for y param").isEqualTo("y");
    assertThat(params[1].getType()).as("Incorrect type for y param").isEqualTo(int.class.getName());
}
Also used : ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo) Test(org.junit.jupiter.api.Test)

Example 49 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project spring-framework by spring-projects.

the class MetadataMBeanInfoAssembler method getOperationParameters.

/**
 * Reads {@code MBeanParameterInfo} from the {@code ManagedOperationParameter}
 * attributes attached to a method. Returns an empty array of {@code MBeanParameterInfo}
 * if no attributes are found.
 */
@Override
protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) {
    ManagedOperationParameter[] params = obtainAttributeSource().getManagedOperationParameters(method);
    if (ObjectUtils.isEmpty(params)) {
        return super.getOperationParameters(method, beanKey);
    }
    MBeanParameterInfo[] parameterInfo = new MBeanParameterInfo[params.length];
    Class<?>[] methodParameters = method.getParameterTypes();
    for (int i = 0; i < params.length; i++) {
        ManagedOperationParameter param = params[i];
        parameterInfo[i] = new MBeanParameterInfo(param.getName(), methodParameters[i].getName(), param.getDescription());
    }
    return parameterInfo;
}
Also used : ManagedOperationParameter(org.springframework.jmx.export.metadata.ManagedOperationParameter) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 50 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project tomcat 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.
 */
// parameters can't be null if signature.length > 0
@SuppressWarnings("null")
private Object invokeOperationInternal(String onameStr, String operation, String[] parameters) throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname = new ObjectName(onameStr);
    int paramCount = null == parameters ? 0 : parameters.length;
    MBeanOperationInfo methodInfo = registry.getMethodInfo(oname, operation, paramCount);
    if (null == methodInfo) {
        // getMethodInfo returns null for both "object not found" and "operation not found"
        MBeanInfo info = null;
        try {
            info = registry.getMBeanServer().getMBeanInfo(oname);
        } catch (InstanceNotFoundException infe) {
            throw infe;
        } catch (Exception e) {
            throw new IllegalArgumentException(sm.getString("jmxProxyServlet.noBeanFound", onameStr), e);
        }
        throw new IllegalArgumentException(sm.getString("jmxProxyServlet.noOperationOnBean", operation, Integer.valueOf(paramCount), onameStr, info.getClassName()));
    }
    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 : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) OperationsException(javax.management.OperationsException) IOException(java.io.IOException) ServletException(jakarta.servlet.ServletException) MBeanException(javax.management.MBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) ObjectName(javax.management.ObjectName) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Aggregations

MBeanParameterInfo (javax.management.MBeanParameterInfo)59 MBeanOperationInfo (javax.management.MBeanOperationInfo)36 MBeanInfo (javax.management.MBeanInfo)19 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)15 ObjectName (javax.management.ObjectName)10 ArrayList (java.util.ArrayList)9 Descriptor (javax.management.Descriptor)8 Method (java.lang.reflect.Method)5 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)5 Annotation (java.lang.annotation.Annotation)4 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 TreeMap (java.util.TreeMap)3 Attribute (javax.management.Attribute)3 ImmutableDescriptor (javax.management.ImmutableDescriptor)3 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)3 ReflectionException (javax.management.ReflectionException)3 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)3 Constructor (java.lang.reflect.Constructor)2