Example usage for javax.management.openmbean CompositeType keySet

List of usage examples for javax.management.openmbean CompositeType keySet

Introduction

In this page you can find the example usage for javax.management.openmbean CompositeType keySet.

Prototype

public Set<String> keySet() 

Source Link

Document

Returns an unmodifiable Set view of all the item names defined by this CompositeType instance.

Usage

From source file:com.streamsets.datacollector.bundles.content.SdcInfoContentGenerator.java

private void writeObject(JsonGenerator jg, Object value) throws IOException {
    if (value == null) {
        jg.writeNull();/* w w w .  ja  v a  2 s .  c o m*/
    } else {
        Class<?> c = value.getClass();
        if (c.isArray()) {
            jg.writeStartArray();
            int len = Array.getLength(value);
            for (int j = 0; j < len; j++) {
                Object item = Array.get(value, j);
                writeObject(jg, item);
            }
            jg.writeEndArray();
        } else if (value instanceof Number) {
            Number n = (Number) value;
            if (value instanceof Double && (((Double) value).isInfinite() || ((Double) value).isNaN())) {
                jg.writeString(n.toString());
            } else {
                jg.writeNumber(n.toString());
            }
        } else if (value instanceof Boolean) {
            Boolean b = (Boolean) value;
            jg.writeBoolean(b);
        } else if (value instanceof CompositeData) {
            CompositeData cds = (CompositeData) value;
            CompositeType comp = cds.getCompositeType();
            Set<String> keys = comp.keySet();
            jg.writeStartObject();
            for (String key : keys) {
                writeAttribute(jg, key, cds.get(key));
            }
            jg.writeEndObject();
        } else if (value instanceof TabularData) {
            TabularData tds = (TabularData) value;
            jg.writeStartArray();
            for (Object entry : tds.values()) {
                writeObject(jg, entry);
            }
            jg.writeEndArray();
        } else if (value instanceof GaugeValue) {
            ((GaugeValue) value).serialize(jg);
        } else {
            jg.writeString(value.toString());
        }
    }
}

From source file:org.apache.hadoop.jmx.JMXJsonServlet.java

private void writeObject(JsonGenerator jg, Object value) throws IOException {
    if (value == null) {
        jg.writeNull();//  w ww .ja  v a  2 s.c  o m
    } else {
        Class<?> c = value.getClass();
        if (c.isArray()) {
            jg.writeStartArray();
            int len = Array.getLength(value);
            for (int j = 0; j < len; j++) {
                Object item = Array.get(value, j);
                writeObject(jg, item);
            }
            jg.writeEndArray();
        } else if (value instanceof Number) {
            Number n = (Number) value;
            jg.writeNumber(n.toString());
        } else if (value instanceof Boolean) {
            Boolean b = (Boolean) value;
            jg.writeBoolean(b);
        } else if (value instanceof CompositeData) {
            CompositeData cds = (CompositeData) value;
            CompositeType comp = cds.getCompositeType();
            Set<String> keys = comp.keySet();
            jg.writeStartObject();
            for (String key : keys) {
                writeAttribute(jg, key, cds.get(key));
            }
            jg.writeEndObject();
        } else if (value instanceof TabularData) {
            TabularData tds = (TabularData) value;
            jg.writeStartArray();
            for (Object entry : tds.values()) {
                writeObject(jg, entry);
            }
            jg.writeEndArray();
        } else {
            jg.writeString(value.toString());
        }
    }
}

From source file:com.streamsets.datacollector.http.JMXJsonServlet.java

private void writeObject(JsonGenerator jg, Object value) throws IOException {
    if (value == null) {
        jg.writeNull();/*  w w  w.j ava2  s .com*/
    } else {
        Class<?> c = value.getClass();
        if (c.isArray()) {
            jg.writeStartArray();
            int len = Array.getLength(value);
            for (int j = 0; j < len; j++) {
                Object item = Array.get(value, j);
                writeObject(jg, item);
            }
            jg.writeEndArray();
        } else if (value instanceof Number) {
            Number n = (Number) value;
            jg.writeNumber(n.toString());
        } else if (value instanceof Boolean) {
            Boolean b = (Boolean) value;
            jg.writeBoolean(b);
        } else if (value instanceof CompositeData) {
            CompositeData cds = (CompositeData) value;
            CompositeType comp = cds.getCompositeType();
            Set<String> keys = comp.keySet();
            jg.writeStartObject();
            for (String key : keys) {
                writeAttribute(jg, key, cds.get(key));
            }
            jg.writeEndObject();
        } else if (value instanceof TabularData) {
            TabularData tds = (TabularData) value;
            jg.writeStartArray();
            for (Object entry : tds.values()) {
                writeObject(jg, entry);
            }
            jg.writeEndArray();
        } else if (value instanceof GaugeValue) {
            ((GaugeValue) value).serialize(jg);
        } else {
            jg.writeString(value.toString());
        }
    }
}

From source file:org.jolokia.converter.json.TabularDataExtractor.java

/**
 * Check whether the given tabular type represents a MXBean map. See the
 * {@link javax.management.MXBean} specification for
 * details how a map is converted to {@link TabularData} by the MXBean framework.
 *
 * @param pType type of tabular data to convert
 * @return true if this type represents an MXBean map, false otherwise.
 *//*from w w  w . jav a2 s  .c o m*/
private boolean checkForMxBeanMap(TabularType pType) {
    CompositeType rowType = pType.getRowType();
    return rowType.containsKey("key") && rowType.containsKey("value") && rowType.keySet().size() == 2
    // Only convert to map for simple types for all others use normal conversion. See #105 for details.
            && rowType.getType("key") instanceof SimpleType;
}

From source file:org.echocat.jemoni.carbon.jmx.Jmx2CarbonBridge.java

@Nullable
protected AttributeDefinition findDefinitionFor(@Nonnull ObjectName objectName,
        @Nonnull MBeanAttributeInfo info, @Nonnull String name, @Nonnull CompositeType compositeType) {
    final Set<AttributeDefinition> children = new HashSet<>();
    for (String key : compositeType.keySet()) {
        final OpenType<?> childType = compositeType.getType(key);
        final AttributeDefinition child = findDefinitionFor(objectName, info, key, childType);
        if (child != null) {
            children.add(child);/*  w w w.j  a va 2s. c om*/
        }
    }
    return children.isEmpty() ? null : new AttributeDefinition(objectName, name, CompositeData.class, children);
}

From source file:org.eclipse.gyrex.monitoring.internal.mbeans.MetricSetMBean.java

@Override
public Object getAttribute(final String attributeName)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    if (ID.equals(attributeName)) {
        return metricSet.getId();
    } else if (DESCRIPTION.equals(attributeName)) {
        return metricSet.getDescription();
    } else if (PROPERTIES.equals(attributeName)) {
        return properties;
    } else if (metricTypesByAttributeName.containsKey(attributeName)) {
        final CompositeType type = metricTypesByAttributeName.get(attributeName);
        final BaseMetric metric = metricByAttributeName.get(attributeName);
        if ((type != null) && (metric != null)) {
            final Map<String, ?> rawValues = metric.getAttributeValues();
            final String[] metricAttributeNames = type.keySet().toArray(new String[0]);
            final Object[] metricValues = new Object[metricAttributeNames.length];
            for (int i = 0; i < metricValues.length; i++) {
                Object rawValue = rawValues.get(metricAttributeNames[i]);
                // convert if necessary
                if (null != rawValue) {
                    final OpenType detectedTyp = detectType(rawValue.getClass());
                    if ((SimpleType.STRING == detectedTyp) && !(rawValue instanceof String)) {
                        rawValue = String.valueOf(rawValue);
                    }//from   w  w  w. ja v  a  2s .  c  om
                }
                metricValues[i] = rawValue;
            }
            try {
                return new CompositeDataSupport(type, metricAttributeNames, metricValues);
            } catch (final OpenDataException e) {
                throw new MBeanException(e);
            }
        }
    }

    throw new AttributeNotFoundException(String.format("attribute %s not found", attributeName));
}

From source file:com.appleframework.jmx.core.services.MBeanServiceImpl.java

/**
 * Expands a CompositeData object into individual attributes with the
 * naming convention:/*  w  ww .j a  v a 2s .co m*/
 * <p>
 * attributeName.itemName
 * <p>
 * The items should conform to given "dataType" array. These individual
 * attributes are added to the <code>attributeList</code>
 * @param attributesList    ObjectAttributeInfo instances are added to this
 *                          list
 */
private void handleCompositeData(ServerConnection connection, ObjectName objectName,
        ObjectAttributeInfo attrInfo, String[] dataTypes, List<ObjectAttributeInfo> attributesList) {

    CompositeType type = getCompositeType(connection, objectName, attrInfo);
    for (Iterator<?> it = type.keySet().iterator(); it.hasNext();) {
        String itemName = (String) it.next();
        OpenType<?> itemType = type.getType(itemName);
        Class<?> itemTypeClass = getClass(itemType.getClassName(), this.getClass().getClassLoader());
        for (int j = 0; j < dataTypes.length; j++) {
            Class<?> dataType = getClass(dataTypes[j], this.getClass().getClassLoader());
            if (dataType.isAssignableFrom(itemTypeClass)) {
                attributesList
                        .add(new ObjectAttributeInfo(attrInfo.getName() + COMPOSITE_ATTR_SEPARATOR + itemName,
                                type.getDescription(itemName), itemType.getClassName(), false, true, false));
            }
        }
    }
}

From source file:com.heliosapm.opentsdb.TSDBSubmitterImpl.java

/**
 * Decoposes the passed composite data instance to a map of numeric values keyed by the composite type key
 * @param cd The composite data instance
 * @return a map of numeric values keyed by the composite type key
 *//* w w  w . ja  v a 2  s.c o  m*/
protected Map<String, Number> fromOpenType(final CompositeData cd) {
    if (cd == null)
        return Collections.emptyMap();
    final Map<String, Number> map = new LinkedHashMap<String, Number>();
    final CompositeType ct = cd.getCompositeType();
    for (final String key : ct.keySet()) {
        final Object value = cd.get(key);
        if (value != null && (value instanceof Number)) {
            map.put(key, (Number) value);
        }
    }
    return map;
}

From source file:com.heliosapm.opentsdb.TSDBSubmitterImpl.java

/**
 * Decomposes a composite data type so it can be traced
 * @param objectName The ObjectName of the MBean the composite data came from
 * @param cd The composite data instance
 * @return A map of values keyed by synthesized ObjectNames that represent the structure down to the numeric composite data items
 *//*from ww w. j a  va2s.  c  o m*/
protected Map<ObjectName, Number> fromOpenType(final ObjectName objectName, final CompositeData cd) {
    if (objectName == null)
        throw new IllegalArgumentException("The passed ObjectName was null");
    if (cd == null)
        throw new IllegalArgumentException("The passed CompositeData was null");
    final Map<ObjectName, Number> map = new HashMap<ObjectName, Number>();
    final CompositeType ct = cd.getCompositeType();
    for (final String key : ct.keySet()) {
        final Object value = cd.get(key);
        if (value == null || !(value instanceof Number))
            continue;
        StringBuilder b = new StringBuilder(objectName.toString());
        b.append(",ctype=").append(simpleName(ct.getTypeName()));
        b.append(",metric=").append(key);
        ObjectName on = JMXHelper.objectName(clean(b));
        map.put(on, (Number) value);

    }
    return map;
}