Search in sources :

Example 1 with ManagedOperation

use of org.glassfish.admin.amx.annotation.ManagedOperation in project Payara by payara.

the class MBeanInfoSupport method findInterfaceMethods.

public static void findInterfaceMethods(final Class<?> intf, final Map<String, Method> getters, final Map<String, Method> setters, final Map<String, Method> getterSetters, final Set<Method> operations) {
    final Method[] methods = intf.getMethods();
    for (final Method method : methods) {
        final ManagedAttribute managedAttr = method.getAnnotation(ManagedAttribute.class);
        final ManagedOperation managedOp = method.getAnnotation(ManagedOperation.class);
        if (managedAttr != null) {
            String attrName = null;
            final int numArgs = method.getParameterTypes().length;
            if (managedOp != null) {
                AMXLoggerInfo.getLogger().log(Level.WARNING, AMXLoggerInfo.attributeCantBeOperation, new Object[] { intf.getName(), method.getName() });
            } else if (numArgs == 0 && JMXUtil.isIsOrGetter(method)) {
                attrName = JMXUtil.getAttributeName(method);
                getters.put(attrName, method);
            // debug( "findInterfaceMethods: getter: " + attrName );
            } else if (numArgs == 1 && JMXUtil.isSetter(method)) {
                attrName = JMXUtil.getAttributeName(method);
                setters.put(attrName, method);
            // debug( "findInterfaceMethods: setter: " + attrName );
            } else {
                AMXLoggerInfo.getLogger().log(Level.WARNING, AMXLoggerInfo.attributeNotGetterSetter, new Object[] { intf.getName(), method.getName() });
            // ignore
            }
            if ((attrName != null) && getters.containsKey(attrName) && setters.containsKey(attrName)) {
                final Method getter = getters.get(attrName);
                final Class<?> getterType = getter.getReturnType();
                final Class<?> setterType = setters.get(attrName).getParameterTypes()[0];
                if (getterType == setterType) {
                    getters.remove(attrName);
                    setters.remove(attrName);
                    getterSetters.put(attrName, getter);
                // debug( "findInterfaceMethods: getter/setter: " + attrName );
                } else {
                    throw new IllegalArgumentException("Attribute " + attrName + "has type " + getterType.getName() + " as getter but type " + setterType.getName() + " as setter");
                }
            }
        } else if (managedOp != null) {
            operations.add(method);
        }
    }
/*
        java.util.Iterator	iter	= null;
        trace( "-------------------- getterSetters -------------------" );
        iter	= getterSetters.values().iterator();
        while ( iter.hasNext() )
        {
        trace( ((Method)iter.next()).getNameProp() + ", " );
        }
        trace( "-------------------- getters -------------------" );
        iter	= getters.values().iterator();
        while ( iter.hasNext() )
        {
        trace( ((Method)iter.next()).getNameProp() + ", " );
        }
        trace( "-------------------- setters -------------------" );
        iter	= setters.values().iterator();
        while ( iter.hasNext() )
        {
        trace( ((Method)iter.next()).getNameProp() + ", " );
        }
         */
}
Also used : Method(java.lang.reflect.Method) ManagedAttribute(org.glassfish.admin.amx.annotation.ManagedAttribute) ManagedOperation(org.glassfish.admin.amx.annotation.ManagedOperation)

Example 2 with ManagedOperation

use of org.glassfish.admin.amx.annotation.ManagedOperation in project Payara by payara.

the class MBeanInfoSupport method generateMBeanOperationInfos.

public static MBeanOperationInfo[] generateMBeanOperationInfos(final Collection<Method> methods) {
    final MBeanOperationInfo[] infos = new MBeanOperationInfo[methods.size()];
    int i = 0;
    for (final Method m : methods) {
        final ManagedOperation managed = m.getAnnotation(ManagedOperation.class);
        final String methodName = m.getName();
        final MBeanParameterInfo[] parameterInfos = parameterInfos(m);
        final int impact = managed == null ? MBeanOperationInfo.UNKNOWN : managed.impact();
        final String description = getDescription(m);
        final MBeanOperationInfo info = new MBeanOperationInfo(methodName, description, parameterInfos, translatedType(m.getReturnType()).getName(), impact, null);
        infos[i] = info;
        ++i;
    }
    return (infos);
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) Method(java.lang.reflect.Method) ManagedOperation(org.glassfish.admin.amx.annotation.ManagedOperation) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Aggregations

Method (java.lang.reflect.Method)2 ManagedOperation (org.glassfish.admin.amx.annotation.ManagedOperation)2 MBeanOperationInfo (javax.management.MBeanOperationInfo)1 MBeanParameterInfo (javax.management.MBeanParameterInfo)1 ManagedAttribute (org.glassfish.admin.amx.annotation.ManagedAttribute)1