use of org.eclipse.jetty.util.annotation.Name in project jetty.project by eclipse.
the class ObjectMBean method defineOperation.
/* ------------------------------------------------------------ */
/**
* TODO update to new behavior
*
* Define an operation on the managed object. Defines an operation with parameters. Refection is
* used to determine find the method and it's return type. The description of the method is
* found with a call to findDescription on "name(signature)". The name and description of each
* parameter is found with a call to findDescription with "name(signature)[n]", the returned
* description is for the last parameter of the partial signature and is assumed to start with
* the parameter name, followed by a colon.
*
* @param metaData "description" or "impact:description" or "type:impact:description", type is
* the "Object","MBean", "MMBean" or "MObject" to indicate the method is on the object, the MBean or on the
* object but converted to an MBean reference, and impact is either "ACTION","INFO","ACTION_INFO" or "UNKNOWN".
*/
private MBeanOperationInfo defineOperation(Method method, ManagedOperation methodAnnotation) {
String description = methodAnnotation.value();
boolean onMBean = methodAnnotation.proxied();
boolean convert = false;
// determine if we should convert
Class<?> returnType = method.getReturnType();
if (returnType.isArray()) {
if (LOG.isDebugEnabled())
LOG.debug("returnType is array, get component type");
returnType = returnType.getComponentType();
}
if (returnType.isAnnotationPresent(ManagedObject.class)) {
convert = true;
}
String impactName = methodAnnotation.impact();
if (LOG.isDebugEnabled())
LOG.debug("defineOperation {} {}:{}:{}", method.getName(), onMBean, impactName, description);
String signature = method.getName();
try {
// Resolve the impact
int impact = MBeanOperationInfo.UNKNOWN;
if (impactName == null || impactName.equals("UNKNOWN"))
impact = MBeanOperationInfo.UNKNOWN;
else if (impactName.equals("ACTION"))
impact = MBeanOperationInfo.ACTION;
else if (impactName.equals("INFO"))
impact = MBeanOperationInfo.INFO;
else if (impactName.equals("ACTION_INFO"))
impact = MBeanOperationInfo.ACTION_INFO;
else
LOG.warn("Unknown impact '" + impactName + "' for " + signature);
Annotation[][] allParameterAnnotations = method.getParameterAnnotations();
Class<?>[] methodTypes = method.getParameterTypes();
MBeanParameterInfo[] pInfo = new MBeanParameterInfo[allParameterAnnotations.length];
for (int i = 0; i < allParameterAnnotations.length; ++i) {
Annotation[] parameterAnnotations = allParameterAnnotations[i];
for (Annotation anno : parameterAnnotations) {
if (anno instanceof Name) {
Name nameAnnotation = (Name) anno;
pInfo[i] = new MBeanParameterInfo(nameAnnotation.value(), methodTypes[i].getName(), nameAnnotation.description());
}
}
}
signature += "(";
for (int i = 0; i < methodTypes.length; ++i) {
signature += methodTypes[i].getName();
if (i != methodTypes.length - 1) {
signature += ",";
}
}
signature += ")";
Class<?> returnClass = method.getReturnType();
if (LOG.isDebugEnabled())
LOG.debug("Method Cache: " + signature);
if (_methods.containsKey(signature)) {
// we have an operation for this already
return null;
}
_methods.put(signature, method);
if (convert)
_convert.add(signature);
return new MBeanOperationInfo(method.getName(), description, pInfo, returnClass.isPrimitive() ? TypeUtil.toName(returnClass) : (returnClass.getName()), impact);
} catch (Exception e) {
LOG.warn("Operation '" + signature + "'", e);
throw new IllegalArgumentException(e.toString());
}
}
Aggregations