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: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();//from  ww  w  .  ja  va  2 s  . 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, 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:org.jolokia.converter.util.TabularTypeAndJson.java

public TabularTypeAndJson(String[] index, CompositeTypeAndJson taj, Object... rowVals)
        throws OpenDataException {
    CompositeType cType = taj.getType();
    json = new JSONObject();
    addRow(json, taj.getJson(), index);//from   ww w .j a va 2s. co  m
    int nrCols = cType.keySet().size();
    for (int i = 0; i < rowVals.length; i += nrCols) {
        JSONObject row = new JSONObject();
        for (int j = 0; j < nrCols; j++) {
            row.put(taj.getKey(j), rowVals[i + j]);
        }
        addRow(json, row, index);
    }
    //System.out.println(json.toJSONString());
    type = new TabularType("test", "test", cType, index);
}

From source file:com.alibaba.dragoon.stat.WebStatisticManager.java

public TabularData getURIList() throws JMException {
    CompositeType rowType = WebURIStatistic.getCompositeType();
    String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);

    TabularType tabularType = new TabularType("URIStatisticList", "URIStatisticList", rowType, indexNames);
    TabularData data = new TabularDataSupport(tabularType);

    for (Map.Entry<String, WebURIStatistic> entry : this.statsMap.entrySet()) {
        if (entry.getValue().getCountDirect() == 0) {
            continue;
        }/*ww  w  . ja v a 2  s .c o  m*/

        data.put(entry.getValue().getCompositeData());
    }

    return data;
}

From source file:com.adobe.acs.commons.httpcache.store.caffeine.impl.CaffeineMemHttpCacheStoreImplTest.java

@Test
public void test_get_cache_entry_type() throws OpenDataException {
    CompositeType compositeType = caffeine.getCacheEntryType();
    assertEquals(7, compositeType.keySet().size());
}

From source file:com.adobe.acs.commons.httpcache.store.mem.impl.MemHttpCacheStoreImplTest.java

@Test
public void test_get_cache_entry_type() throws OpenDataException {
    CompositeType compositeType = systemUnderTest.getCacheEntryType();
    assertEquals(7, compositeType.keySet().size());
}

From source file:fr.openfarm.jmx.service.JMXQuery.java

@Override
public List<KeyResponse> getJmxKeys(String name, String attributeName)
        throws MalformedObjectNameException, NullPointerException, AttributeNotFoundException,
        InstanceNotFoundException, MBeanException, ReflectionException, IOException {
    List<KeyResponse> response = new ArrayList<KeyResponse>();
    ObjectName objectName = new ObjectName(name);
    Set<ObjectName> objectNameList = connection.queryNames(objectName, null);
    if (objectNameList != null && objectNameList.size() > 0) {
        objectName = objectNameList.iterator().next();
        Object attr = connection.getAttribute(objectName, attributeName);
        if (attr instanceof CompositeDataSupport) {
            CompositeDataSupport cds = (CompositeDataSupport) attr;
            CompositeType type = cds.getCompositeType();
            Set<String> listKey = type.keySet();
            for (Object key : listKey) {
                if (key instanceof String) {
                    Object value = cds.get((String) key);
                    KeyResponse keyResponse = new KeyResponse();
                    keyResponse.setKey(key.toString());
                    keyResponse.setValue(value.toString());
                    response.add(keyResponse);
                }//from   w  ww . j  ava  2  s  .  com
            }
        } else {
            KeyResponse keyResponse = new KeyResponse();
            keyResponse.setValue(attr.toString());
            response.add(keyResponse);
        }
    }
    return response;
}

From source file:fr.openfarm.jmx.service.JMXQuery.java

@Override
public GetMultiObjectKeysResponse getWildcardJmxKeys(String name, String attributeName)
        throws MalformedObjectNameException, NullPointerException, AttributeNotFoundException,
        InstanceNotFoundException, MBeanException, ReflectionException, IOException {
    GetMultiObjectKeysResponse reponse = new GetMultiObjectKeysResponse();
    ArrayList<MultiObjectKeys> multiObjectKeysList = new ArrayList<MultiObjectKeys>();

    ObjectName objectName = new ObjectName(name);
    Set<ObjectName> objectNameList = connection.queryNames(objectName, null);
    for (ObjectName iterObject : objectNameList) {
        objectName = iterObject;/*from  w  ww .j a va2 s .  c o m*/
        List<KeyResponse> keyList = new ArrayList<KeyResponse>();
        Object attr = connection.getAttribute(objectName, attributeName);
        if (attr instanceof CompositeDataSupport) {
            CompositeDataSupport cds = (CompositeDataSupport) attr;
            CompositeType type = cds.getCompositeType();
            Set<String> listKey = type.keySet();
            for (Object key : listKey) {
                if (key instanceof String) {
                    Object value = cds.get((String) key);
                    KeyResponse keyResponse = new KeyResponse();
                    keyResponse.setKey(key.toString());
                    keyResponse.setValue(value.toString());
                    keyList.add(keyResponse);
                }
            }
        } else {
            KeyResponse keyResponse = new KeyResponse();
            keyResponse.setValue(attr.toString());
            keyList.add(keyResponse);
        }
        MultiObjectKeys multiObjectKeys = new MultiObjectKeys();
        multiObjectKeys.setJmxKeys(keyList);
        multiObjectKeys.setObjectName(objectName.getCanonicalName());
        multiObjectKeysList.add(multiObjectKeys);
    }
    reponse.setMultiObjectKeys(multiObjectKeysList);
    return reponse;
}

From source file:org.jolokia.converter.object.CompositeTypeConverter.java

private void completeCompositeValuesWithDefaults(CompositeType pType, Map<String, Object> pCompositeValues) {
    /* fields that were not given in the JSON must be added with
     * null for Objects and the default value for primitives
     *//*from  w w  w .jav  a  2s.  c o m*/
    for (String itemName : pType.keySet()) {
        if (!pCompositeValues.containsKey(itemName)) {
            Object itemValue = null;
            OpenType itemType = pType.getType(itemName);
            if (itemType instanceof SimpleType) {
                SimpleType sType = (SimpleType) itemType;
                itemValue = DEFAULT_PRIMITIVE_VALUES.get(sType.getClassName());
            }
            pCompositeValues.put(itemName, itemValue);
        }
    }
}

From source file:it.jnrpe.plugin.jmx.CCheckJMX.java

@Override
protected Collection<Metric> gatherMetrics(ICommandLine cl) throws MetricGatheringException {
    Collection<Metric> metrics = new ArrayList<Metric>(super.gatherMetrics(cl));
    if (this.getInfoData() == null || this.getVerbatim() >= 2) {
        String metricName = getCheckName();
        if (this.getCheckData() instanceof Number) {
            metrics.add(//  w  w w . j  av a 2  s. com
                    MetricBuilder.forMetric(metricName).withMessage(metricName + " is {0}", this.getCheckData())
                            .withValue((Number) this.getCheckData()).build());
        } else {
            metrics.add(MetricBuilder.forMetric(metricName)
                    .withMessage(metricName + " is {0}", this.getCheckData()).withValue(0).build());
        }
        LOG.debug(getContext(), "Created metric : " + metricName);
    }
    if (this.getInfoData() != null) {
        String metricName = getInfo_attribute();
        if (this.getInfoData() instanceof CompositeDataSupport) {
            CompositeDataSupport data = (CompositeDataSupport) this.getInfoData();
            CompositeType type = data.getCompositeType();
            for (Iterator<String> it = type.keySet().iterator(); it.hasNext();) {
                String key = (String) it.next();
                if (data.containsKey(key) && !getCheckName().equals(metricName + "." + key)) {
                    if (data.get(key) instanceof Number) {
                        metrics.add(MetricBuilder.forMetric(metricName + "." + key)
                                .withMessage(metricName + "." + key + " is {0}", data.get(key))
                                .withValue((Number) data.get(key)).build());
                    } else {
                        metrics.add(MetricBuilder.forMetric(metricName + "." + key)
                                .withMessage(metricName + "." + key + " is {0}", data.get(key)).withValue(0)
                                .build());
                    }
                    LOG.debug(getContext(), "Created metric : " + metricName + "." + key);
                }
            }
        } else {
            if (this.getInfoData() instanceof Number) {
                metrics.add(MetricBuilder.forMetric(metricName)
                        .withMessage("info is {0}", this.getCheckData().toString())
                        .withValue((Number) this.getInfoData()).build());
            } else {
                metrics.add(MetricBuilder.forMetric(metricName)
                        .withMessage("info is {0}", this.getCheckData().toString()).withValue(0).build());
            }
            LOG.debug(getContext(), "Created metric : " + "info");
        }
    }

    return metrics;
}

From source file:org.jolokia.converter.object.TabularDataConverter.java

private boolean checkForMapValue(TabularType pType) {
    CompositeType rowType = pType.getRowType();
    // Two entries in the row: "key" and "value"
    return rowType.containsKey(TD_KEY_VALUE) && rowType.containsKey(TD_KEY_KEY) && rowType.keySet().size() == 2;
}