[SPR-5859] @ManagedOperation can now be used on getters/setters
This commit is contained in:
parent
2a0d68cb5c
commit
aa08c11976
|
|
@ -87,11 +87,6 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException {
|
public ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException {
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
|
|
||||||
if (pd != null) {
|
|
||||||
throw new InvalidMetadataException(
|
|
||||||
"The ManagedOperation attribute is not valid for JavaBean properties. Use ManagedAttribute instead.");
|
|
||||||
}
|
|
||||||
Annotation ann = AnnotationUtils.findAnnotation(method, org.springframework.jmx.export.annotation.ManagedOperation.class);
|
Annotation ann = AnnotationUtils.findAnnotation(method, org.springframework.jmx.export.annotation.ManagedOperation.class);
|
||||||
if (ann == null) {
|
if (ann == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -355,7 +355,9 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean
|
||||||
info.setDescriptor(desc);
|
info.setDescriptor(desc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (includeOperation(method, beanKey)) {
|
|
||||||
|
// allow getters and setters to be marked as operations directly
|
||||||
|
if (info == null && includeOperation(method, beanKey)) {
|
||||||
info = createModelMBeanOperationInfo(method, method.getName(), beanKey);
|
info = createModelMBeanOperationInfo(method, method.getName(), beanKey);
|
||||||
Descriptor desc = info.getDescriptor();
|
Descriptor desc = info.getDescriptor();
|
||||||
desc.setField(FIELD_ROLE, ROLE_OPERATION);
|
desc.setField(FIELD_ROLE, ROLE_OPERATION);
|
||||||
|
|
|
||||||
|
|
@ -156,12 +156,12 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssem
|
||||||
protected boolean includeOperation(Method method, String beanKey) {
|
protected boolean includeOperation(Method method, String beanKey) {
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
|
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
|
||||||
if (pd != null) {
|
if (pd != null) {
|
||||||
return hasManagedAttribute(method);
|
if(hasManagedAttribute(method)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return hasManagedOperation(method);
|
return hasManagedOperation(method);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if the given Method has the <code>ManagedAttribute</code> attribute.
|
* Checks to see if the given Method has the <code>ManagedAttribute</code> attribute.
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,12 @@ public class AnnotationMetadataAssemblerTests extends AbstractMetadataAssemblerT
|
||||||
assertNotNull(op);
|
assertNotNull(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testOperationOnGetter() throws Exception {
|
||||||
|
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
|
||||||
|
ModelMBeanOperationInfo op = inf.getOperation("getExpensiveToCalculate");
|
||||||
|
assertNotNull(op);
|
||||||
|
}
|
||||||
|
|
||||||
protected JmxAttributeSource getAttributeSource() {
|
protected JmxAttributeSource getAttributeSource() {
|
||||||
return new AnnotationJmxAttributeSource();
|
return new AnnotationJmxAttributeSource();
|
||||||
}
|
}
|
||||||
|
|
@ -65,6 +71,6 @@ public class AnnotationMetadataAssemblerTests extends AbstractMetadataAssemblerT
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getExpectedOperationCount() {
|
protected int getExpectedOperationCount() {
|
||||||
return super.getExpectedOperationCount() + 3;
|
return super.getExpectedOperationCount() + 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,4 +110,6 @@ public class AnnotationTestBean implements IJmxTestBean {
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,4 +48,8 @@ public class AnnotationTestSubBean extends AnnotationTestBean implements IAnnota
|
||||||
|
|
||||||
public void fromInterface() {
|
public void fromInterface() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getExpensiveToCalculate() {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,7 @@ public interface IAnnotationTestBean {
|
||||||
|
|
||||||
@ManagedOperation
|
@ManagedOperation
|
||||||
void fromInterface();
|
void fromInterface();
|
||||||
|
|
||||||
|
@ManagedOperation
|
||||||
|
int getExpensiveToCalculate();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue