Example usage for javax.management.openmbean TabularData values

List of usage examples for javax.management.openmbean TabularData values

Introduction

In this page you can find the example usage for javax.management.openmbean TabularData values.

Prototype

public Collection<?> values();

Source Link

Document

Returns a collection view of the CompositeData values (ie the rows) contained in this TabularData instance.

Usage

From source file:Main.java

public static void appendTabularMap(Map map, CompositeData cdata, String fieldName) {
    Object tabularObject = cdata.get(fieldName);
    if (tabularObject instanceof TabularData) {
        TabularData tabularData = (TabularData) tabularObject;
        Collection<CompositeData> values = (Collection<CompositeData>) tabularData.values();
        for (CompositeData compositeData : values) {
            Object key = compositeData.get("key");
            Object value = compositeData.get("value");
            map.put(key, value);//w  ww.  j  ava  2  s. co  m
        }
    }
}

From source file:org.apache.hadoop.hbase.util.JSONBean.java

private static void writeObject(final JsonGenerator jg, final boolean description, Object value)
        throws IOException {
    if (value == null) {
        jg.writeNull();// w w  w  .  j  a v  a  2  s. co 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, description, 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, null, cds.get(key));
            }
            jg.writeEndObject();
        } else if (value instanceof TabularData) {
            TabularData tds = (TabularData) value;
            jg.writeStartArray();
            for (Object entry : tds.values()) {
                writeObject(jg, description, entry);
            }
            jg.writeEndArray();
        } else {
            jg.writeString(value.toString());
        }
    }
}

From source file:dk.netarkivet.common.utils.JMXUtils.java

/** Get a single CompositeData object out of a TabularData structure.
 *
 * @param items TabularData structure as returned from JMX calls.
 * @return The one item in the items structure.
 * @throws ArgumentNotValid if there is not exactly one item in items,
 * or items is null.//from w ww .  ja v  a2 s.  c o  m
 */
public static CompositeData getOneCompositeData(TabularData items) {
    ArgumentNotValid.checkNotNull(items, "TabularData items");
    ArgumentNotValid.checkTrue(items.size() == 1, "TabularData items should have 1 item");
    return (CompositeData) items.values().toArray()[0];
}

From source file:com.jkoolcloud.tnt4j.streams.custom.kafka.interceptors.reporters.metrics.MetricsReporter.java

protected static PropertySnapshot processAttrValue(PropertySnapshot snapshot, PropertyNameBuilder propName,
        Object value) {// w  w w . ja v  a  2  s . co m
    if (value instanceof CompositeData) {
        CompositeData cdata = (CompositeData) value;
        Set<String> keys = cdata.getCompositeType().keySet();
        boolean isKVSet = keys.contains("key") && keys.contains("value"); // NON-NLS
        for (String key : keys) {
            Object cVal = cdata.get(key);
            if (isKVSet && "key".equals(key)) { // NON-NLS
                propName.append(Utils.toString(cVal));
            } else if (isKVSet && "value".equals(key)) { // NON-NLS
                processAttrValue(snapshot, propName, cVal);
            } else {
                processAttrValue(snapshot, propName.append(key), cVal);
            }
        }
        propName.popLevel();
    } else if (value instanceof TabularData) {
        TabularData tData = (TabularData) value;
        Collection<?> values = tData.values();
        int row = 0;
        for (Object tVal : values) {
            processAttrValue(snapshot,
                    tVal instanceof CompositeData ? propName : propName.append(padNumber(++row)), tVal);
        }
        propName.popLevel();
    } else {
        snapshot.add(propName.propString(), value);
    }
    return snapshot;
}

From source file:com.stumbleupon.hbaseadmin.JMXQuery.java

protected StringBuffer recurseTabularData(StringBuffer buffer, String indent, String name, TabularData data) {
    addNameToBuffer(buffer, indent, name);
    final Collection c = data.values();
    for (Iterator i = c.iterator(); i.hasNext();) {
        final Object obj = i.next();
        if (obj instanceof CompositeData) {
            recurseCompositeData(buffer, indent + " ", "", (CompositeData) obj);
        } else if (obj instanceof TabularData) {
            recurseTabularData(buffer, indent, "", (TabularData) obj);
        } else {/*  ww w .  ja  va2s .c  om*/
            buffer.append(obj);
        }
    }
    return buffer;
}

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

private void writeObject(JsonGenerator jg, Object value) throws IOException {
    if (value == null) {
        jg.writeNull();//ww w .  j  ava2s.c  om
    } 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();/*from w  ww  .  j a  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();/*from   w  w w . j av a  2 s.co  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 if (value instanceof GaugeValue) {
            ((GaugeValue) value).serialize(jg);
        } else {
            jg.writeString(value.toString());
        }
    }
}

From source file:org.apache.qpid.systest.management.jmx.ConnectionManagementTest.java

private CompositeDataSupport getTheOneChannelRow(final ManagedConnection mBean) throws Exception {
    TabularData channelsData = getChannelsDataWithRetry(mBean);

    assertEquals("Unexpected number of rows in channel table", 1, channelsData.size());

    @SuppressWarnings("unchecked")
    final Iterator<CompositeDataSupport> rowItr = (Iterator<CompositeDataSupport>) channelsData.values()
            .iterator();//from  ww w  .  j  a  v a 2s  . co  m
    final CompositeDataSupport row = rowItr.next();
    return row;
}

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

private Object convertMxBeanMapToJson(TabularData pTd, Stack<String> pExtraArgs,
        ObjectToJsonConverter pConverter) throws AttributeNotFoundException {
    JSONObject ret = new JSONObject();
    for (Object rowObject : pTd.values()) {
        CompositeData row = (CompositeData) rowObject;
        Stack<String> path = (Stack<String>) pExtraArgs.clone();
        Object keyObject = row.get("key");
        if (keyObject != null) {
            try {
                Object value = pConverter.extractObject(row.get("value"), path, true);
                ret.put(keyObject.toString(), value);
            } catch (ValueFaultHandler.AttributeFilteredException exp) {
                // Skip to next object since attribute was filtered
            }//from  w  w w  .j a v a 2  s. c o m
        }
    }
    if (!pTd.isEmpty() && ret.isEmpty()) {
        // Bubble up if not a single thingy has been found
        throw new ValueFaultHandler.AttributeFilteredException();
    }
    return ret;
}