Search in sources :

Example 41 with MBeanServer

use of javax.management.MBeanServer in project jdk8u_jdk by JetBrains.

the class PlatformMBeanServerTest method main.

public static void main(String[] argv) throws Exception {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    printMBeans(mbs);
    // validate if all standard JVM MBeans are registered
    checkStandardMBeans(mbs);
    // validate if all platform MBeans are registered
    checkPlatformMBeans(mbs);
    MBeanServer mbs1 = ManagementFactory.getPlatformMBeanServer();
    if (mbs != mbs1) {
        throw new RuntimeException("Second call to getPlatformMBeanServer()" + " returns a different MBeanServer.");
    }
    System.out.println("Test passed.");
}
Also used : MBeanServer(javax.management.MBeanServer)

Example 42 with MBeanServer

use of javax.management.MBeanServer in project jdk8u_jdk by JetBrains.

the class LoggingMXBeanTest method main.

public static void main(String[] argv) throws Exception {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    LoggingMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(mbs, LogManager.LOGGING_MXBEAN_NAME, LoggingMXBean.class);
    // test LoggingMXBean proxy
    test = new LoggingMXBeanTest(proxy);
    // check if the attributes implemented by PlatformLoggingMXBean
    // and LoggingMXBean return the same value
    PlatformLoggingMXBean mxbean = ManagementFactory.getPlatformMXBean(mbs, PlatformLoggingMXBean.class);
    checkAttributes(proxy, mxbean);
}
Also used : MBeanServer(javax.management.MBeanServer)

Example 43 with MBeanServer

use of javax.management.MBeanServer in project jdk8u_jdk by JetBrains.

the class FeatureOrderTest method main.

public static void main(String[] args) throws Exception {
    // Build the lists of attributes and operations that we would expect
    // if they are derived by reflection and preserve the reflection order
    List<String> expectedAttributeNames = new ArrayList<String>();
    List<String> expectedOperationNames = new ArrayList<String>();
    for (Method m : OrderMXBean.class.getMethods()) {
        String name = m.getName();
        String attrName = null;
        if (name.startsWith("get") && !name.equals("get") && m.getParameterTypes().length == 0 && m.getReturnType() != void.class)
            attrName = name.substring(3);
        else if (name.startsWith("is") && !name.equals("is") && m.getParameterTypes().length == 0 && m.getReturnType() == boolean.class)
            attrName = name.substring(2);
        else if (name.startsWith("set") && !name.equals("set") && m.getReturnType() == void.class && m.getParameterTypes().length == 1)
            attrName = name.substring(3);
        if (attrName != null) {
            if (!expectedAttributeNames.contains(attrName))
                expectedAttributeNames.add(attrName);
        } else
            expectedOperationNames.add(name);
    }
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    for (boolean mxbean : booleans) {
        for (boolean withStandardMBean : booleans) {
            String testName = "MXBean: " + mxbean + "; " + "using javax.management.StandardMBean: " + withStandardMBean;
            System.out.println("Test case: " + testName);
            Object mbean;
            if (mxbean) {
                if (withStandardMBean) {
                    mbean = new StandardMBean(new OrderImpl(), OrderMXBean.class, true);
                } else
                    mbean = new OrderImpl();
            } else {
                if (withStandardMBean)
                    mbean = new StandardMBean(new Order(), OrderMBean.class);
                else
                    mbean = new Order();
            }
            ObjectName name = new ObjectName(":mxbean=" + mxbean + "," + "withStandardMBean=" + withStandardMBean);
            mbs.registerMBean(mbean, name);
            /* Make sure we are testing what we think. */
            MBeanInfo mbi = mbs.getMBeanInfo(name);
            boolean isWithStandardMBean = mbs.isInstanceOf(name, StandardMBean.class.getName());
            System.out.println("classname " + mbi.getClassName());
            String mxbeanField = (String) mbi.getDescriptor().getFieldValue("mxbean");
            boolean isMXBean = "true".equalsIgnoreCase(mxbeanField);
            if (mxbean != isMXBean)
                throw new Exception("Test error: MXBean mismatch");
            if (withStandardMBean != isWithStandardMBean)
                throw new Exception("Test error: StandardMBean mismatch");
            // Check that order of attributes and operations matches
            MBeanAttributeInfo[] mbais = mbi.getAttributes();
            checkEqual(expectedAttributeNames.size(), mbais.length, "number of attributes");
            List<String> attributeNames = new ArrayList<String>();
            for (MBeanAttributeInfo mbai : mbais) attributeNames.add(mbai.getName());
            checkEqual(expectedAttributeNames, attributeNames, "order of attributes");
            MBeanOperationInfo[] mbois = mbi.getOperations();
            checkEqual(expectedOperationNames.size(), mbois.length, "number of operations");
            List<String> operationNames = new ArrayList<String>();
            for (MBeanOperationInfo mboi : mbois) operationNames.add(mboi.getName());
            checkEqual(expectedOperationNames, operationNames, "order of operations");
            System.out.println();
        }
    }
    if (failed)
        throw new Exception("TEST FAILED");
    System.out.println("TEST PASSED");
}
Also used : MBeanInfo(javax.management.MBeanInfo) StandardMBean(javax.management.StandardMBean) MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 44 with MBeanServer

use of javax.management.MBeanServer in project jdk8u_jdk by JetBrains.

the class ImmutableNotificationInfoTest method test.

private static boolean test(Object mbean, boolean expectImmutable) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName on = new ObjectName("a:b=c");
    mbs.registerMBean(mbean, on);
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    Descriptor d = mbi.getDescriptor();
    String immutableValue = (String) d.getFieldValue("immutableInfo");
    boolean immutable = ("true".equals(immutableValue));
    if (immutable != expectImmutable) {
        System.out.println("FAILED: " + mbean.getClass().getName() + " -> " + immutableValue);
        return false;
    } else {
        System.out.println("OK: " + mbean.getClass().getName());
        return true;
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) Descriptor(javax.management.Descriptor) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 45 with MBeanServer

use of javax.management.MBeanServer in project jdk8u_jdk by JetBrains.

the class UnregisterMBeanExceptionTest method main.

public static void main(String[] args) throws Exception {
    // Instantiate the MBean server
    //
    System.out.println("Create the MBean server");
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    // Register the MBean
    //
    System.out.println("Create a TestDynamicMBean");
    TestDynamicMBean obj = new TestDynamicMBean();
    ObjectName n = new ObjectName("d:k=v");
    System.out.println("Register a TestDynamicMBean");
    mbs.registerMBean(obj, n);
    obj.throwException = true;
    System.out.println("Unregister a TestDynamicMBean");
    try {
        mbs.unregisterMBean(n);
    } catch (Exception e) {
        throw new IllegalArgumentException("Test failed", e);
    }
    boolean isRegistered = mbs.isRegistered(n);
    System.out.println("Is MBean Registered? " + isRegistered);
    if (isRegistered) {
        throw new IllegalArgumentException("Test failed: the MBean is still registered");
    } else {
        System.out.println("Test passed");
    }
}
Also used : InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) AttributeNotFoundException(javax.management.AttributeNotFoundException) ReflectionException(javax.management.ReflectionException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

MBeanServer (javax.management.MBeanServer)1218 ObjectName (javax.management.ObjectName)939 Test (org.junit.Test)214 MalformedObjectNameException (javax.management.MalformedObjectNameException)123 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)94 InstanceNotFoundException (javax.management.InstanceNotFoundException)87 IOException (java.io.IOException)82 JMXServiceURL (javax.management.remote.JMXServiceURL)70 Attribute (javax.management.Attribute)66 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)65 HashMap (java.util.HashMap)63 MBeanRegistrationException (javax.management.MBeanRegistrationException)56 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)54 TabularData (javax.management.openmbean.TabularData)51 ArrayList (java.util.ArrayList)47 JMXConnectorServer (javax.management.remote.JMXConnectorServer)47 JMXConnector (javax.management.remote.JMXConnector)40 Map (java.util.Map)38 JMException (javax.management.JMException)38 Test (org.junit.jupiter.api.Test)36