Search in sources :

Example 41 with CompositeData

use of javax.management.openmbean.CompositeData in project tdi-studio-se by Talend.

the class SWTResourceMonitor method refreshResourcesCache.

/*
     * @see ISWTResourceMonitor#refreshResourcesCache()
     */
@Override
public void refreshResourcesCache() throws JvmCoreException {
    resources.clear();
    ObjectName objectName = validateAgent();
    if (objectName != null) {
        Object attribute = jvm.getMBeanServer().getAttribute(objectName, RESOURCES);
        if (attribute instanceof CompositeData[]) {
            resources = new ArrayList<ISWTResourceElement>(getSWTResourceElements((CompositeData[]) attribute));
        }
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ObjectName(javax.management.ObjectName) ISWTResourceElement(org.talend.designer.runtime.visualization.ISWTResourceElement)

Example 42 with CompositeData

use of javax.management.openmbean.CompositeData in project tdi-studio-se by Talend.

the class AttributeContentProvider method addAttributeItems.

/**
     * Adds the attribute to the given list.
     * 
     * @param parent The parent attribute
     * @param value The value
     */
private void addAttributeItems(AttributeNode parent, Object value) {
    if (value instanceof CompositeData) {
        CompositeData compositeData = (CompositeData) value;
        CompositeType type = compositeData.getCompositeType();
        for (String key : type.keySet()) {
            AttributeNode attribute = new AttributeNode(key, parent);
            parent.addChild(attribute);
            addAttributeItems(attribute, compositeData.get(key));
        }
    } else if (value instanceof TabularData) {
        TabularData tabularData = (TabularData) value;
        for (Object keyList : tabularData.keySet()) {
            @SuppressWarnings("unchecked") Object[] keys = ((List<Object>) keyList).toArray(new Object[0]);
            AttributeNode attribute = new AttributeNode(String.valueOf(keys[0]), parent);
            parent.addChild(attribute);
            addAttributeItems(attribute, tabularData.get(keys));
        }
    } else if (value instanceof Long || value instanceof Integer || value instanceof Double) {
        parent.setRgb(getRGB(parent.getQualifiedName()));
        parent.setValidLeaf(true);
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Example 43 with CompositeData

use of javax.management.openmbean.CompositeData in project tdi-studio-se by Talend.

the class OverviewContentProvider method toArray.

/**
     * Gets the array corresponding to the given tabular data.
     * 
     * @param tabularData
     *            The tabular data
     * @return The array
     */
private Object[] toArray(TabularData tabularData) {
    List<OverviewProperty> list = new ArrayList<OverviewProperty>();
    for (Object object : tabularData.values()) {
        if (object instanceof CompositeData) {
            CompositeData compositeData = (CompositeData) object;
            String[] elements = compositeData.values().toArray(new String[0]);
            OverviewProperty property = getProperty(elements[0]);
            if (property == null) {
                property = new OverviewProperty(OverviewCategory.Runtime, elements[0], elements[0], false);
            }
            property.setValue(elements[1]);
            list.add(property);
        }
    }
    Collections.sort(list, new Comparator<OverviewProperty>() {

        @Override
        public int compare(OverviewProperty o1, OverviewProperty o2) {
            return o1.getDisplayName().compareTo(o2.getDisplayName());
        }
    });
    systemProperties = list;
    return systemProperties.toArray(new OverviewProperty[systemProperties.size()]);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList)

Example 44 with CompositeData

use of javax.management.openmbean.CompositeData in project tdi-studio-se by Talend.

the class OverviewProperty method getValueString.

/**
     * Gets the string representation of value.
     * 
     * @return The string representation of value
     */
protected String getValueString() {
    if (value == null) {
        //$NON-NLS-1$
        return "";
    }
    if (value instanceof String[]) {
        StringBuffer buffer = new StringBuffer();
        for (String element : (String[]) value) {
            buffer.append(element).append(' ');
        }
        return buffer.toString();
    }
    if (value instanceof CompositeData) {
        if (!attributeName.contains(".")) {
            //$NON-NLS-1$
            return "";
        }
        CompositeData compositeData = (CompositeData) value;
        //$NON-NLS-1$
        String[] elements = attributeName.split("\\.");
        String compositeDataKey = elements[elements.length - 1];
        value = compositeData.get(compositeDataKey);
    }
    if (value instanceof String) {
        //$NON-NLS-1$ //$NON-NLS-2$
        return ((String) value).replace("\n", "\\n");
    }
    if (value instanceof Long) {
        if (format != null) {
            return format.format(value);
        }
    }
    if (value instanceof TabularData) {
        //$NON-NLS-1$
        return "";
    }
    return value.toString();
}
Also used : CompositeData(javax.management.openmbean.CompositeData) TabularData(javax.management.openmbean.TabularData)

Example 45 with CompositeData

use of javax.management.openmbean.CompositeData in project ats-framework by Axway.

the class SystemOperations method getJvmMbeans.

/**
     * @param host the address of the host machine
     * @param jmxPort the jmx port
     * 
     * @return all MBeans with their attributes and type
     * @throws SystemOperationException
     */
@PublicAtsApi
public String getJvmMbeans(String host, String jmxPort) {
    JMXConnector jmxCon = null;
    try {
        // Connect to JMXConnector
        JMXServiceURL serviceUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi");
        jmxCon = JMXConnectorFactory.newJMXConnector(serviceUrl, null);
        jmxCon.connect();
        // Access the MBean
        MBeanServerConnection con = jmxCon.getMBeanServerConnection();
        Set<ObjectName> queryResults = con.queryNames(null, null);
        StringBuilder results = new StringBuilder();
        for (ObjectName theName : queryResults) {
            results.append("\n---");
            results.append("\nMBean name: " + theName.getCanonicalName());
            MBeanAttributeInfo[] attributes = con.getMBeanInfo(theName).getAttributes();
            for (MBeanAttributeInfo attribute : attributes) {
                if (attribute.getType() != null) {
                    if (!"javax.management.openmbean.CompositeData".equals(attribute.getType())) {
                        if ("java.lang.Long".equals(attribute.getType()) || "java.lang.Integer".equals(attribute.getType()) || "int".equals(attribute.getType()) || "long".equals(attribute.getType()))
                            results.append("\r   " + attribute.getName() + " | " + attribute.getType());
                    } else {
                        results.append("\r   " + attribute.getName() + " | " + attribute.getType());
                        CompositeData comdata = (CompositeData) con.getAttribute(theName, attribute.getName());
                        if (comdata != null) {
                            for (String key : comdata.getCompositeType().keySet()) {
                                Object value = comdata.get(key);
                                if (value instanceof Integer || value instanceof Double || value instanceof Long)
                                    results.append("\r      " + key + " | " + value.getClass());
                            }
                        }
                    }
                }
            }
        }
        return results.toString();
    } catch (Exception e) {
        throw new SystemOperationException("MBeans with their attributes cannot be get.", e);
    } finally {
        if (jmxCon != null)
            try {
                jmxCon.close();
            } catch (IOException e) {
                log.error("JMX connection was not closed!");
            }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) SystemOperationException(com.axway.ats.common.system.SystemOperationException) CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IOException(java.io.IOException) SystemOperationException(com.axway.ats.common.system.SystemOperationException) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

CompositeData (javax.management.openmbean.CompositeData)229 TabularData (javax.management.openmbean.TabularData)91 Test (org.junit.Test)73 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)51 CompositeType (javax.management.openmbean.CompositeType)50 HashMap (java.util.HashMap)31 ArrayList (java.util.ArrayList)27 Map (java.util.Map)27 Bundle (org.osgi.framework.Bundle)24 ObjectName (javax.management.ObjectName)21 OpenDataException (javax.management.openmbean.OpenDataException)18 IOException (java.io.IOException)17 Collection (java.util.Collection)16 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)16 AuditEvent (org.nhindirect.common.audit.AuditEvent)15 TabularType (javax.management.openmbean.TabularType)13 MBeanServer (javax.management.MBeanServer)12 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)11 MBeanException (javax.management.MBeanException)8