use of javax.management.RuntimeMBeanException in project neo4j by neo4j.
the class JmxQueryProcedureTest method shouldHandleMBeanThatThrowsOnGetAttribute.
@Test
public void shouldHandleMBeanThatThrowsOnGetAttribute() throws Throwable {
// given some JVM MBeans do not allow accessing their attributes, despite marking
// then as readable
when(jmxServer.getAttribute(beanName, "name")).thenThrow(new RuntimeMBeanException(new UnsupportedOperationException("Haha, screw discoverable services!")));
JmxQueryProcedure procedure = new JmxQueryProcedure(ProcedureSignature.procedureName("bob"), jmxServer);
// when
RawIterator<Object[], ProcedureException> result = procedure.apply(null, new Object[] { "*:*" });
// then
assertThat(asList(result), contains(equalTo(new Object[] { "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference", "This is a description", map(attributeName, map("description", "This is the attribute desc.", "value", null)) })));
}
use of javax.management.RuntimeMBeanException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getMBeanInfo.
public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException, ReflectionException {
// ------------------------------
// ------------------------------
DynamicMBean moi = getMBean(name);
final MBeanInfo mbi;
try {
mbi = moi.getMBeanInfo();
} catch (RuntimeMBeanException e) {
throw e;
} catch (RuntimeErrorException e) {
throw e;
} catch (RuntimeException e) {
throw new RuntimeMBeanException(e, "getMBeanInfo threw RuntimeException");
} catch (Error e) {
throw new RuntimeErrorException(e, "getMBeanInfo threw Error");
}
if (mbi == null)
throw new JMRuntimeException("MBean " + name + "has no MBeanInfo");
checkMBeanPermission(mbi.getClassName(), null, name, "getMBeanInfo");
return mbi;
}
use of javax.management.RuntimeMBeanException in project tomee by apache.
the class LocalJMXCommand method listMBeans.
private void listMBeans() {
final MBeanServer mBeanServer = LocalMBeanServer.get();
final Set<ObjectName> names;
try {
names = mBeanServer.queryNames(null, null);
} catch (Exception e) {
streamManager.writeErr(e);
return;
}
final Iterator<ObjectName> it = names.iterator();
while (it.hasNext()) {
ObjectName oname = it.next();
streamManager.writeOut("Name: " + oname.toString());
try {
final MBeanInfo minfo = mBeanServer.getMBeanInfo(oname);
String code = minfo.getClassName();
if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
code = (String) mBeanServer.getAttribute(oname, "modelerType");
}
streamManager.writeOut(" + modelerType: " + code);
MBeanAttributeInfo[] attrs = minfo.getAttributes();
Object value = null;
for (int i = 0; i < attrs.length; i++) {
if (!attrs[i].isReadable()) {
continue;
}
final String attName = attrs[i].getName();
if ("modelerType".equals(attName)) {
continue;
}
if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0 || attName.indexOf(" ") >= 0) {
continue;
}
try {
value = mBeanServer.getAttribute(oname, attName);
} catch (RuntimeMBeanException uoe) {
// ignored
} catch (Throwable t) {
streamManager.writeErr(new Exception(t));
continue;
}
try {
String valueString = stringify(value);
streamManager.writeOut(" + " + attName + ": " + valueString);
} catch (Throwable t) {
streamManager.writeErr(new Exception(t));
}
}
} catch (Throwable t) {
streamManager.writeErr(new Exception(t));
}
streamManager.writeOut("");
}
}
Aggregations