Search in sources :

Example 66 with Descriptor

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

the class MXBeanIntrospector method getMBeanOperationInfo.

@Override
MBeanOperationInfo getMBeanOperationInfo(String operationName, ConvertingMethod operation) {
    final Method method = operation.getMethod();
    final String description = operationName;
    /* Ideally this would be an empty string, but
           OMBOperationInfo constructor forbids that.  Also, we
           could consult an annotation to get a useful
           description.  */
    final int impact = MBeanOperationInfo.UNKNOWN;
    final OpenType<?> returnType = operation.getOpenReturnType();
    final Type originalReturnType = operation.getGenericReturnType();
    final OpenType<?>[] paramTypes = operation.getOpenParameterTypes();
    final Type[] originalParamTypes = operation.getGenericParameterTypes();
    final MBeanParameterInfo[] params = new MBeanParameterInfo[paramTypes.length];
    boolean openReturnType = canUseOpenInfo(originalReturnType);
    boolean openParameterTypes = true;
    Annotation[][] annots = method.getParameterAnnotations();
    for (int i = 0; i < paramTypes.length; i++) {
        final String paramName = "p" + i;
        final String paramDescription = paramName;
        final OpenType<?> openType = paramTypes[i];
        final Type originalType = originalParamTypes[i];
        Descriptor descriptor = typeDescriptor(openType, originalType);
        descriptor = ImmutableDescriptor.union(descriptor, Introspector.descriptorForAnnotations(annots[i]));
        final MBeanParameterInfo pi;
        if (canUseOpenInfo(originalType)) {
            pi = new OpenMBeanParameterInfoSupport(paramName, paramDescription, openType, descriptor);
        } else {
            openParameterTypes = false;
            pi = new MBeanParameterInfo(paramName, originalTypeString(originalType), paramDescription, descriptor);
        }
        params[i] = pi;
    }
    Descriptor descriptor = typeDescriptor(returnType, originalReturnType);
    descriptor = ImmutableDescriptor.union(descriptor, Introspector.descriptorForElement(method));
    final MBeanOperationInfo oi;
    if (openReturnType && openParameterTypes) {
        /* If the return value and all the parameters can be faithfully
             * represented as OpenType then we return an OpenMBeanOperationInfo.
             * If any of them is a primitive type, we can't.  Compatibility
             * with JSR 174 means that we must return an MBean*Info where
             * the getType() is the primitive type, not its wrapped type as
             * we would get with an OpenMBean*Info.  The OpenType is available
             * in the Descriptor in either case.
             */
        final OpenMBeanParameterInfo[] oparams = new OpenMBeanParameterInfo[params.length];
        System.arraycopy(params, 0, oparams, 0, params.length);
        oi = new OpenMBeanOperationInfoSupport(operationName, description, oparams, returnType, impact, descriptor);
    } else {
        oi = new MBeanOperationInfo(operationName, description, params, openReturnType ? returnType.getClassName() : originalTypeString(originalReturnType), impact, descriptor);
    }
    return oi;
}
Also used : OpenMBeanParameterInfo(javax.management.openmbean.OpenMBeanParameterInfo) OpenType(javax.management.openmbean.OpenType) MBeanOperationInfo(javax.management.MBeanOperationInfo) OpenMBeanParameterInfoSupport(javax.management.openmbean.OpenMBeanParameterInfoSupport) Method(java.lang.reflect.Method) GenericArrayType(java.lang.reflect.GenericArrayType) OpenType(javax.management.openmbean.OpenType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor) OpenMBeanOperationInfoSupport(javax.management.openmbean.OpenMBeanOperationInfoSupport) MBeanParameterInfo(javax.management.MBeanParameterInfo) OpenMBeanParameterInfo(javax.management.openmbean.OpenMBeanParameterInfo)

Example 67 with Descriptor

use of javax.management.Descriptor in project qi4j-sdk by Qi4j.

the class ModelMBeanBuilder method operation.

public ModelMBeanBuilder operation(String name, String description, String returnType, int impact, MBeanParameterInfo... parameters) {
    Descriptor stateDesc = new DescriptorSupport();
    stateDesc.setField("name", name);
    stateDesc.setField("descriptorType", "operation");
    stateDesc.setField("class", className);
    stateDesc.setField("role", "operation");
    stateDesc.setField("targetType", "objectReference");
    ModelMBeanOperationInfo operationInfo = new ModelMBeanOperationInfo(name, description, parameters, returnType, impact, stateDesc);
    operations.add(operationInfo);
    return this;
}
Also used : Descriptor(javax.management.Descriptor)

Example 68 with Descriptor

use of javax.management.Descriptor in project qi4j-sdk by Qi4j.

the class ModelMBeanBuilder method newModelMBean.

public RequiredModelMBean newModelMBean() throws MBeanException {
    Descriptor mmbDesc = new DescriptorSupport();
    mmbDesc.setField("name", objectName.toString());
    mmbDesc.setField("descriptorType", "mbean");
    mmbDesc.setField("displayName", displayName);
    ModelMBeanInfo modelMBeanInfo = new ModelMBeanInfoSupport(className, displayName, attributes.toArray(new ModelMBeanAttributeInfo[attributes.size()]), constructors.toArray(new ModelMBeanConstructorInfo[constructors.size()]), operations.toArray(new ModelMBeanOperationInfo[operations.size()]), notifications.toArray(new ModelMBeanNotificationInfo[notifications.size()]));
    modelMBeanInfo.setMBeanDescriptor(mmbDesc);
    return new RequiredModelMBean(modelMBeanInfo);
}
Also used : Descriptor(javax.management.Descriptor)

Example 69 with Descriptor

use of javax.management.Descriptor in project cxf by apache.

the class ModelMBeanAssembler method addAttributeOperation.

void addAttributeOperation(Method method) {
    Descriptor operationDescriptor = supporter.buildAttributeOperationDescriptor(method.getName());
    Class<?>[] types = method.getParameterTypes();
    String[] paramTypes = new String[types.length];
    String[] paramNames = new String[types.length];
    String[] paramDescs = new String[types.length];
    for (int j = 0; j < types.length; j++) {
        paramTypes[j] = types[j].getName();
        paramDescs[j] = "";
        paramNames[j] = types[j].getName();
    }
    supporter.addModelMBeanMethod(method.getName(), paramTypes, paramNames, paramDescs, "", method.getReturnType().getName(), operationDescriptor);
}
Also used : Descriptor(javax.management.Descriptor)

Example 70 with Descriptor

use of javax.management.Descriptor in project cxf by apache.

the class ModelMBeanInfoSupporter method buildMBeanDescriptor.

public Descriptor buildMBeanDescriptor(ManagedResource mr) {
    Descriptor desc = new DescriptorSupport();
    if (mr.componentName() != null) {
        desc.setField("name", mr.componentName());
    }
    desc.setField("descriptorType", "mbean");
    if (mr.description() != null) {
        desc.setField("displayName", mr.description());
    }
    if (mr.persistLocation() != null) {
        desc.setField("persistLocation", mr.persistLocation());
    }
    if (mr.persistName() != null) {
        desc.setField("persistName", mr.persistName());
    }
    if (mr.log()) {
        desc.setField("log", "true");
    } else {
        desc.setField("log", "false");
    }
    if (mr.persistPolicy() != null) {
        desc.setField("persistPolicy", mr.persistPolicy());
    }
    if (mr.persistPeriod() >= -1) {
        desc.setField("persistPeriod", mr.persistPeriod());
    }
    if (mr.logFile() != null) {
        desc.setField("logFile", mr.logFile());
    }
    if (mr.currencyTimeLimit() >= -1) {
        desc.setField("currencyTimeLimit", mr.currencyTimeLimit());
    }
    return desc;
}
Also used : Descriptor(javax.management.Descriptor) DescriptorSupport(javax.management.modelmbean.DescriptorSupport)

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