Search in sources :

Example 76 with MBeanInfo

use of javax.management.MBeanInfo in project Payara by payara.

the class BulkAccessImpl method bulkGetAttributeNames.

public Object[] bulkGetAttributeNames(final ObjectName[] objectNames) {
    final Object[] results = new Object[objectNames.length];
    final Object[] mbeanInfos = bulkGetMBeanInfo(objectNames);
    for (int i = 0; i < results.length; ++i) {
        if (mbeanInfos[i] instanceof MBeanInfo) {
            final MBeanInfo info = (MBeanInfo) mbeanInfos[i];
            results[i] = JMXUtil.getAttributeNames(info.getAttributes());
        } else {
            results[i] = mbeanInfos[i];
        }
    }
    return (results);
}
Also used : MBeanInfo(javax.management.MBeanInfo)

Example 77 with MBeanInfo

use of javax.management.MBeanInfo in project quickstart by wildfly.

the class AnnotatedComponentHelloWorldIT method testHello.

@Test
public void testHello() throws Exception {
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName("quickstarts", "type", AnnotatedComponentHelloWorld.class.getSimpleName());
    MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName);
    Assert.assertNotNull(mbeanInfo);
    Assert.assertEquals(0L, mbeanServer.getAttribute(objectName, "Count"));
    Assert.assertEquals("Hello", mbeanServer.getAttribute(objectName, "WelcomeMessage"));
    Assert.assertEquals("Hello jer!", mbeanServer.invoke(objectName, "sayHello", new Object[] { "jer" }, new String[] { "java.lang.String" }));
    Assert.assertEquals(1L, mbeanServer.getAttribute(objectName, "Count"));
    mbeanServer.setAttribute(objectName, new Attribute("WelcomeMessage", "Hi"));
    Assert.assertEquals("Hi jer!", mbeanServer.invoke(objectName, "sayHello", new Object[] { "jer" }, new String[] { "java.lang.String" }));
    Assert.assertEquals(2L, mbeanServer.getAttribute(objectName, "Count"));
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 78 with MBeanInfo

use of javax.management.MBeanInfo in project quickstart by wildfly.

the class MXPojoHelloWorldIT method testHello.

@Test
public void testHello() throws Exception {
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName("quickstarts", "type", MXPojoHelloWorld.class.getSimpleName());
    MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName);
    Assert.assertNotNull(mbeanInfo);
    Assert.assertEquals(0L, mbeanServer.getAttribute(objectName, "Count"));
    Assert.assertEquals("Welcome", mbeanServer.getAttribute(objectName, "WelcomeMessage"));
    Assert.assertEquals("Welcome jer!", mbeanServer.invoke(objectName, "sayHello", new Object[] { "jer" }, new String[] { "java.lang.String" }));
    Assert.assertEquals(1L, mbeanServer.getAttribute(objectName, "Count"));
    mbeanServer.setAttribute(objectName, new Attribute("WelcomeMessage", "Hi"));
    Assert.assertEquals("Hi jer!", mbeanServer.invoke(objectName, "sayHello", new Object[] { "jer" }, new String[] { "java.lang.String" }));
    Assert.assertEquals(2L, mbeanServer.getAttribute(objectName, "Count"));
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 79 with MBeanInfo

use of javax.management.MBeanInfo in project tomee by apache.

the class LocalJMXCommand method invoke.

private void invoke(final String value) {
    if (!value.contains("(") || !value.contains(")")) {
        streamManager.writeErr("method should follow the format: <methoName>(<arg1>,<arg2>,...)");
        return;
    }
    int open = value.indexOf("(");
    int close = value.lastIndexOf(")");
    final String name = value.substring(0, open).trim();
    final String rawArgs = value.substring(open + 1, close).trim();
    final ObjectName on;
    try {
        on = new ObjectName(value.substring(close + 1).trim());
    } catch (MalformedObjectNameException e) {
        streamManager.writeErr(e);
        return;
    }
    final MBeanServer server = LocalMBeanServer.get();
    final String[] args;
    if (rawArgs == null || rawArgs.isEmpty()) {
        args = new String[0];
    } else {
        args = rawArgs.split(",");
    }
    try {
        final MBeanInfo minfo = server.getMBeanInfo(on);
        final MBeanOperationInfo[] methods = minfo.getOperations();
        MBeanOperationInfo operation = null;
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().equals(name)) {
                operation = methods[i];
                break;
            }
        }
        if (operation == null) {
            streamManager.writeErr("can't find operation '" + name + "'");
            return;
        }
        final Object[] passedArgs = new Object[args.length];
        final String[] passedArgTypes = new String[args.length];
        for (int i = 0; i < passedArgs.length; i++) {
            final String expected = operation.getSignature()[i].getType();
            if (!String.class.getName().equals(expected)) {
                passedArgs[i] = PropertyEditors.getValue(expected, args[i], Thread.currentThread().getContextClassLoader());
            } else {
                passedArgs[i] = args[i];
            }
            passedArgTypes[i] = expected;
        }
        streamManager.writeOut(stringify(server.invoke(on, name, passedArgs, passedArgTypes)));
    } catch (Exception e) {
        streamManager.writeErr(e);
        return;
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) RuntimeMBeanException(javax.management.RuntimeMBeanException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer) MBeanServer(javax.management.MBeanServer)

Example 80 with MBeanInfo

use of javax.management.MBeanInfo 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

MBeanInfo (javax.management.MBeanInfo)154 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)87 ObjectName (javax.management.ObjectName)79 MBeanOperationInfo (javax.management.MBeanOperationInfo)38 MBeanServer (javax.management.MBeanServer)27 Test (org.junit.Test)27 Attribute (javax.management.Attribute)19 ArrayList (java.util.ArrayList)17 IntrospectionException (javax.management.IntrospectionException)16 ReflectionException (javax.management.ReflectionException)16 HashMap (java.util.HashMap)15 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 IOException (java.io.IOException)12 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)12 MBeanParameterInfo (javax.management.MBeanParameterInfo)12 MBeanServerConnection (javax.management.MBeanServerConnection)10 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 AttributeList (javax.management.AttributeList)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)9 Descriptor (javax.management.Descriptor)8