use of javax.management.modelmbean.ModelMBeanOperationInfo in project voldemort by voldemort.
the class JmxUtils method extractOperationInfo.
/**
* Extract all operations and attributes from the given object that have
* been annotated with the Jmx annotation. Operations are all methods that
* are marked with the JmxOperation annotation.
*
* @param object The object to process
* @return An array of operations taken from the object
*/
public static ModelMBeanOperationInfo[] extractOperationInfo(Object object) {
ArrayList<ModelMBeanOperationInfo> infos = new ArrayList<ModelMBeanOperationInfo>();
for (Method m : object.getClass().getMethods()) {
JmxOperation jmxOperation = m.getAnnotation(JmxOperation.class);
JmxGetter jmxGetter = m.getAnnotation(JmxGetter.class);
JmxSetter jmxSetter = m.getAnnotation(JmxSetter.class);
if (jmxOperation != null || jmxGetter != null || jmxSetter != null) {
String description = "";
int visibility = 1;
int impact = MBeanOperationInfo.UNKNOWN;
if (jmxOperation != null) {
description = jmxOperation.description();
impact = jmxOperation.impact();
} else if (jmxGetter != null) {
description = jmxGetter.description();
impact = MBeanOperationInfo.INFO;
visibility = 4;
} else if (jmxSetter != null) {
description = jmxSetter.description();
impact = MBeanOperationInfo.ACTION;
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);
}
}
return infos.toArray(new ModelMBeanOperationInfo[infos.size()]);
}
use of javax.management.modelmbean.ModelMBeanOperationInfo in project camel by apache.
the class MBeanInfoAssembler method extractMbeanAttributes.
private void extractMbeanAttributes(Object managedBean, Map<String, ManagedAttributeInfo> attributes, Set<ModelMBeanAttributeInfo> mBeanAttributes, Set<ModelMBeanOperationInfo> mBeanOperations) throws IntrospectionException {
for (ManagedAttributeInfo info : attributes.values()) {
ModelMBeanAttributeInfo mbeanAttribute = new ModelMBeanAttributeInfo(info.getKey(), info.getDescription(), info.getGetter(), info.getSetter());
// add missing attribute descriptors, this is needed to have attributes accessible
Descriptor desc = mbeanAttribute.getDescriptor();
desc.setField("mask", info.isMask() ? "true" : "false");
if (info.getGetter() != null) {
desc.setField("getMethod", info.getGetter().getName());
// attribute must also be added as mbean operation
ModelMBeanOperationInfo mbeanOperation = new ModelMBeanOperationInfo(info.getKey(), info.getGetter());
Descriptor opDesc = mbeanOperation.getDescriptor();
opDesc.setField("mask", info.isMask() ? "true" : "false");
mbeanOperation.setDescriptor(opDesc);
mBeanOperations.add(mbeanOperation);
}
if (info.getSetter() != null) {
desc.setField("setMethod", info.getSetter().getName());
// attribute must also be added as mbean operation
ModelMBeanOperationInfo mbeanOperation = new ModelMBeanOperationInfo(info.getKey(), info.getSetter());
mBeanOperations.add(mbeanOperation);
}
mbeanAttribute.setDescriptor(desc);
mBeanAttributes.add(mbeanAttribute);
LOG.trace("Assembled attribute: {}", mbeanAttribute);
}
}
use of javax.management.modelmbean.ModelMBeanOperationInfo in project camel by apache.
the class MBeanInfoAssembler method extractMbeanOperations.
private void extractMbeanOperations(Object managedBean, Set<ManagedOperationInfo> operations, Set<ModelMBeanOperationInfo> mBeanOperations) {
for (ManagedOperationInfo info : operations) {
ModelMBeanOperationInfo mbean = new ModelMBeanOperationInfo(info.getDescription(), info.getOperation());
Descriptor opDesc = mbean.getDescriptor();
opDesc.setField("mask", info.isMask() ? "true" : "false");
mbean.setDescriptor(opDesc);
mBeanOperations.add(mbean);
LOG.trace("Assembled operation: {}", mbean);
}
}
use of javax.management.modelmbean.ModelMBeanOperationInfo in project spring-framework by spring-projects.
the class AnnotationMetadataAssemblerTests method testOperationOnGetter.
@Test
public void testOperationOnGetter() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanOperationInfo op = inf.getOperation("getExpensiveToCalculate");
assertNotNull(op);
}
use of javax.management.modelmbean.ModelMBeanOperationInfo in project spring-framework by spring-projects.
the class AbstractJmxAssemblerTests method testAttributeHasCorrespondingOperations.
@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"));
}
Aggregations