/** * Creates an instance of {@code ModelMBeanOperationInfo} for the * given method. Populates the parameter info for the operation. * @param method the {@code Method} to create a {@code ModelMBeanOperationInfo} for * @param name the logical name for the operation (method name or property name); * not used by the default implementation but possibly by subclasses * @param beanKey the key associated with the MBean in the beans map * of the {@code MBeanExporter} * @return the {@code ModelMBeanOperationInfo} */ protected ModelMBeanOperationInfo createModelMBeanOperationInfo(Method method, String name, String beanKey) { MBeanParameterInfo[] params = getOperationParameters(method, beanKey); if (params.length == 0) { return new ModelMBeanOperationInfo(getOperationDescription(method, beanKey), method); } else { return new ModelMBeanOperationInfo(method.getName(), getOperationDescription(method, beanKey), getOperationParameters(method, beanKey), method.getReturnType().getName(), MBeanOperationInfo.UNKNOWN); } }
visibility = 4; ModelMBeanOperationInfo info = new ModelMBeanOperationInfo(m.getName(), description, extractParameterInfo(m), m.getReturnType() .getName(), impact); info.getDescriptor().setField("visibility", Integer.toString(visibility)); infos.add(info);
Descriptor desc = info.getDescriptor(); if (method.equals(pd.getReadMethod())) { desc.setField(FIELD_ROLE, ROLE_GETTER); desc.setField(FIELD_CLASS, getClassForDescriptor(managedBean).getName()); info.setDescriptor(desc); Descriptor desc = info.getDescriptor(); desc.setField(FIELD_ROLE, ROLE_OPERATION); if (isExposeClassDescriptor()) { info.setDescriptor(desc);
Descriptor operationDescriptor = operInfo.getDescriptor(); if (operationDescriptor == null) throw new MBeanException(new ServiceNotFoundException( Class declared = loadClassWithContextClassLoader(operInfo.getReturnType()); Class declared = loadClassWithContextClassLoader(operInfo.getReturnType()); int impact = operInfo.getImpact(); if (persistNow && impact != MBeanOperationInfo.INFO) { if (logger.isEnabledFor(Logger.TRACE))
impact = ModelMBeanOperationInfo.INFO; info = new ModelMBeanOperationInfo (getName(), getDescription(), parameters, getReturnType(), impact); Descriptor descriptor = info.getDescriptor(); descriptor.removeField("class"); descriptor.setField("role", getRole()); addFields(descriptor); info.setDescriptor(descriptor); return (info);
protected void doCollectOperations(Class<?> clazz, BeanInfo beanInfo) { for (MethodDescriptor methodInfo : beanInfo.getMethodDescriptors()) { if (methodInfo.isHidden()) { continue; } Descriptor descriptor = doGetDescriptor(methodInfo, "operation"); String name = methodInfo.getName(); Method method = methodInfo.getMethod(); ParameterDescriptor[] parameters = methodInfo.getParameterDescriptors(); boolean hasParameters = parameters != null && parameters.length > 0; Class<?> returnType = method.getReturnType(); boolean returnValue = returnType != null && !void.class.equals(returnType); if ((name.startsWith("get") && hasParameters && returnValue) || (name.startsWith("is") && !hasParameters && boolean.class.equals(returnType))) { descriptor.setField("role", "getter"); } else if (methodInfo.getName().startsWith("set") && void.class.equals(returnType) && hasParameters && parameters.length == 1) { // doFixAttribute(clazz, methodInfo.getName()); descriptor.setField("role", "setter"); } else { descriptor.setField("role", "operation"); } ModelMBeanOperationInfo operationInfo = new ModelMBeanOperationInfo(methodInfo.getShortDescription(), methodInfo.getMethod(), descriptor); operationsInfo.put(operationInfo.getName(), operationInfo); } }
@Test public void testAttributeHasCorrespondingOperations() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanOperationInfo get = info.getOperation("getName"); assertNotNull("get operation should not be null", get); assertEquals("get operation should have visibility of four", get.getDescriptor().getFieldValue("visibility"), new Integer(4)); assertEquals("get operation should have role \"getter\"", "getter", get.getDescriptor().getFieldValue("role")); ModelMBeanOperationInfo set = info.getOperation("setName"); assertNotNull("set operation should not be null", set); assertEquals("set operation should have visibility of four", set.getDescriptor().getFieldValue("visibility"), new Integer(4)); assertEquals("set operation should have role \"setter\"", "setter", set.getDescriptor().getFieldValue("role")); }
MBeanParameterInfo[] pInfo = opInfo.getSignature(); String method=opInfo.getName()+"("; for (int i=0;i<pInfo.length;i++) _method.put(method,oClass.getMethod(opInfo.getName(),types)); _operations.add(opInfo);
@Override public String toString() { return getMetadata().getName(); }
Descriptor operationDescriptor = operInfo.getDescriptor(); if (operationDescriptor == null) throw new MBeanException(new ServiceNotFoundException(LocalizedStrings.MX4JModelMBean_OPERATION_DESCRIPTOR_FOR_OPERATION_0_CANNOT_BE_NULL.toLocalizedString(method))); String role = (String)operationDescriptor.getFieldValue("role"); Class declared = loadClassWithContextClassLoader(operInfo.getReturnType()); Class declared = loadClassWithContextClassLoader(operInfo.getReturnType()); int impact = operInfo.getImpact(); if (persistNow && impact != MBeanOperationInfo.INFO)
@Test public void testOperationDescriptor() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); Descriptor desc = info.getOperation("myOperation").getDescriptor(); assertEquals("Currency Time Limit should be 30", "30", desc.getFieldValue("currencyTimeLimit")); assertEquals("Role should be \"operation\"", "operation", desc.getFieldValue("role")); }
MBeanParameterInfo[] pInfo = opInfo.getSignature(); String method=opInfo.getName()+"("; for (int i=0;i<pInfo.length;i++) _method.put(method,oClass.getMethod(opInfo.getName(),types)); _operations.add(opInfo);
/** * Creates an instance of {@code ModelMBeanOperationInfo} for the * given method. Populates the parameter info for the operation. * @param method the {@code Method} to create a {@code ModelMBeanOperationInfo} for * @param name the logical name for the operation (method name or property name); * not used by the default implementation but possibly by subclasses * @param beanKey the key associated with the MBean in the beans map * of the {@code MBeanExporter} * @return the {@code ModelMBeanOperationInfo} */ protected ModelMBeanOperationInfo createModelMBeanOperationInfo(Method method, String name, String beanKey) { MBeanParameterInfo[] params = getOperationParameters(method, beanKey); if (params.length == 0) { return new ModelMBeanOperationInfo(getOperationDescription(method, beanKey), method); } else { return new ModelMBeanOperationInfo(method.getName(), getOperationDescription(method, beanKey), getOperationParameters(method, beanKey), method.getReturnType().getName(), MBeanOperationInfo.UNKNOWN); } }
visibility = 4; ModelMBeanOperationInfo info = new ModelMBeanOperationInfo(m.getName(), description, extractParameterInfo(m), m.getReturnType() .getName(), impact); info.getDescriptor().setField("visibility", Integer.toString(visibility)); infos.add(info);
Descriptor desc = info.getDescriptor(); if (method.equals(pd.getReadMethod())) { desc.setField(FIELD_ROLE, ROLE_GETTER); desc.setField(FIELD_CLASS, getClassForDescriptor(managedBean).getName()); info.setDescriptor(desc); Descriptor desc = info.getDescriptor(); desc.setField(FIELD_ROLE, ROLE_OPERATION); if (isExposeClassDescriptor()) { info.setDescriptor(desc);
Descriptor operationDescriptor = operInfo.getDescriptor(); if (operationDescriptor == null) throw new MBeanException(new ServiceNotFoundException(LocalizedStrings.MX4JModelMBean_OPERATION_DESCRIPTOR_FOR_OPERATION_0_CANNOT_BE_NULL.toLocalizedString(method))); String role = (String)operationDescriptor.getFieldValue("role"); Class declared = loadClassWithContextClassLoader(operInfo.getReturnType()); Class declared = loadClassWithContextClassLoader(operInfo.getReturnType()); int impact = operInfo.getImpact(); if (persistNow && impact != MBeanOperationInfo.INFO)
protected void initOperationContexts(MBeanOperationInfo[] operations) { // make sure we invoke the super class initialization sequence first super.initOperationContexts(operations); for (int i = 0; i < operations.length; ++i) { OperationKey key = new OperationKey(operations[i]); InvocationContext ctx = (InvocationContext) operationContextMap.get(key); ModelMBeanOperationInfo info = (ModelMBeanOperationInfo) operations[i]; ctx.setDescriptor(info.getDescriptor()); } }
private ModelMBeanOperationInfo getMBeanOperation(JmxOperation operation) { String name = operation.getName(); String description = operation.getDescription(); MBeanParameterInfo[] signature = getSignature(operation.getParameters()); String type = getType(operation.getOutputType()); int impact = getImpact(operation.getType()); return new ModelMBeanOperationInfo(name, description, signature, type, impact); }
protected JmxOperation buildOperation(Class<?> managedClass, Method operation) { MBeanOperation jmxOperation = new MBeanOperation( operation, getOperationExportName(managedClass, operation), getOperationDescription(managedClass, operation), getOperationParameters(managedClass, operation)); Descriptor desc = jmxOperation.getMetadata().getDescriptor(); populateOperationDescriptor(managedClass, operation, desc); jmxOperation.getMetadata().setDescriptor(desc); return jmxOperation; }
protected void initOperationContexts(MBeanOperationInfo[] operations) { // make sure we invoke the super class initialization sequence first super.initOperationContexts(operations); for (int i = 0; i < operations.length; ++i) { OperationKey key = new OperationKey(operations[i]); InvocationContext ctx = (InvocationContext) operationContextMap.get(key); ModelMBeanOperationInfo info = (ModelMBeanOperationInfo) operations[i]; ctx.setDescriptor(info.getDescriptor()); } }