Example usage for javax.management MBeanInfo getConstructors

List of usage examples for javax.management MBeanInfo getConstructors

Introduction

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

Prototype

public MBeanConstructorInfo[] getConstructors() 

Source Link

Document

Returns the list of the public constructors of the MBean.

Usage

From source file:Utilities.java

/**
 * Prints info about a bean to a {@link VarOutputSink}.
 * //from  w  w w  .  ja v a2  s  .c o m
 * @param sink The {@link VarOutputSink} to which info will be sent
 * @param mbs The {@link MBeanServer} with respect to which the
 *          {@code objectName} is accessed
 * @param objectName The {@link ObjectName} that identifies this bean
 */
public static void printMBeanInfo(VarOutputSink sink, MBeanServer mbs, ObjectName objectName) {
    MBeanInfo info = getMBeanInfoSafely(sink, mbs, objectName);
    if (info == null) {
        return;
    }

    sink.echo("\nCLASSNAME: \t" + info.getClassName());
    sink.echo("\nDESCRIPTION: \t" + info.getDescription());
    sink.echo("\nATTRIBUTES");
    MBeanAttributeInfo[] attrInfo = info.getAttributes();
    sink.printVariable("attrcount", Integer.toString(attrInfo.length));
    if (attrInfo.length > 0) {
        for (int i = 0; i < attrInfo.length; i++) {
            sink.echo(" ** NAME: \t" + attrInfo[i].getName());
            sink.echo("    DESCR: \t" + attrInfo[i].getDescription());
            sink.echo("    TYPE: \t" + attrInfo[i].getType() + "\tREAD: " + attrInfo[i].isReadable()
                    + "\tWRITE: " + attrInfo[i].isWritable());
        }
    } else
        sink.echo(" ** No attributes **");
    sink.echo("\nCONSTRUCTORS");
    MBeanConstructorInfo[] constrInfo = info.getConstructors();
    for (int i = 0; i < constrInfo.length; i++) {
        sink.echo(" ** NAME: \t" + constrInfo[i].getName());
        sink.echo("    DESCR: \t" + constrInfo[i].getDescription());
        sink.echo("    PARAM: \t" + constrInfo[i].getSignature().length + " parameter(s)");
    }
    sink.echo("\nOPERATIONS");
    MBeanOperationInfo[] opInfo = info.getOperations();
    if (opInfo.length > 0) {
        for (int i = 0; i < opInfo.length; i++) {
            sink.echo(" ** NAME: \t" + opInfo[i].getName());
            sink.echo("    DESCR: \t" + opInfo[i].getDescription());
            sink.echo("    PARAM: \t" + opInfo[i].getSignature().length + " parameter(s)");
        }
    } else
        sink.echo(" ** No operations ** ");
    sink.echo("\nNOTIFICATIONS");
    MBeanNotificationInfo[] notifInfo = info.getNotifications();
    if (notifInfo.length > 0) {
        for (int i = 0; i < notifInfo.length; i++) {
            sink.echo(" ** NAME: \t" + notifInfo[i].getName());
            sink.echo("    DESCR: \t" + notifInfo[i].getDescription());
            String notifTypes[] = notifInfo[i].getNotifTypes();
            for (int j = 0; j < notifTypes.length; j++) {
                sink.echo("    TYPE: \t" + notifTypes[j]);
            }
        }
    } else
        sink.echo(" ** No notifications **");
}

From source file:org.apache.hadoop.hbase.metrics.MetricsMBeanBase.java

protected void init() {
    List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>();
    MBeanInfo parentInfo = super.getMBeanInfo();
    List<String> parentAttributes = new ArrayList<String>();
    for (MBeanAttributeInfo attr : parentInfo.getAttributes()) {
        attributes.add(attr);//from w w w . j  a  v a  2  s  .co m
        parentAttributes.add(attr.getName());
    }

    this.registryLength = this.registry.getMetricsList().size();

    for (MetricsBase metric : this.registry.getMetricsList()) {
        if (metric.getName() == null || parentAttributes.contains(metric.getName()))
            continue;

        // add on custom HBase metric types
        if (metric instanceof MetricsRate) {
            attributes.add(new MBeanAttributeInfo(metric.getName(), "java.lang.Float", metric.getDescription(),
                    true, false, false));
            extendedAttributes.put(metric.getName(), metric);
        } else if (metric instanceof MetricsString) {
            attributes.add(new MBeanAttributeInfo(metric.getName(), "java.lang.String", metric.getDescription(),
                    true, false, false));
            extendedAttributes.put(metric.getName(), metric);
            LOG.info("MetricsString added: " + metric.getName());
        } else if (metric instanceof MetricsHistogram) {

            String metricName = metric.getName() + MetricsHistogram.NUM_OPS_METRIC_NAME;
            attributes.add(new MBeanAttributeInfo(metricName, "java.lang.Long", metric.getDescription(), true,
                    false, false));
            extendedAttributes.put(metricName, metric);

            metricName = metric.getName() + MetricsHistogram.MIN_METRIC_NAME;
            attributes.add(new MBeanAttributeInfo(metricName, "java.lang.Long", metric.getDescription(), true,
                    false, false));
            extendedAttributes.put(metricName, metric);

            metricName = metric.getName() + MetricsHistogram.MAX_METRIC_NAME;
            attributes.add(new MBeanAttributeInfo(metricName, "java.lang.Long", metric.getDescription(), true,
                    false, false));
            extendedAttributes.put(metricName, metric);

            metricName = metric.getName() + MetricsHistogram.MEAN_METRIC_NAME;
            attributes.add(new MBeanAttributeInfo(metricName, "java.lang.Float", metric.getDescription(), true,
                    false, false));
            extendedAttributes.put(metricName, metric);

            metricName = metric.getName() + MetricsHistogram.STD_DEV_METRIC_NAME;
            attributes.add(new MBeanAttributeInfo(metricName, "java.lang.Float", metric.getDescription(), true,
                    false, false));
            extendedAttributes.put(metricName, metric);

            metricName = metric.getName() + MetricsHistogram.MEDIAN_METRIC_NAME;
            attributes.add(new MBeanAttributeInfo(metricName, "java.lang.Float", metric.getDescription(), true,
                    false, false));
            extendedAttributes.put(metricName, metric);

            metricName = metric.getName() + MetricsHistogram.SEVENTY_FIFTH_PERCENTILE_METRIC_NAME;
            attributes.add(new MBeanAttributeInfo(metricName, "java.lang.Float", metric.getDescription(), true,
                    false, false));
            extendedAttributes.put(metricName, metric);

            metricName = metric.getName() + MetricsHistogram.NINETY_FIFTH_PERCENTILE_METRIC_NAME;
            attributes.add(new MBeanAttributeInfo(metricName, "java.lang.Float", metric.getDescription(), true,
                    false, false));
            extendedAttributes.put(metricName, metric);

            metricName = metric.getName() + MetricsHistogram.NINETY_NINETH_PERCENTILE_METRIC_NAME;
            attributes.add(new MBeanAttributeInfo(metricName, "java.lang.Float", metric.getDescription(), true,
                    false, false));
            extendedAttributes.put(metricName, metric);
        }
        // else, its probably a hadoop metric already registered. Skip it.
    }

    LOG.info("new MBeanInfo");
    this.extendedInfo = new MBeanInfo(this.getClass().getName(), this.description,
            attributes.toArray(new MBeanAttributeInfo[0]), parentInfo.getConstructors(),
            parentInfo.getOperations(), parentInfo.getNotifications());
}