Example usage for javax.management.modelmbean ModelMBeanOperationInfo ModelMBeanOperationInfo

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

Introduction

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

Prototype


public ModelMBeanOperationInfo(String name, String description, MBeanParameterInfo[] signature, String type,
        int impact) 

Source Link

Document

Constructs a ModelMBeanOperationInfo object with a default descriptor.

Usage

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

private static ModelMBeanOperationInfo[] extractOperationInfo(Object object) {
    ArrayList<ModelMBeanOperationInfo> infos = new ArrayList<ModelMBeanOperationInfo>();
    for (Method m : object.getClass().getMethods()) {
        JmxOperation jmxOperation = m.getAnnotation(JmxOperation.class);
        JmxGetter jmxGetter = m.getAnnotation(JmxGetter.class);
        JmxSetter jmxSetter = m.getAnnotation(JmxSetter.class);
        if (jmxOperation != null || jmxGetter != null || jmxSetter != null) {
            String description = "";
            int visibility = 1;
            int impact = MBeanOperationInfo.UNKNOWN;
            if (jmxOperation != null) {
                description = jmxOperation.description();
                impact = jmxOperation.impact();
            } else if (jmxGetter != null) {
                description = jmxGetter.description();
                impact = MBeanOperationInfo.INFO;
                visibility = 4;/*from www .  j ava  2s . c o  m*/
            } else if (jmxSetter != null) {
                description = jmxSetter.description();
                impact = MBeanOperationInfo.ACTION;
                visibility = 4;
            }
            ModelMBeanOperationInfo info = new ModelMBeanOperationInfo(m.getName(), description,
                    extractParameterInfo(m), m.getReturnType().getName(), impact);
            info.getDescriptor().setField("visibility", Integer.toString(visibility));
            infos.add(info);
        }
    }

    return infos.toArray(new ModelMBeanOperationInfo[infos.size()]);
}

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

/** Define an operation on the managed object.
 * Defines an operation with parameters. Refection is used to
 * determine find the method and it's return type. The description
 * of the method is found with a call to findDescription on
 * "name(signature)". The name and description of each parameter
 * is found with a call to findDescription with
 * "name(partialSignature", the returned description is for the
 * last parameter of the partial signature and is assumed to start
 * with the parameter name, followed by a colon.
 * @param name The name of the method call.
 * @param signature The types of the operation parameters.
 * @param impact Impact as defined in MBeanOperationInfo
 * @param onMBean true if the operation is defined on the mbean
 *//*from  www  .  j av a  2 s.com*/
public synchronized void defineOperation(String name, String[] signature, int impact, boolean onMBean) {
    _dirty = true;
    Class oClass = onMBean ? this.getClass() : _object.getClass();
    if (signature == null)
        signature = new String[0];

    try {
        Class[] types = new Class[signature.length];
        MBeanParameterInfo[] pInfo = new MBeanParameterInfo[signature.length];

        // Check types and build methodKey
        String methodKey = name + "(";
        for (int i = 0; i < signature.length; i++) {
            Class type = TypeUtil.fromName(signature[i]);
            if (type == null)
                type = Thread.currentThread().getContextClassLoader().loadClass(signature[i]);
            types[i] = type;
            signature[i] = type.isPrimitive() ? TypeUtil.toName(type) : signature[i];
            methodKey += (i > 0 ? "," : "") + signature[i];
        }
        methodKey += ")";

        // Build param infos
        for (int i = 0; i < signature.length; i++) {
            String description = findDescription(methodKey + "[" + i + "]");
            int colon = description.indexOf(":");
            if (colon < 0) {
                description = "param" + i + ":" + description;
                colon = description.indexOf(":");
            }
            pInfo[i] = new MBeanParameterInfo(description.substring(0, colon).trim(), signature[i],
                    description.substring(colon + 1).trim());
        }

        // build the operation info
        Method method = oClass.getMethod(name, types);
        Class returnClass = method.getReturnType();
        _method.put(methodKey, method);
        _operations.add(new ModelMBeanOperationInfo(name, findDescription(methodKey), pInfo,
                returnClass.isPrimitive() ? TypeUtil.toName(returnClass) : (returnClass.getName()), impact));
    } catch (Exception e) {
        log.warn("operation " + name, e);
        throw new IllegalArgumentException(e.toString());
    }

}

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.
 * //from w w w  .  jav a 2  s.c  o  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 ww  w .ja v  a  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);
}