Example usage for javax.management.modelmbean ModelMBeanInfoSupport ModelMBeanInfoSupport

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

Introduction

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

Prototype

public ModelMBeanInfoSupport(String className, String description, ModelMBeanAttributeInfo[] attributes,
        ModelMBeanConstructorInfo[] constructors, ModelMBeanOperationInfo[] operations,
        ModelMBeanNotificationInfo[] notifications) 

Source Link

Document

Creates a ModelMBeanInfoSupport with the provided information, but the descriptor is a default.

Usage

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

private static ModelMBean createModelMBean(Object o) {
    try {//from ww w. ja v a 2 s  .c  om
        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);/* ww w .j a  va 2s.  co 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.sakaiproject.kernel.component.core.SharedClassLoaderContainer.java

/**
 * Create the the MBean Info for the Shared ClassLoader so that the methods
 * and properties are accessible via JMX.
 * //ww  w  .ja va  2s  . co m
 * @return a new MBeanInfo structure
 */
private ModelMBeanInfo createMBeanInfo() {
    Descriptor sharedClassLoader = new DescriptorSupport(
            new String[] { "name=SharedClassLoader", "descriptorType=attribute", "default=null",
                    "displayName=Shared Class Loader", "getMethod=getManagedObject" });

    ModelMBeanAttributeInfo[] mmbai = new ModelMBeanAttributeInfo[1];
    mmbai[0] = new ModelMBeanAttributeInfo("SharedClassLoader", ClassLoader.class.getName(),
            "Shared Class Loader", true, false, false, sharedClassLoader);

    ModelMBeanOperationInfo[] mmboi = new ModelMBeanOperationInfo[1];

    mmboi[0] = new ModelMBeanOperationInfo("getManagedObject", "Get the Shared Class Loader", null,
            ClassLoader.class.getName(), ModelMBeanOperationInfo.INFO);

    return new ModelMBeanInfoSupport(this.getClass().getName(), "Sakai Shared Classloader", mmbai, null, mmboi,
            null);
}

From source file:org.sakaiproject.kernel.component.KernelLifecycle.java

/**
 * Create the the MBean Info for the Kernel so that the methods and properties are accessable via
 * JMX.//w  w w.j  ava  2 s  .  co  m
 *
 * @return a new MBeanInfo structure
 */
private ModelMBeanInfo createMBeanInfo() {
    Descriptor lastLoadDateDesc = new DescriptorSupport(
            new String[] { "name=LastLoadDate", "descriptorType=attribute", "default=0",
                    "displayName=Last Load Date", "getMethod=getLastLoadDate" });
    Descriptor lastLoadTimeDesc = new DescriptorSupport(new String[] { "name=LastLoadTime",
            "descriptorType=attribute", "default=0", "displayName=Last Load Time", "getMethod=getLoadTime" });

    ModelMBeanAttributeInfo[] mmbai = new ModelMBeanAttributeInfo[2];
    mmbai[0] = new ModelMBeanAttributeInfo("LastLoadDate", "java.util.Date", "Last Load Date", true, false,
            false, lastLoadDateDesc);

    mmbai[1] = new ModelMBeanAttributeInfo("LastLoadTime", "java.lang.Long", "Last Load Time", true, false,
            false, lastLoadTimeDesc);

    ModelMBeanOperationInfo[] mmboi = new ModelMBeanOperationInfo[7];

    mmboi[0] = new ModelMBeanOperationInfo("start", "Start the Kernel", null, "void",
            ModelMBeanOperationInfo.ACTION);
    mmboi[1] = new ModelMBeanOperationInfo("stop", "Stop the Kernel", null, "void",
            ModelMBeanOperationInfo.ACTION);
    mmboi[2] = new ModelMBeanOperationInfo("getManagedObject", "Get the Current Kernel", null,
            Kernel.class.getName(), ModelMBeanOperationInfo.INFO);

    mmboi[3] = new ModelMBeanOperationInfo("addKernelLifecycleListener",
            "Add a listener to the kernel lifecycle",
            new MBeanParameterInfo[] { new MBeanParameterInfo("Lifecycle Listener",
                    CommonLifecycleListener.class.getName(), "The Lifecycle Listener to be added") },
            "void", ModelMBeanOperationInfo.ACTION);
    mmboi[4] = new ModelMBeanOperationInfo("removeKernelLifecycleListener",
            "Remove a listener to the kernel lifecycle",
            new MBeanParameterInfo[] { new MBeanParameterInfo("Lifecycle Listener",
                    CommonLifecycleListener.class.getName(), "The Lifecycle Listener to be removed") },
            "void", ModelMBeanOperationInfo.ACTION);
    mmboi[5] = new ModelMBeanOperationInfo("getLastLoadDate", "The date the kernel was last loaded", null,
            "java.util.Date", ModelMBeanOperationInfo.INFO);
    mmboi[6] = new ModelMBeanOperationInfo("getLoadTime", "The time it took to load the kernel", null, "long",
            ModelMBeanOperationInfo.INFO);

    /*
     * mmboi[1] = new ModelMBeanOperationInfo("decPanelValue", "decrement the meter value", null,
     * "void", ModelMBeanOperationInfo.ACTION ); mmboi[2] = new
     * ModelMBeanOperationInfo("getPanelValue", "getter for PanelValue", null,"Integer",
     * ModelMBeanOperationInfo.INFO); MBeanParameterInfo [] mbpi = new MBeanParameterInfo[1];
     * mbpi[0] = new MBeanParameterInfo("inVal", "java.lang.Integer", "value to set"); mmboi[3] =
     * new ModelMBeanOperationInfo("setPanelValue", "setter for PanelValue", mbpi, "void",
     * ModelMBeanOperationInfo.ACTION); ModelMBeanConstructorInfo [] mmbci = new
     * ModelMBeanConstructorInfo[1]; mmbci[0] = new ModelMBeanConstructorInfo("ClickMeterMod",
     * "constructor for Model Bean Sample", null);
     */

    return new ModelMBeanInfoSupport(this.getClass().getName(), "Sakai Kernel", mmbai, null, mmboi, null);
}

From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java

public synchronized MBeanInfo getMBeanInfo() {
    log.debug("getMBeanInfo");

    if (_dirty) {
        _dirty = false;/*w w  w  .j  a v  a 2 s  .co m*/
        ModelMBeanAttributeInfo[] attributes = (ModelMBeanAttributeInfo[]) _attributes
                .toArray(new ModelMBeanAttributeInfo[_attributes.size()]);
        ModelMBeanOperationInfo[] operations = (ModelMBeanOperationInfo[]) _operations
                .toArray(new ModelMBeanOperationInfo[_operations.size()]);
        ModelMBeanNotificationInfo[] notifications = (ModelMBeanNotificationInfo[]) _notifications
                .toArray(new ModelMBeanNotificationInfo[_notifications.size()]);

        _beanInfo = new ModelMBeanInfoSupport(_object.getClass().getName(), findDescription(null), attributes,
                null, operations, notifications);
    }

    return _beanInfo;
}