use of javax.management.MBeanInfo in project jmxtrans by jmxtrans.
the class Query method fetchResults.
public Iterable<Result> fetchResults(MBeanServerConnection mbeanServer, ObjectName queryName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
MBeanInfo info = mbeanServer.getMBeanInfo(queryName);
ObjectInstance oi = mbeanServer.getObjectInstance(queryName);
List<String> attributes;
if (attr.isEmpty()) {
attributes = new ArrayList<>();
for (MBeanAttributeInfo attrInfo : info.getAttributes()) {
attributes.add(attrInfo.getName());
}
} else {
attributes = attr;
}
try {
if (!attributes.isEmpty()) {
logger.debug("Executing queryName [{}] from query [{}]", queryName.getCanonicalName(), this);
AttributeList al = mbeanServer.getAttributes(queryName, attributes.toArray(new String[attributes.size()]));
return new JmxResultProcessor(this, oi, al.asList(), info.getClassName(), queryName.getDomain()).getResults();
}
} catch (UnmarshalException ue) {
if ((ue.getCause() != null) && (ue.getCause() instanceof ClassNotFoundException)) {
logger.debug("Bad unmarshall, continuing. This is probably ok and due to something like this: " + "http://ehcache.org/xref/net/sf/ehcache/distribution/RMICacheManagerPeerListener.html#52", ue.getMessage());
} else {
throw ue;
}
}
return ImmutableList.of();
}
use of javax.management.MBeanInfo in project jvm-tools by aragozin.
the class MBeanHelper method get.
public String get(ObjectName bean, String attr) throws Exception {
MBeanInfo mbinfo = mserver.getMBeanInfo(bean);
MBeanAttributeInfo ai = attrInfo(mbinfo, attr);
if (ai == null) {
throw new IllegalArgumentException("No such attribute '" + attr + "'");
}
if (!ai.isReadable()) {
throw new IllegalArgumentException("Attribute '" + attr + "' is write-only");
}
Object v = mserver.getAttribute(bean, attr);
String type = ai.getType();
String text = format(v, type);
return text;
}
use of javax.management.MBeanInfo in project jvm-tools by aragozin.
the class MBeanHelper method set.
public void set(ObjectName bean, String attr, String value) throws Exception {
MBeanInfo mbinfo = mserver.getMBeanInfo(bean);
MBeanAttributeInfo ai = attrInfo(mbinfo, attr);
if (ai == null) {
throw new IllegalArgumentException("No such attribute '" + attr + "'");
}
if (!ai.isWritable()) {
throw new IllegalArgumentException("Attribute '" + attr + "' is not writeable");
}
String type = ai.getType();
Object ov = convert(value, type);
mserver.setAttribute(bean, new Attribute(attr, ov));
}
use of javax.management.MBeanInfo in project jetty.project by eclipse.
the class ObjectMBean method getMBeanInfo.
public MBeanInfo getMBeanInfo() {
try {
if (_info == null) {
// Start with blank lazy lists attributes etc.
String desc = null;
List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>();
List<MBeanConstructorInfo> constructors = new ArrayList<MBeanConstructorInfo>();
List<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>();
List<MBeanNotificationInfo> notifications = new ArrayList<MBeanNotificationInfo>();
// Find list of classes that can influence the mbean
Class<?> o_class = _managed.getClass();
List<Class<?>> influences = new ArrayList<Class<?>>();
// always add MBean itself
influences.add(this.getClass());
influences = findInfluences(influences, _managed.getClass());
if (LOG.isDebugEnabled())
LOG.debug("Influence Count: {}", influences.size());
// Process Type Annotations
ManagedObject primary = o_class.getAnnotation(ManagedObject.class);
if (primary != null) {
desc = primary.value();
} else {
if (LOG.isDebugEnabled())
LOG.debug("No @ManagedObject declared on {}", _managed.getClass());
}
// For each influence
for (int i = 0; i < influences.size(); i++) {
Class<?> oClass = influences.get(i);
ManagedObject typeAnnotation = oClass.getAnnotation(ManagedObject.class);
if (LOG.isDebugEnabled())
LOG.debug("Influenced by: " + oClass.getCanonicalName());
if (typeAnnotation == null) {
if (LOG.isDebugEnabled())
LOG.debug("Annotations not found for: {}", oClass.getCanonicalName());
continue;
}
for (Method method : oClass.getDeclaredMethods()) {
ManagedAttribute methodAttributeAnnotation = method.getAnnotation(ManagedAttribute.class);
if (methodAttributeAnnotation != null) {
// TODO sort out how a proper name could get here, its a method name as an attribute at this point.
if (LOG.isDebugEnabled())
LOG.debug("Attribute Annotation found for: {}", method.getName());
MBeanAttributeInfo mai = defineAttribute(method, methodAttributeAnnotation);
if (mai != null) {
attributes.add(mai);
}
}
ManagedOperation methodOperationAnnotation = method.getAnnotation(ManagedOperation.class);
if (methodOperationAnnotation != null) {
if (LOG.isDebugEnabled())
LOG.debug("Method Annotation found for: {}", method.getName());
MBeanOperationInfo oi = defineOperation(method, methodOperationAnnotation);
if (oi != null) {
operations.add(oi);
}
}
}
}
_info = new MBeanInfo(o_class.getName(), desc, (MBeanAttributeInfo[]) attributes.toArray(new MBeanAttributeInfo[attributes.size()]), (MBeanConstructorInfo[]) constructors.toArray(new MBeanConstructorInfo[constructors.size()]), (MBeanOperationInfo[]) operations.toArray(new MBeanOperationInfo[operations.size()]), (MBeanNotificationInfo[]) notifications.toArray(new MBeanNotificationInfo[notifications.size()]));
}
} catch (RuntimeException e) {
LOG.warn(e);
throw e;
}
return _info;
}
use of javax.management.MBeanInfo in project jetty.project by eclipse.
the class ObjectMBeanTest method testDerivedOperations.
@Test
public void testDerivedOperations() throws Exception {
Derived derived = new Derived();
ObjectMBean mbean = (ObjectMBean) ObjectMBean.mbeanFor(derived);
mbean.setMBeanContainer(container);
container.beanAdded(null, derived);
MBeanInfo info = mbean.getMBeanInfo();
Assert.assertEquals("operation count does not match", 5, info.getOperations().length);
MBeanOperationInfo[] opinfos = info.getOperations();
boolean publish = false;
boolean doodle = false;
boolean good = false;
for (int i = 0; i < opinfos.length; ++i) {
MBeanOperationInfo opinfo = opinfos[i];
if ("publish".equals(opinfo.getName())) {
publish = true;
Assert.assertEquals("description doesn't match", "publish something", opinfo.getDescription());
}
if ("doodle".equals(opinfo.getName())) {
doodle = true;
Assert.assertEquals("description doesn't match", "Doodle something", opinfo.getDescription());
MBeanParameterInfo[] pinfos = opinfo.getSignature();
Assert.assertEquals("parameter description doesn't match", "A description of the argument", pinfos[0].getDescription());
Assert.assertEquals("parameter name doesn't match", "doodle", pinfos[0].getName());
}
// This is a proxied operation on the JMX wrapper
if ("good".equals(opinfo.getName())) {
good = true;
Assert.assertEquals("description does not match", "test of proxy operations", opinfo.getDescription());
Assert.assertEquals("execution contexts wrong", "not bad", mbean.invoke("good", new Object[] {}, new String[] {}));
}
}
Assert.assertTrue("publish operation was not not found", publish);
Assert.assertTrue("doodle operation was not not found", doodle);
Assert.assertTrue("good operation was not not found", good);
}
Aggregations