Example usage for javax.management.openmbean CompositeData get

List of usage examples for javax.management.openmbean CompositeData get

Introduction

In this page you can find the example usage for javax.management.openmbean CompositeData get.

Prototype

public Object get(String key);

Source Link

Document

Returns the value of the item whose name is key .

Usage

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

@Test
public void compositeType() throws OpenDataException, AttributeNotFoundException, ParseException {
    CompositeTypeAndJson taj = new CompositeTypeAndJson(STRING, "verein", "FCN", INTEGER, "platz", 6, STRING,
            "trainer", null, BOOLEAN, "absteiger", false);
    for (Object input : new Object[] { taj.getJson(), taj.getJsonAsString() }) {
        CompositeData result = (CompositeData) converter.convertToObject(taj.getType(), input);
        assertEquals(result.get("verein"), "FCN");
        assertEquals(result.get("trainer"), null);
        assertEquals(result.get("platz"), 6);
        assertEquals(result.get("absteiger"), false);
        assertEquals(result.values().size(), 4);
    }// w w w . j  a v a2  s  .c o  m
}

From source file:com.haulmont.cuba.web.app.ui.statistics.ThreadsDatasource.java

protected String getStackTrace(Long threadId) {
    JmxInstance node = (JmxInstance) savedParameters.get("node");
    ManagedBeanInfo threadingBean = jmxControlAPI.getManagedBean(node, "java.lang:type=Threading");
    ManagedBeanOperation getThreadInfo = jmxControlAPI.getOperation(threadingBean, "getThreadInfo",
            new String[] { "long", "int" });
    CompositeData threadInfo = (CompositeData) jmxControlAPI.invokeOperation(getThreadInfo,
            new Object[] { threadId, Integer.MAX_VALUE });

    StringBuilder sb = new StringBuilder();
    if (threadInfo != null) {
        CompositeData[] traces = (CompositeData[]) threadInfo.get("stackTrace");
        ThreadSnapshot t = getThreadSnapshot(threadId);
        sb.append(t.getName()).append(" [id=").append(threadId).append("] (").append(t.getStatus())
                .append(")\n");
        for (CompositeData trace : traces) {
            String className = (String) trace.get("className");
            String methodName = (String) trace.get("methodName");
            int line = (int) trace.get("lineNumber");
            sb.append(className).append(".").append(methodName).append(":").append(line).append("\n");
        }//from www .  j  a  v a2 s.co m
    }
    return sb.toString();
}

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

@Test
public void multipleLevleTabularData() throws OpenDataException {
    JSONObject map = new JSONObject();
    JSONObject inner = new JSONObject();
    map.put("fcn", inner);
    JSONObject innerinner = new JSONObject();
    inner.put("franconia", innerinner);
    innerinner.put("verein", "fcn");
    innerinner.put("region", "franconia");
    innerinner.put("absteiger", false);

    TabularType type = new TabularType("soccer", "soccer",
            new CompositeType("row", "row", new String[] { "verein", "region", "absteiger" },
                    new String[] { "verein", "region", "absteiger" },
                    new OpenType[] { STRING, STRING, BOOLEAN }),
            new String[] { "verein", "region" });
    TabularData data = (TabularData) converter.convertToObject(type, map);
    CompositeData row = data.get(new Object[] { "fcn", "franconia" });
    assertNotNull(row);//w  w  w .j av a2  s. co m
    assertFalse((Boolean) row.get("absteiger"));
}

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
            }//  www.  j  a  va  2 s  .com
        }
    }
    if (!pTd.isEmpty() && ret.isEmpty()) {
        // Bubble up if not a single thingy has been found
        throw new ValueFaultHandler.AttributeFilteredException();
    }
    return ret;
}

From source file:org.apache.activemq.leveldb.test.ReplicatedLevelDBBrokerTest.java

private ArrayList<String> browseMessagesViaJMX(BrokerService brokerService) throws Exception {
    ArrayList<String> rc = new ArrayList<String>();
    ObjectName on = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + brokerService.getBrokerName()
            + ",destinationType=Queue,destinationName=FOO");
    CompositeData[] browse = (CompositeData[]) ManagementFactory.getPlatformMBeanServer().invoke(on, "browse",
            null, null);/*from   w ww .ja  va  2  s  .  c  o m*/
    for (CompositeData cd : browse) {
        rc.add(cd.get("Text").toString());
    }
    return rc;
}

From source file:com.tribloom.module.JmxClient.java

private void addCompositeData(Map<String, Object> model, CompositeData data, String name) {
    CompositeType type = data.getCompositeType();
    String typeName = type.getTypeName();
    echo("\naddCompositeData with type " + typeName);
    if (typeName.contains("MemoryUsage")) {
        model.put(name + "Committed", data.get("committed"));
        model.put(name + "Init", data.get("init"));
        model.put(name + "Max", data.get("max"));
        model.put(name + "Used", data.get("used"));
    } else if (typeName.contains("GcInfo")) {
        model.put(name + "Duration", data.get("duration"));
        model.put(name + "EndTime", data.get("endTime"));
        model.put(name + "StartTime", data.get("startTime"));
        model.put(name + "Id", data.get("id"));

        //         TabularData memUsageAfterGc = (TabularData) data.get("memoryUsageAfterGc");
        //         addTabularData(model, memUsageAfterGc, name + "MemoryUsageAfterGc");

        //         TabularData memoryUsageBeforeGc = (TabularData) data.get("memoryUsageBeforeGc");
        //         addTabularData(model, memoryUsageBeforeGc, name + "MemoryUsageBeforeGc");
    }/*from  w w w . ja v a  2 s  . c  o  m*/
}

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

/**
 * <p>/*from  w  w  w.  ja va2 s  . c o m*/
 *  Extract a {@link TabularData}. The JSON representation of a tabular data is different,
 *  depending on whether it represents a map for an {@link javax.management.MXBean} or is a regular data.
 * </p>
 * <p>
 *  I.e. for an tabular data which have a row type with two column "key" and "value", then
 *  a map is returned (with the "key" values as map keys and "value" values as map values).
 * </p>
 * <p>
 *  Otherwise a map of (one or more) maps is returned, where the map keys are taken
 *  from {@link TabularType} of the presented data. E.g. if there is a single valued key
 *  <code>"key"</code>, then the returned JSON looks like
 *  <pre>
 *      {
 *         "mykey1" : { "key" : "mkey1", "item" : "value1", .... }
 *         "mykey2" : { "key" : "mkey2", "item" : "value2", .... }
 *         ....
 *      }
 *  </pre>
 *  For multi valued keys of simple open types (i.e. {@link TabularType#getIndexNames()} is a list with more than one element), the
 *  returned JSON structure looks like (index names here are "key" and "innerkey")
 *  <pre>
 *      {
 *         "mykey1" : {
 *                       "myinner1" : { "key" : "mkey1", "innerkey" : "myinner1", "item" : "value1", .... }
 *                       "myinner2" : { "key" : "mkey1", "innerkey" : "myinner2", "item" : "value1", .... }
 *                       ....
 *                     }
 *         "mykey2" : {
 *                       "second1" : { "key" : "mkey2", "innerkey" : "second1", "item" : "value1", .... }
 *                       "second2" : { "key" : "mkey2", "innerkey" : "second2", "item" : "value1", .... }
 *                       ....
 *                    }
 *         ....
 *      }
 *  </pre>
 *  If keys are used, which themselves are complex objects (like composite data), this hierarchical map
 *  structure can not be used. In this case an object with two keys is returned: "indexNames" holds the
 *  name of the key index and "values" is an array of all rows which are represented as JSON objects:
 *  <pre>
 *      {
 *        "indexNames" : [ "key", "innerkey" ],
 *        "values" : [
 *           { "key" : "mykey1", "innerkey" : { "name" : "a", "number" : 4711 }, "item" : "value1", .... },
 *           { "key" : "mykey2", "innerkey" : { "name" : "b", "number" : 815 }, "item" : "value2", .... },
 *           ...
 *        ]
 *      }
 *  </pre>
 * </p>
 * <p>
 *   Accessing {@link TabularData} with a path is only supported for simple type keys, i.e. each index name must point
 *   to a string representation of a simple open type. As many path elements must be provided as index names for
 *   the tabular type exists (i.e. <code>pExtraArgs.size() >= pValue.getTabularType().getIndexNames().size()</code>)
 *
 *   For TabularData representing maps, a path access with the single "key" value will
 *   return the content of the "value" value. For all other TabularData, the complete row to which the path points
 *   is returned.
 * </p>
 * @param pConverter the global converter in order to be able do dispatch for
 *        serializing inner data types
 * @param pValue the value to convert
 * @param pPathParts extra arguments which contain e.g. a path
 * @param pJsonify whether to convert to a JSON object/list or whether the plain object
 *        should be returned. The later is required for writing an inner value
 * @return the extracted object
 * @throws AttributeNotFoundException
 */
public Object extractObject(ObjectToJsonConverter pConverter, Object pValue, Stack<String> pPathParts,
        boolean pJsonify) throws AttributeNotFoundException {
    TabularData td = (TabularData) pValue;
    String tdPath = pPathParts.isEmpty() ? null : pPathParts.pop();
    if (tdPath != null) {
        try {
            pPathParts.push(tdPath); // Need it later on for the index
            CompositeData cd = extractCompositeDataFromPath(td, pPathParts);
            return pConverter.extractObject(
                    cd != null && checkForMxBeanMap(td.getTabularType()) ? cd.get("value") : cd, pPathParts,
                    pJsonify);
        } catch (AttributeNotFoundException exp) {
            ValueFaultHandler faultHandler = pConverter.getValueFaultHandler();
            return faultHandler.handleException(exp);
        }
    } else {
        if (pJsonify) {
            return checkForMxBeanMap(td.getTabularType()) ? convertMxBeanMapToJson(td, pPathParts, pConverter)
                    : convertTabularDataToJson(td, pPathParts, pConverter);
        } else {
            return td;
        }
    }
}

From source file:com.zabbix.gateway.JMXItemChecker.java

private void findPrimitiveAttributes(JSONArray counters, ObjectName name, String descr, String attrPath,
        Object attribute) throws JSONException {
    logger.trace("drilling down with attribute path '{}'", attrPath);

    if (isPrimitiveAttributeType(attribute.getClass())) {
        logger.trace("found attribute of a primitive type: {}", attribute.getClass());

        JSONObject counter = new JSONObject();

        counter.put("{#JMXDESC}", null == descr ? name + "," + attrPath : descr);
        counter.put("{#JMXOBJ}", name);
        counter.put("{#JMXATTR}", attrPath);
        counter.put("{#JMXTYPE}", attribute.getClass().getName());
        counter.put("{#JMXVALUE}", attribute.toString());

        counters.put(counter);/* w w w  .  j a va2  s .co  m*/
    } else if (attribute instanceof CompositeData) {
        logger.trace("found attribute of a composite type: {}", attribute.getClass());

        CompositeData comp = (CompositeData) attribute;

        for (String key : comp.getCompositeType().keySet())
            findPrimitiveAttributes(counters, name, descr, attrPath + "." + key, comp.get(key));
    } else if (attribute instanceof TabularDataSupport) {
        logger.trace("found attribute of a known TabularDataSupport, unsupported type: {}",
                attribute.getClass());
    } else if (attribute.getClass().isArray()) {
        logger.trace("found attribute of a known, unsupported type: {}", attribute.getClass());
        Object[] array = (Object[]) attribute;
        for (Object obj : array) {
            logger.trace("Object value " + obj.toString());
            findPrimitiveAttributes(counters, name, descr, obj.toString(), obj);
        }
    } else
        logger.trace("found attribute of an unknown, unsupported type: {}", attribute.getClass());
}

From source file:org.wso2.carbon.analytics.common.jmx.agent.tasks.JmxTask.java

private ArrayList<Object> getMBeansDetail(JmxAgent jmxAgent) {
    ArrayList<Object> arrayList = new ArrayList<Object>();
    JMXConnector jmxConnector = null;
    try {//from   ww  w  .  j a v a 2 s. c o  m
        jmxConnector = jmxAgent.openJmxConnection();

        MBean[] mBeans = jmxAgent.getProfile().getSelectedMBeans();
        Object attrValue;
        for (MBean mBean : mBeans) {
            for (MBeanAttribute mBeanAttribute : mBean.getAttributes()) {
                // If MBean is a composite.
                if (mBeanAttribute.getProperties() != null) {
                    CompositeData cd = (CompositeData) jmxAgent.getAttribute(jmxConnector, mBean.getMBeanName(),
                            mBeanAttribute.getAttributeName());
                    for (MBeanAttributeProperty mBeanAttributeProperty : mBeanAttribute.getProperties()) {
                        attrValue = cd.get(mBeanAttributeProperty.getPropertyName());
                        addMBeanDetail(arrayList, attrValue);
                    }
                } else {
                    attrValue = jmxAgent.getAttribute(jmxConnector, mBean.getMBeanName(),
                            mBeanAttribute.getAttributeName());
                    addMBeanDetail(arrayList, attrValue);
                }
            }
        }
    } catch (JmxConnectionException e) {
        log.error("Jmx Connection Exception", e);
        return null;
    } catch (JmxMBeanException e) {
        log.error("Jmx MBean exception", e);
        return null;
    } finally {
        if (jmxConnector != null) {
            try {
                jmxAgent.closeJmxConnection(jmxConnector);
            } catch (JmxConnectionException e) {
                log.error("Unable to close JMX connection.", e);
            }
        }
    }
    return arrayList;
}

From source file:org.wso2.carbon.analytics.common.jmx.agent.tasks.JmxTask.java

private StreamDefinition createStreamDefinition(String streamName, String version, JmxAgent jmxAgent)
        throws MalformedStreamDefinitionException, JmxConnectionException, JmxMBeanException {

    StreamDefinition streamDefinition = new StreamDefinition(streamName, version);
    streamDefinition.setDescription("JMX monitoring data");
    streamDefinition.setNickName("JMX");
    List<Attribute> metaDataList = getMetaAttributeList();
    streamDefinition.setMetaData(metaDataList);
    List<Attribute> payloadDataList = new ArrayList<>();
    JMXConnector jmxConnector = null;
    try {/*from  w w w.  j a  va 2 s. co m*/
        jmxConnector = jmxAgent.openJmxConnection();
        MBean[] mBeans = jmxAgent.getProfile().getSelectedMBeans();
        //add the attributes
        Object attrValue;
        for (MBean mBean : mBeans) {
            for (MBeanAttribute mBeanAttribute : mBean.getAttributes()) {
                // If MBean is a composite.
                if (mBeanAttribute.getProperties() != null) {
                    CompositeData cd = (CompositeData) jmxAgent.getAttribute(jmxConnector, mBean.getMBeanName(),
                            mBeanAttribute.getAttributeName());
                    for (MBeanAttributeProperty mBeanAttributeProperty : mBeanAttribute.getProperties()) {
                        attrValue = cd.get(mBeanAttributeProperty.getPropertyName());
                        payloadDataList.add(getColumnName(attrValue, mBeanAttributeProperty.getAliasName()));
                    }
                } else {
                    attrValue = jmxAgent.getAttribute(jmxConnector, mBean.getMBeanName(),
                            mBeanAttribute.getAttributeName());
                    payloadDataList.add(getColumnName(attrValue, mBeanAttribute.getAliasName()));
                }
            }
        }
    } finally {
        if (jmxConnector != null) {
            try {
                jmxAgent.closeJmxConnection(jmxConnector);
            } catch (JmxConnectionException e) {
                log.error("Unable to close Jmx connection.", e);
            }
        }
    }
    streamDefinition.setPayloadData(payloadDataList);
    return streamDefinition;
}