Search in sources :

Example 6 with RuntimeMBeanException

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)) })));
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 7 with RuntimeMBeanException

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;
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) DynamicMBean(javax.management.DynamicMBean) JMRuntimeException(javax.management.JMRuntimeException) MBeanInfo(javax.management.MBeanInfo) RuntimeErrorException(javax.management.RuntimeErrorException) JMRuntimeException(javax.management.JMRuntimeException)

Example 8 with RuntimeMBeanException

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("");
    }
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanInfo(javax.management.MBeanInfo) RuntimeMBeanException(javax.management.RuntimeMBeanException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer) MBeanServer(javax.management.MBeanServer)

Aggregations

RuntimeMBeanException (javax.management.RuntimeMBeanException)8 MBeanException (javax.management.MBeanException)5 MBeanInfo (javax.management.MBeanInfo)3 ObjectName (javax.management.ObjectName)3 ReflectionException (javax.management.ReflectionException)3 RuntimeErrorException (javax.management.RuntimeErrorException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)2 MBeanServer (javax.management.MBeanServer)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)2 Attribute (javax.management.Attribute)1 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 DynamicMBean (javax.management.DynamicMBean)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 IntrospectionException (javax.management.IntrospectionException)1 JMRuntimeException (javax.management.JMRuntimeException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 StandardMBean (javax.management.StandardMBean)1 LocalMBeanServer (org.apache.openejb.monitoring.LocalMBeanServer)1 Test (org.junit.Test)1