Example usage for javax.management.modelmbean RequiredModelMBean RequiredModelMBean

List of usage examples for javax.management.modelmbean RequiredModelMBean RequiredModelMBean

Introduction

In this page you can find the example usage for javax.management.modelmbean RequiredModelMBean RequiredModelMBean.

Prototype

public RequiredModelMBean() throws MBeanException, RuntimeOperationsException 

Source Link

Document

Constructs an RequiredModelMBean with an empty ModelMBeanInfo.

Usage

From source file:com.brienwheeler.lib.jmx.MBeanRegistrationSupport.java

public static void registerMBean(Object mbean) {
    try {/*  w  ww .  ja va 2 s  .c o m*/
        ObjectNamingStrategy namingStrategy = new IdentityNamingStrategy();
        ObjectName objectName = namingStrategy.getObjectName(mbean, null);

        MBeanRegistrationSupport registrar = new MBeanRegistrationSupport();
        registrar.setServer(JmxUtils.locateMBeanServer());

        // if item qualifies as MBean, export it directly
        if (JmxUtils.isMBean(mbean.getClass())) {
            registrar.doRegister(mbean, objectName);
            return;
        }

        // assemble MBean info (from annotations by default)
        ModelMBean modelMBean = new RequiredModelMBean();
        modelMBean.setManagedResource(mbean, MR_TYPE_OBJECT_REFERENCE);
        MBeanInfoAssembler mBeanInfoAssembler = new MetadataMBeanInfoAssembler(
                new AnnotationJmxAttributeSource());
        modelMBean.setModelMBeanInfo(mBeanInfoAssembler.getMBeanInfo(mbean, objectName.getCanonicalName()));
        registrar.doRegister(modelMBean, objectName);
    } catch (Exception e) {
        throw new JmxRegisterException("error registering MBean", e);
    }
}

From source file:com.espertech.esper.metrics.jmx.CommonJMXUtil.java

private static ModelMBean createModelMBean(Object o) {
    try {//from ww w . j  a v  a  2s .  c  o m
        ModelMBean mbean = new RequiredModelMBean();
        JmxManaged annotation = o.getClass().getAnnotation(JmxManaged.class);
        String description = annotation == null ? "" : annotation.description();
        ModelMBeanInfo info = new ModelMBeanInfoSupport(o.getClass().getName(), description,
                extractAttributeInfo(o), new ModelMBeanConstructorInfo[0], extractOperationInfo(o),
                new ModelMBeanNotificationInfo[0]);
        mbean.setModelMBeanInfo(info);
        mbean.setManagedResource(o, "ObjectReference");

        return mbean;
    } catch (MBeanException e) {
        throw new RuntimeException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new RuntimeException(e);
    } catch (InstanceNotFoundException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.jolokia.jmx.JolokiaMBeanServerTest.java

@Test
public void withModelMBean() throws MBeanException, InvalidTargetObjectTypeException, InstanceNotFoundException,
        InstanceAlreadyExistsException, NotCompliantMBeanException, MalformedObjectNameException,
        NoSuchMethodException, IntrospectionException {

    RequiredModelMBean modelMBean = new RequiredModelMBean();

    ModelMBeanInfo mbi = new ModelMBeanInfoSupport(JsonAnnoPlainTest.class.getName(), "JsonMBean Test",
            new ModelMBeanAttributeInfo[] { new ModelMBeanAttributeInfo("DeepDive", "description",
                    JsonAnnoPlainTest.class.getDeclaredMethod("getDeepDive"), null) },
            new ModelMBeanConstructorInfo[] {}, new ModelMBeanOperationInfo[] {},
            new ModelMBeanNotificationInfo[] {});
    modelMBean.setModelMBeanInfo(mbi);/*from  w  ww .  j a  v a 2  s.c  o m*/
    modelMBean.setManagedResource(new JsonAnnoPlainTest(), "ObjectReference");

    JolokiaMBeanServer server = new JolokiaMBeanServer();

    ObjectName oName = new ObjectName("test:type=jsonMBean");

    server.registerMBean(modelMBean, oName);
    MBeanServer plattformServer = ManagementFactory.getPlatformMBeanServer();

    Assert.assertTrue(plattformServer.isRegistered(oName));
    Assert.assertTrue(server.isRegistered(oName));

    server.unregisterMBean(oName);
    Assert.assertFalse(plattformServer.isRegistered(oName));
    Assert.assertFalse(server.isRegistered(oName));

}

From source file:org.springframework.jmx.export.MBeanExporter.java

/**
 * Create an instance of a class that implements <code>ModelMBean</code>.
 * <p>This method is called to obtain a <code>ModelMBean</code> instance to
 * use when registering a bean. This method is called once per bean during the
 * registration phase and must return a new instance of <code>ModelMBean</code>
 * @return a new instance of a class that implements <code>ModelMBean</code>
 * @throws MBeanException if creation of the ModelMBean failed
 *///w  w  w  .ja v a 2  s.c om
protected ModelMBean createModelMBean() throws MBeanException {
    return new RequiredModelMBean();
}