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));
}
}
}
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);
}
}
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()]);
}
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();
}
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!");
}
}
}
Aggregations