Example usage for javax.management MBeanParameterInfo MBeanParameterInfo

List of usage examples for javax.management MBeanParameterInfo MBeanParameterInfo

Introduction

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

Prototype

public MBeanParameterInfo(String name, String type, String description) 

Source Link

Document

Constructs an MBeanParameterInfo object.

Usage

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

private static MBeanParameterInfo[] extractParameterInfo(Method m) {
    Class<?>[] types = m.getParameterTypes();
    Annotation[][] annotations = m.getParameterAnnotations();
    MBeanParameterInfo[] params = new MBeanParameterInfo[types.length];
    for (int i = 0; i < params.length; i++) {
        boolean hasAnnotation = false;
        for (int j = 0; j < annotations[i].length; j++) {
            if (annotations[i][j] instanceof JmxParam) {
                JmxParam param = (JmxParam) annotations[i][j];
                params[i] = new MBeanParameterInfo(param.name(), types[i].getName(), param.description());
                hasAnnotation = true;/*from   www.  j  a  v  a2  s  .c om*/
                break;
            }
        }
        if (!hasAnnotation) {
            params[i] = new MBeanParameterInfo("", types[i].getName(), "");
        }
    }

    return params;
}

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 a  va 2  s. c o  m*/
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.echocat.jemoni.jmx.support.CacheDynamicMBean.java

@Nonnull
protected MBeanOperationInfo[] getOperations() {
    final List<MBeanOperationInfo> result = new ArrayList<>();
    result.add(new MBeanOperationInfo("get", null,
            new MBeanParameterInfo[] { new MBeanParameterInfo("key", String.class.getName(), null) },
            String.class.getName(), ACTION));
    result.add(new MBeanOperationInfo("remove", null,
            new MBeanParameterInfo[] { new MBeanParameterInfo("key", String.class.getName(), null) },
            Void.TYPE.getName(), ACTION));
    result.add(new MBeanOperationInfo("contains", null,
            new MBeanParameterInfo[] { new MBeanParameterInfo("key", String.class.getName(), null) },
            Boolean.TYPE.getName(), ACTION));
    if (_cache instanceof KeysEnabledCache) {
        result.add(new MBeanOperationInfo("getKeys", null,
                new MBeanParameterInfo[] { new MBeanParameterInfo("limit", Integer.class.getName(), null) },
                String.class.getName(), ACTION));
    }/* w w w  .java  2 s.  com*/
    if (_cache instanceof ClearableCache) {
        result.add(
                new MBeanOperationInfo("clear", null, new MBeanParameterInfo[0], Void.TYPE.getName(), ACTION));
    }
    if (_cache instanceof StatisticsEnabledCache) {
        result.add(new MBeanOperationInfo("resetStatistics", null, new MBeanParameterInfo[0],
                Void.TYPE.getName(), ACTION));
    }
    if (_cache instanceof ListenerEnabledCache) {
        result.add(new MBeanOperationInfo("getListeners", null, new MBeanParameterInfo[0],
                String.class.getName(), ACTION));
    }
    return result.toArray(new MBeanOperationInfo[result.size()]);
}

From source file:org.parallelj.launching.transport.jmx.DynamicLegacyProgram.java

/**
 * Default constructor//w w  w. ja  v a  2 s .  c  o m
 * 
 * @param adapterClass
 *            the Program's adapter type
 * @param adapterArgs
 */
public DynamicLegacyProgram(RemoteProgram remoteProgram) {
    this.remoteProgram = remoteProgram;

    // Get all available Commands
    this.cmds = JmxCommands.getCommands().values().toArray(new JmxCommand[] {});
    Arrays.sort(this.cmds);

    this.operations = new MBeanOperationInfo[this.cmds.length];
    int opIndex = 0;
    for (JmxCommand cmd : this.cmds) {
        final List<MBeanParameterInfo> parameters = new ArrayList<MBeanParameterInfo>();
        for (JmxOption option : JmxOptions.getOptions()) {
            // Options "id" and "args" doesn't have to be shown using Jmx
            final MBeanParameterInfo param = new MBeanParameterInfo(option.getName(), "java.lang.String",
                    option.getDescription());
            parameters.add(param);
        }
        final MBeanOperationInfo operation = new MBeanOperationInfo(cmd.getType(), cmd.getUsage(),
                ArrayUtils.addAll(parameters.toArray(new MBeanParameterInfo[] {}), createMBeanParameterInfos()),
                "java.lang.String", MBeanOperationInfo.INFO);
        operations[opIndex++] = operation;
    }
}

From source file:org.parallelj.launching.transport.jmx.DynamicLegacyProgram.java

/**
 * Generate MBean parameter info for all Program field annotated with @In
 * /*ww  w  . j  ava2 s .co m*/
 * @return an array of MBeanParameterInfo
 */
private MBeanParameterInfo[] createMBeanParameterInfos() {
    final int lenght = this.remoteProgram.getArguments() != null ? this.remoteProgram.getArguments().size() : 0;
    int cpt = 0;
    MBeanParameterInfo[] result = new MBeanParameterInfo[lenght];
    if (this.remoteProgram.getArguments() != null) {
        for (Argument arg : this.remoteProgram.getArguments()) {
            // Only simple Type are authorized for JMX
            String type = null;

            String descriptionWithParserFormat = "Parser  '%s' will be used to set this parameter as it is defined in @In annotation for this field.";
            String descriptionWithoutParserFormat = "No parser will be used for this field as it is a primitive one.";
            String descriptionValueValue = descriptionWithoutParserFormat;
            if (!arg.getParser().getCanonicalName().equals(NopParser.class.getCanonicalName())) {
                descriptionValueValue = String.format(descriptionWithParserFormat,
                        arg.getParser().getCanonicalName());
            }
            if (!arg.getType().equals(String.class) && !arg.getType().equals(int.class)
                    && !arg.getType().equals(long.class) && !arg.getType().equals(boolean.class)) {
                type = String.class.getCanonicalName();
            } else {
                type = arg.getType().getCanonicalName();
            }

            result[cpt++] = new MBeanParameterInfo(arg.getName(), type, descriptionValueValue);
        }
    }
    return result;
}

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.//  www.  j  a v  a2s .  com
 *
 * @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);
}