use of org.glassfish.admin.amx.annotation.ManagedAttribute 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() + ", " );
}
*/
}
use of org.glassfish.admin.amx.annotation.ManagedAttribute in project Payara by payara.
the class MBeanInfoSupport method attributeInfo.
/**
* Return MBeanAttributeInfo for the method. If it's a getter,
* it's marked as read-only, if it's a setter, it's marked as read/write.
* @param m
* @return
*/
public static MBeanAttributeInfo attributeInfo(final Method m) {
final ManagedAttribute managed = m.getAnnotation(ManagedAttribute.class);
if (managed == null) {
return null;
}
final Description d = m.getAnnotation(Description.class);
final String description = d == null ? "" : d.value();
String attrName = JMXUtil.getAttributeName(m);
final boolean isGetter = JMXUtil.isGetter(m);
final boolean isSetter = JMXUtil.isSetter(m);
final boolean isIs = JMXUtil.isIs(m);
final MBeanAttributeInfo info = new MBeanAttributeInfo(attrName, m.getReturnType().getName(), description, isGetter, isSetter, isIs, null);
return info;
}
Aggregations