Example usage for javax.management.openmbean CompositeDataSupport get

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

Introduction

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

Prototype

public Object get(String key) 

Source Link

Document

Returns the value of the item whose name is key .

Usage

From source file:com.athena.dolly.console.module.jmx.JmxClientManager.java

public static MemoryVo getMemoryUsage(String nodeName) {
    JmxClient jmxClient = jmxClientMap.get(nodeName);

    MemoryVo memory = null;//  ww w  . jav  a  2s. c  om
    try {
        ObjectName objectName = new ObjectName("java.lang:type=Memory");

        MBeanServerConnection connection = jmxClient.getJmxConnector().getMBeanServerConnection();
        CompositeDataSupport heapMemoryUsage = (CompositeDataSupport) connection.getAttribute(objectName,
                "HeapMemoryUsage");

        memory = new MemoryVo();
        memory.setCommitted((Long) heapMemoryUsage.get("committed"));
        memory.setInit((Long) heapMemoryUsage.get("init"));
        memory.setMax((Long) heapMemoryUsage.get("max"));
        memory.setUsed((Long) heapMemoryUsage.get("used"));

        logger.debug("nodeName: [{}], memoryUsage: [committed: {}, init:{}, max:{}, used:{}]", new Object[] {
                nodeName, memory.getCommitted(), memory.getInit(), memory.getMax(), memory.getUsed() });
    } catch (Exception e) {
        logger.error("unhandled exception has errored : ", e);
    }

    return memory;
}

From source file:com.dsf.dbxtract.cdc.AppJournalWindowTest.java

@Test(dependsOnMethods = { "testAppWithJournalWindow" })
public void testInfoStatistics() throws Exception {

    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:5000/jmxrmi");
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    ObjectName mbeanName = new ObjectName("com.dsf.dbxtract:type=InfoMBean");

    TabularDataSupport info = (TabularDataSupport) mbsc.getAttribute(mbeanName, InfoMBean.ATTR_INFO);
    Collection<?> list = info.values();
    boolean hasHandlerEntry = false;
    for (Iterator<?> it = list.iterator(); it.hasNext();) {
        CompositeDataSupport entry = (CompositeDataSupport) it.next();

        if (entry.get("handler").equals(TestWindowHandler.class.getName())) {
            assert (((Long) entry.get("readCount")).longValue() == TEST_SIZE);
            hasHandlerEntry = true;//from ww w  .java2s  . c  o m
        }
    }
    assert (hasHandlerEntry);
    jmxc.close();
}

From source file:com.tomcat.monitor.jmx.obj.bean.MServer.java

/**
 * getValue form OpenMBean Value FIXME: SimpleType Umwandlung in skalare
 * Datentypen FIXME: Suche eine elegante Moeglichkeit an den Wert eines
 * Attributes in einem OpenMBean heranzukommen (BeanUtils...)?
 * <p/>/*from   w  w w  .  j a  v  a 2  s. c  om*/
 * <p/>
 * Beispiele: attribute1 [key1] attribute1.attribute2 [key].attribute1
 * [key1].[key2] [key1].attribute1.[key2].attribute2
 * 
 * @param attributePath
 *           path to Mbean OpenMbean attribute
 * @param bean
 *           current value
 */
public Object accessValue(String attributePath, Object bean) {
    if (attributePath == null || "".equals(attributePath))
        return null;
    if (bean instanceof CompositeDataSupport) {
        CompositeDataSupport data = (CompositeDataSupport) bean;
        // FIXME This only supports direct key access
        return data.get(attributePath);
    } else if (bean instanceof TabularDataSupport) {
        TabularDataSupport data = (TabularDataSupport) bean;
        if (attributePath.startsWith("[")) {
            int endIndex = attributePath.indexOf("]");
            if (endIndex > 1) {
                String attributeKey = attributePath.substring(1, endIndex);
                CompositeData valuedata = data.get(new Object[] { attributeKey });
                Object value = valuedata.get("value");
                OpenType<?> type = valuedata.getCompositeType().getType("value");
                if (type instanceof SimpleType) {
                    // FIXME Es fehlt noch die Prfung ob attributePath
                    // nicht false ist, sprich das nach [].<xxxx> gefragt
                    // wahr.
                    return value;
                } else {
                    String nextAttributePath = attributePath.substring(endIndex);
                    if (nextAttributePath.startsWith(".")) {
                        // FIXME stimmt das oder endIndex
                        return accessValue(attributePath.substring(endIndex + 1), value);
                    }
                }
            }
        }
    }
    return null;
}

From source file:io.github.albertopires.mjc.JConsoleM.java

public long getEdenUsage(ServerConfiguration serverConfiguration) throws Exception {
    ObjectName mbeanName = null;//from   w  ww. j  a v  a 2s . c o m
    if (serverConfiguration.getJdkVersion().equals(JdkVersion.JDK6)) {
        mbeanName = new ObjectName("java.lang:type=MemoryPool,name=Par Eden Space");
    } else if (serverConfiguration.getJdkVersion().equals(JdkVersion.JDK8)) {
        mbeanName = new ObjectName("java.lang:type=MemoryPool,name=G1 Eden Space");
    }
    CompositeDataSupport o;
    o = (CompositeDataSupport) mbsc.getAttribute(mbeanName, "Usage");
    return ((Long) o.get("used")).longValue();
}

From source file:io.github.albertopires.mjc.JConsoleM.java

public long getHeapUsage() throws Exception {
    ObjectName mbeanName;//from w w w  .java2s.c om
    mbeanName = new ObjectName("java.lang:type=Memory");
    CompositeDataSupport o;
    o = (CompositeDataSupport) mbsc.getAttribute(mbeanName, "HeapMemoryUsage");
    return ((Long) o.get("used")).longValue();
}

From source file:io.github.albertopires.mjc.JConsoleM.java

public long getCMSUsage(ServerConfiguration serverConfiguration) throws Exception {
    ObjectName mbeanName = null;//from ww w .j ava2 s  .  c  om
    if (serverConfiguration.getJdkVersion().equals(JdkVersion.JDK6)) {
        mbeanName = new ObjectName("java.lang:type=MemoryPool,name=CMS Old Gen");
        CompositeDataSupport o;
        o = (CompositeDataSupport) mbsc.getAttribute(mbeanName, "Usage");
        return ((Long) o.get("used")).longValue();
    } else {
        return 0L;
    }
}

From source file:io.github.albertopires.mjc.JConsoleM.java

public Long getNonHeapUsage() throws Exception {
    ObjectName mbeanName;/*from  w w  w .j  av  a  2 s  .com*/
    mbeanName = new ObjectName("java.lang:type=Memory");
    CompositeDataSupport o;
    o = (CompositeDataSupport) mbsc.getAttribute(mbeanName, "NonHeapMemoryUsage");
    return Long.valueOf(o.get("used").toString());
}

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

@Override
public String getJmxData(String name, String attributeName, String key)
        throws MalformedObjectNameException, NullPointerException, AttributeNotFoundException,
        InstanceNotFoundException, MBeanException, ReflectionException, IOException {
    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;
            if (key == null) {
                throw new IllegalArgumentException("Key is null for composed data " + name);
            }// w  w w. j  a va  2s  .co  m
            return cds.get(key).toString();

        } else {
            return attr.toString();
        }
    }
    return null;
}

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);
                }/*www. j  a va2s  .  co m*/
            }
        } 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;//  w  w w.  j  a v  a2 s. co 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;
}