Search in sources :

Example 61 with MBeanInfo

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

the class MBeanDeployerTest method mbeans.

@Test
public void mbeans() throws Exception {
    final Set<String> parsed = new HashSet<String>();
    for (final Object name : appInfo.jmx.values()) {
        final ObjectName on = new ObjectName((String) name);
        final String cn = on.getCanonicalName();
        if (cn.contains("name=Empty")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            parsed.add(cn);
        } else if (cn.contains("name=Reader")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            assertEquals(2, server.getAttribute(on, "value"));
            parsed.add(cn);
        } else if (cn.contains("name=ReaderWriter")) {
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            assertEquals(2, server.getAttribute(on, "value"));
            server.setAttribute(on, new Attribute("value", 5));
            assertEquals(5, server.getAttribute(on, "value"));
            parsed.add(cn);
        } else if (cn.contains("name=Inheritance")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            assertEquals(2, server.getAttribute(on, "value"));
            server.setAttribute(on, new Attribute("value", 5));
            assertEquals(5, server.getAttribute(on, "value"));
            assertEquals("yes - no", server.invoke(on, "returnValue", null, null));
            parsed.add(cn);
        } else if (cn.contains("name=MBeanDescription")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            assertEquals("descr ;)", server.getMBeanInfo(on).getDescription());
            parsed.add(cn);
        } else if (cn.contains("name=Operation")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            final MBeanInfo info = server.getMBeanInfo(on);
            if ("desc".equals(info.getOperations()[0].getName())) {
                assertEquals("param", info.getOperations()[0].getSignature()[0].getDescription());
            } else {
                assertEquals("param", info.getOperations()[1].getSignature()[0].getDescription());
            }
            assertTrue(server.isRegistered(on));
            assertEquals("yes - no", server.invoke(on, "returnValue", null, null));
            parsed.add(cn);
        } else if (cn.contains("name=ReaderDescription")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(cn.contains("name=ReaderDescription"));
            assertTrue(server.isRegistered(on));
            assertEquals(1, server.getMBeanInfo(on).getAttributes().length);
            assertEquals("just a value", server.getMBeanInfo(on).getAttributes()[0].getDescription());
            parsed.add(cn);
        } else if (cn.contains("name=OperationDescription")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            assertEquals(1, server.getMBeanInfo(on).getOperations().length);
            assertEquals("just an op", server.getMBeanInfo(on).getOperations()[0].getDescription());
            parsed.add(cn);
        }
    }
    assertEquals(8, parsed.size());
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) HashSet(java.util.HashSet) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 62 with MBeanInfo

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

the class DynamicMBeanHandler method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    final String methodName = method.getName();
    if (method.getDeclaringClass().equals(Object.class) && "toString".equals(methodName)) {
        return getClass().getSimpleName() + " Proxy";
    }
    if (method.getAnnotation(PreDestroy.class) != null) {
        return destroy();
    }
    final ConnectionInfo info = getConnectionInfo(method);
    final MBeanInfo infos = info.getMBeanInfo();
    if (methodName.startsWith("set") && methodName.length() > 3 && args != null && args.length == 1 && (Void.TYPE.equals(method.getReturnType()) || Void.class.equals(method.getReturnType()))) {
        final String attributeName = attributeName(infos, methodName, method.getParameterTypes()[0]);
        info.setAttribute(new Attribute(attributeName, args[0]));
        return null;
    } else if (methodName.startsWith("get") && (args == null || args.length == 0) && methodName.length() > 3) {
        final String attributeName = attributeName(infos, methodName, method.getReturnType());
        return info.getAttribute(attributeName);
    }
    // operation
    return info.invoke(methodName, args, getSignature(method));
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) PreDestroy(javax.annotation.PreDestroy)

Example 63 with MBeanInfo

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

the class GridMBeanSelfTest method testCorrectMBeanInfo.

/**
 * Tests correct MBean interface.
 *
 * @throws Exception Thrown if test fails.
 */
public void testCorrectMBeanInfo() throws Exception {
    StandardMBean mbean = new IgniteStandardMXBean(new GridMBeanImplementation(), GridMBeanInterface.class);
    MBeanInfo info = mbean.getMBeanInfo();
    assert info.getDescription().equals("MBeanDescription.") == true;
    assert info.getOperations().length == 2;
    for (MBeanOperationInfo opInfo : info.getOperations()) {
        if (opInfo.getDescription().equals("MBeanOperation."))
            assert opInfo.getSignature().length == 2;
        else {
            assert opInfo.getDescription().equals("MBeanSuperOperation.") == true;
            assert opInfo.getSignature().length == 1;
        }
    }
    for (MBeanParameterInfo paramInfo : info.getOperations()[0].getSignature()) {
        if (paramInfo.getName().equals("ignored"))
            assert paramInfo.getDescription().equals("MBeanOperationParameter1.") == true;
        else {
            assert paramInfo.getName().equals("someData") == true;
            assert paramInfo.getDescription().equals("MBeanOperationParameter2.") == true;
        }
    }
    assert info.getAttributes().length == 4 : "Expected 4 attributes but got " + info.getAttributes().length;
    for (MBeanAttributeInfo attrInfo : info.getAttributes()) {
        if (attrInfo.isWritable() == false) {
            assert (attrInfo.getDescription().equals("MBeanReadonlyGetter.") == true || attrInfo.getDescription().equals("MBeanROGetter."));
        } else {
            assert (attrInfo.getDescription().equals("MBeanWritableGetter.") == true || attrInfo.getDescription().equals("MBeanWritableIsGetter."));
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) StandardMBean(javax.management.StandardMBean) IgniteStandardMXBean(org.apache.ignite.internal.mxbean.IgniteStandardMXBean) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 64 with MBeanInfo

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

the class MEJBTest method testMBean.

private void testMBean(final ObjectName objectName) throws Exception {
    println("");
    println("" + objectName);
    final Management mejb = mMEJB;
    final MBeanInfo info = mejb.getMBeanInfo(objectName);
    final String[] attrNames = getAttributeNames(info.getAttributes());
    println("attributes: " + toString(newListFromArray(attrNames), ", "));
    final AttributeList list = mejb.getAttributes(objectName, attrNames);
    for (final String attrName : attrNames) {
        try {
            final Object value = mejb.getAttribute(objectName, attrName);
        } catch (Exception e) {
            println("Attribute failed: " + attrName);
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) AttributeList(javax.management.AttributeList) PortableRemoteObject(javax.rmi.PortableRemoteObject) Management(javax.management.j2ee.Management)

Example 65 with MBeanInfo

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

the class GenericTest method validate.

private boolean validate(final ObjectName objectName) throws Exception {
    boolean valid = true;
    MBeanServerConnection conn = getConnection();
    MBeanInfo info = null;
    try {
        info = conn.getMBeanInfo(objectName);
    } catch (Exception e) {
        valid = false;
        warning(" during getMBeanInfo() for: " + objectName + "\n" + " message = " + e.getMessage());
        // abort--the connection has died
        throw e;
    }
    if (mDoInfo && !validateMBeanInfo(objectName, info)) {
        trace("validateMBeanInfo failed for: " + objectName);
        valid = false;
    }
    if (mDoAttributes && !validateAttributes(objectName, info.getAttributes())) {
        trace("validateAttributes failed for: " + objectName);
        valid = false;
    }
    if (mDoOperations && !validateGetters(objectName, info.getOperations())) {
        trace("validateGetters failed for: " + objectName);
        valid = false;
    }
    return (valid);
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanServerConnection(javax.management.MBeanServerConnection) InstanceNotFoundException(javax.management.InstanceNotFoundException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException)

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