/** * Adds an operation to be exposed to the runtime management framework. * * @param info the operation information */ public void addOperation(ManagementOperationInfo info) { info.setParent(this); operations.add(info); }
Map<OperationKey, MethodHolder> operations = new HashMap<>(); for (ManagementOperationInfo operationInfo : info.getOperations()) { Method method = operationInfo.getMethod(); String description = operationInfo.getDescription(); Set<Role> roles = operationInfo.getRoles();
private void introspect(Object instance, ManagementInfo info) { for (Method method : instance.getClass().getMethods()) { ManagementOperation annotation = method.getAnnotation(ManagementOperation.class); if (annotation == null) { continue; } String description = annotation.description(); if (description.trim().length() == 0) { description = null; } String[] roleNames = annotation.rolesAllowed(); Set<Role> roles = new HashSet<>(); for (String name : roleNames) { roles.add(new Role(name)); } String path = annotation.path(); ManagementOperationInfo operationInfo = new ManagementOperationInfo(method, path, OperationType.UNDEFINED, description, roles); info.addOperation(operationInfo); } }
public void visitMethod(ManagementOperation annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { ManagementInfo info = componentType.getManagementInfo(); if (info == null) { // there was no management annotation on the type - record an error Class<?> clazz = method.getDeclaringClass(); String name = Management.class.getSimpleName(); context.addError(new InvalidAnnotation("Implementation is missing @" + name, method, annotation, clazz)); return; } String description = annotation.description(); if (description.trim().length() == 0) { description = null; } Set<Role> roles = new HashSet<>(); for (String roleName : annotation.rolesAllowed()) { roles.add(new Role(roleName)); } String path = annotation.path(); org.fabric3.api.annotation.management.OperationType operationType = annotation.type(); OperationType type = OperationType.valueOf(operationType.toString()); ManagementOperationInfo operationInfo = new ManagementOperationInfo(method, path, type, description, roles); info.addOperation(operationInfo); }