Search in sources :

Example 1 with StandardMBean

use of javax.management.StandardMBean in project hadoop by apache.

the class FsDatasetImpl method registerMBean.

/**
   * Register the FSDataset MBean using the name
   *        "hadoop:service=DataNode,name=FSDatasetState-<datanodeUuid>"
   */
void registerMBean(final String datanodeUuid) {
    // package naming for mbeans and their impl.
    try {
        StandardMBean bean = new StandardMBean(this, FSDatasetMBean.class);
        mbeanName = MBeans.register("DataNode", "FSDatasetState-" + datanodeUuid, bean);
    } catch (NotCompliantMBeanException e) {
        LOG.warn("Error registering FSDatasetState MBean", e);
    }
    LOG.info("Registered FSDatasetState MBean");
}
Also used : StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException)

Example 2 with StandardMBean

use of javax.management.StandardMBean in project nhin-d by DirectProject.

the class DNSServer method registerMBean.

/**
	 * Register the MBean
	 */
private void registerMBean(DNSServerSettings settings) {
    String[] itemNames = { "Port", "Bind Address", "Max Request Size", "Max Outstanding Accepts", "Max Active Accepts", "Max Connection Backlog", "Read Buffer Size", "Send Timeout", "Receive Timeout", "Socket Close Timeout" };
    String[] itemDesc = { "Port", "Bind Address", "Max Request Size", "Max Outstanding Accepts", "Max Active Accepts", "Max Connection Backlog", "Read Buffer Size", "Send Timeout", "Receive Timeout", "Socket Close Timeout" };
    OpenType<?>[] types = { SimpleType.INTEGER, SimpleType.STRING, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER };
    Object[] settingsValues = { settings.getPort(), settings.getBindAddress(), settings.getMaxRequestSize(), settings.getMaxOutstandingAccepts(), settings.getMaxActiveRequests(), settings.getMaxConnectionBacklog(), settings.getReadBufferSize(), settings.getSendTimeout(), settings.getReceiveTimeout(), settings.getSocketCloseTimeout() };
    try {
        CompositeType settingsType = new CompositeType(DNSServerSettings.class.getSimpleName(), "DNS server settings.", itemNames, itemDesc, types);
        settingsData = new CompositeDataSupport(settingsType, itemNames, settingsValues);
    } catch (OpenDataException e) {
        LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e);
        return;
    }
    Class<?> clazz = this.getClass();
    final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
    objectNameBuilder.append(":type=").append(clazz.getSimpleName());
    objectNameBuilder.append(",name=").append(UUID.randomUUID());
    try {
        final StandardMBean mbean = new StandardMBean(this, DNSServerMBean.class);
        final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
    } catch (JMException e) {
        LOGGER.error("Unable to register the DNSServer MBean", e);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) StandardMBean(javax.management.StandardMBean) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ObjectName(javax.management.ObjectName) OpenDataException(javax.management.openmbean.OpenDataException) JMException(javax.management.JMException) CompositeType(javax.management.openmbean.CompositeType) MBeanServer(javax.management.MBeanServer)

Example 3 with StandardMBean

use of javax.management.StandardMBean in project nhin-d by DirectProject.

the class DNSSocketServer method registerMBean.

protected void registerMBean(Class<?> clazz) {
    final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
    objectNameBuilder.append(":type=").append(clazz.getSimpleName());
    objectNameBuilder.append(",name=").append(UUID.randomUUID());
    try {
        final StandardMBean mbean = new StandardMBean(this, DNSSocketServerMBean.class);
        final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
    } catch (JMException e) {
        LOGGER.error("Unable to register the DNSSocketServer MBean", e);
    }
}
Also used : StandardMBean(javax.management.StandardMBean) JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 4 with StandardMBean

use of javax.management.StandardMBean 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 5 with StandardMBean

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

the class MBeanExceptionTest method main.

public static void main(String[] args) throws Exception {
    System.out.println("Test that if an MBean throws RuntimeException " + "it is wrapped in RuntimeMBeanException,");
    System.out.println("and if a Standard MBean throws Exception " + "it is wrapped in MBeanException");
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    Object standard = new Except();
    ObjectName standardName = new ObjectName(":name=Standard MBean");
    Object standardMBean = new StandardMBean(new Except(), ExceptMBean.class);
    ObjectName standardMBeanName = new ObjectName(":name=Instance of StandardMBean");
    Object dynamic = new DynamicExcept();
    ObjectName dynamicName = new ObjectName(":name=Dynamic MBean");
    mbs.registerMBean(standard, standardName);
    mbs.registerMBean(standardMBean, standardMBeanName);
    mbs.registerMBean(dynamic, dynamicName);
    int failures = 0;
    failures += test(mbs, standardName, true);
    failures += test(mbs, standardMBeanName, true);
    failures += test(mbs, dynamicName, false);
    final boolean[] booleans = { false, true };
    for (boolean runtimeX : booleans) {
        Class<? extends Exception> excC = runtimeX ? RuntimeMBeanException.class : MBeanException.class;
        String excS = runtimeX ? "a RuntimeMBeanException" : "an MBeanException";
        String mbsS = "a plain MBeanServer";
        System.out.println("Test that, with " + mbsS + ", " + excS + " is wrapped " + "in " + excS);
        // is wrapped in an MBeanException".
        try {
            mbs.createMBean(Except.class.getName(), new ObjectName(":name=Oops"), new Object[] { runtimeX }, new String[] { boolean.class.getName() });
            System.out.println("FAIL: createMBean succeeded but should not have");
            failures++;
        } catch (Exception e) {
            if (!excC.isInstance(e)) {
                System.out.println("FAIL: expected " + excC.getName() + " from " + "createMBean, got " + e);
                failures++;
            } else {
                Throwable cause = e.getCause();
                if (!excC.isInstance(cause)) {
                    System.out.println("FAIL: expected " + excC.getName() + " as cause of " + excC.getName() + ", got " + e);
                    failures++;
                } else
                    System.out.println("...ok");
            }
        }
    }
    if (failures == 0)
        System.out.println("Test passed");
    else {
        System.out.println("TEST FAILED: " + failures + " failure(s)");
        System.exit(1);
    }
}
Also used : StandardMBean(javax.management.StandardMBean) MBeanException(javax.management.MBeanException) RuntimeMBeanException(javax.management.RuntimeMBeanException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Aggregations

StandardMBean (javax.management.StandardMBean)70 ObjectName (javax.management.ObjectName)32 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)21 MBeanServer (javax.management.MBeanServer)17 MalformedObjectNameException (javax.management.MalformedObjectNameException)16 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)12 MBeanRegistrationException (javax.management.MBeanRegistrationException)9 Test (org.junit.Test)9 JMException (javax.management.JMException)7 IOException (java.io.IOException)6 Logger (org.apache.aries.jmx.Logger)6 InstanceNotFoundException (javax.management.InstanceNotFoundException)5 Activate (org.apache.felix.scr.annotations.Activate)5 IgniteStandardMXBean (org.apache.ignite.internal.mxbean.IgniteStandardMXBean)5 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 MBeanInfo (javax.management.MBeanInfo)4 OpenDataException (javax.management.openmbean.OpenDataException)4 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)3 CompositeType (javax.management.openmbean.CompositeType)3 OpenType (javax.management.openmbean.OpenType)3