Example usage for javax.management.modelmbean DescriptorSupport DescriptorSupport

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

Introduction

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

Prototype

public DescriptorSupport(String... fields) 

Source Link

Document

Constructor taking fields in the fieldName=fieldValue format.

Usage

From source file:org.apache.geode.admin.jmx.internal.ConfigAttributeInfo.java

@Override
public ModelMBeanAttributeInfo createAttributeInfo() {
    Descriptor desc = new DescriptorSupport(
            new String[] { "name=" + this.displayName, "descriptorType=attribute", "currencyTimeLimit=-1", // always stale
                    "displayName=" + this.displayName, "getMethod=getJmxValue", "setMethod=setJmxValue" });

    Assert.assertTrue(this.config != null, "Config target object is null!");
    desc.setField("targetObject", this.config);

    ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(this.displayName, // name
            this.type, // type
            this.description, // description
            this.readable, // isReadable
            this.writeable, // isWritable
            this.is, // isIs
            desc);//from  www  .j  a  va 2 s . c om

    return info;
}

From source file:org.apache.geode.admin.jmx.internal.StatisticAttributeInfo.java

@Override
public ModelMBeanAttributeInfo createAttributeInfo() {
    Descriptor desc = new DescriptorSupport(
            new String[] { "name=" + this.displayName, "descriptorType=attribute", "currencyTimeLimit=-1", // always stale
                    "displayName=" + this.displayName, "getMethod=getValue" });

    Assert.assertTrue(this.stat != null, "Stat target object is null!");
    desc.setField("targetObject", this.stat);

    ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(this.displayName, // name
            this.type, // type
            this.description, // description
            this.readable, // isReadable
            this.writeable, // isWritable
            this.is, // isIs
            desc);// w w w  .ja  v  a2s  .c  o m

    return info;
}

From source file:org.eclipse.smila.management.jmx.DynamicMBeanBuilder.java

/**
 * Builds the model m bean info./*  w  w w  . j  ava 2s  .co  m*/
 * 
 * @return the model m bean info
 * 
 * @throws IllegalAccessException
 *           the illegal access exception
 * @throws InvocationTargetException
 *           the invocation target exception
 */
private ModelMBeanInfo buildModelMBeanInfo() throws IllegalAccessException, InvocationTargetException {
    // lists
    final List<ModelMBeanOperationInfo> operationsList = new ArrayList<ModelMBeanOperationInfo>();
    final List<ModelMBeanAttributeInfo> attributesList = new ArrayList<ModelMBeanAttributeInfo>();
    // arrays
    final ModelMBeanConstructorInfo[] dConstructors = new ModelMBeanConstructorInfo[0];
    final ModelMBeanNotificationInfo[] dNotifications = new ModelMBeanNotificationInfo[0];
    for (final Method method : _methods) {
        if (!_skippedMethodsSet.contains(method.getName())) {
            // process getter
            if (method.getParameterTypes().length == 0 && method.getName().startsWith("get")
                    && !method.getName().equals("get") && method.getReturnType() != void.class) {
                String attributeName = method.getName().substring(3);
                final Descriptor attributeDescriptor;
                final boolean isPoc = PerformanceCounter.class.isAssignableFrom(method.getReturnType());

                String measureUnitStr = null;
                if (method.isAnnotationPresent(MeasureUnit.class)) {
                    measureUnitStr = method.getAnnotation(MeasureUnit.class).value();
                }

                Method setter = null;
                Class setterSignatureClass = null;
                for (final Method method1 : _methods) {
                    if (method1.getParameterTypes().length == 1 && (method1.getName().startsWith("set"))
                            && (method1.getName().substring(NUMBER_3).equals(attributeName))) {
                        setter = method1;
                        setterSignatureClass = method1.getParameterTypes()[0];
                        break;
                    }
                }

                if (measureUnitStr != null) {
                    attributeName += (" (" + measureUnitStr + ") ");
                }

                if (setter != null) {
                    attributeDescriptor = new DescriptorSupport(
                            new String[] { "name=" + attributeName, "descriptorType=attribute",
                                    "getMethod=" + method.getName(), "setMethod=" + setter.getName(),
                                    "setterSignatureClass=" + setterSignatureClass.getName() });
                } else {
                    if (isPoc) {
                        attributeDescriptor = new DescriptorSupport(new String[] { "name=" + attributeName,
                                "descriptorType=attribute", "getMethod=" + method.getName() });
                    } else {
                        attributeDescriptor = new DescriptorSupport(new String[] { "name=" + attributeName,
                                "descriptorType=attribute", "getMethod=" + method.getName() });
                    }
                }
                try {
                    final ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attributeName,
                            attributeName, method, setter, attributeDescriptor);
                    attributesList.add(info);
                } catch (final IntrospectionException exception) {
                    _log.error("Error creating MBeanAttributeInfo [" + attributeName + "]", exception);
                }
            }
            // }
            final ModelMBeanOperationInfo info = new ModelMBeanOperationInfo("", method);
            operationsList.add(info);
        }
    }
    final ModelMBeanOperationInfo[] dOperations = operationsList
            .toArray(new ModelMBeanOperationInfo[operationsList.size()]);

    final ModelMBeanAttributeInfo[] dAttributes = attributesList
            .toArray(new ModelMBeanAttributeInfo[attributesList.size()]);

    final Descriptor beanDesc = new DescriptorSupport(
            new String[] { ("name=" + _objectName), "descriptorType=mbean", ("displayName=" + _beanName) });

    final ModelMBeanInfoSupport dMBeanInfo = new ModelMBeanInfoSupport(_beanName, "", dAttributes,
            dConstructors, dOperations, dNotifications, beanDesc);
    return dMBeanInfo;

}

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.
 * /* www . ja va2  s . 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.//from  w w  w. ja va2  s . c  om
 *
 * @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);
}