use of javax.management.MBeanInfo in project spring-framework by spring-projects.
the class MBeanExporterOperationsTests method testRegisterExistingMBeanWithUserSuppliedObjectName.
@Test
public void testRegisterExistingMBeanWithUserSuppliedObjectName() throws Exception {
ObjectName objectName = ObjectNameManager.getInstance("spring:name=Foo");
ModelMBeanInfo info = new ModelMBeanInfoSupport("myClass", "myDescription", null, null, null, null);
RequiredModelMBean bean = new RequiredModelMBean(info);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer());
exporter.registerManagedResource(bean, objectName);
MBeanInfo infoFromServer = getServer().getMBeanInfo(objectName);
assertEquals(info, infoFromServer);
}
use of javax.management.MBeanInfo in project cdap by caskdata.
the class OperationalStatsHttpHandler method getStats.
/**
* Reads operational stats collected using the {@link OperationalStats} extension mechanism with the specified
* property key and value, grouped by the specified groupByKey.
*
* @param propertyKey the key that must be contained with the specified value in the stat to be returned
* @param propertyValue the value that the specified key must have in the stat to be returned
* @param groupByKey an additional key in the stat's property to group the stats by
* @return a {@link Map} of the group to a {@link Map} of stats of that group
* @throws Exception when there are errors reading stats using JMX
*/
@VisibleForTesting
Map<String, Map<String, Object>> getStats(String propertyKey, String propertyValue, String groupByKey) throws Exception {
Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey), "Property should not be null or empty.");
Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyValue), "Property value should not be null or empty.");
Hashtable<String, String> properties = new Hashtable<>();
// we want stats with the specified value for the specified key, so set them in the properties
properties.put(propertyKey, propertyValue);
// since we want to group by the groupKey, we want to fetch all groups
properties.put(groupByKey, "*");
ObjectName objectName = new ObjectName(OperationalStatsUtils.JMX_DOMAIN, properties);
Map<String, Map<String, Object>> result = new HashMap<>();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
for (ObjectName name : mbs.queryNames(objectName, null)) {
String group = name.getKeyProperty(groupByKey);
MBeanInfo mBeanInfo = mbs.getMBeanInfo(name);
Map<String, Object> stats = new HashMap<>();
for (MBeanAttributeInfo attributeInfo : mBeanInfo.getAttributes()) {
stats.put(attributeInfo.getName(), mbs.getAttribute(name, attributeInfo.getName()));
}
result.put(group, stats);
LOG.trace("Found stats of group {} as {}", group, stats);
}
return result;
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class XSheet method displayMBeanAttributesNode.
// Call on EDT
private void displayMBeanAttributesNode(final DefaultMutableTreeNode node) {
final XNodeInfo uo = (XNodeInfo) node.getUserObject();
if (!uo.getType().equals(Type.ATTRIBUTES)) {
return;
}
mbean = (XMBean) uo.getData();
final XMBean xmb = mbean;
SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {
@Override
public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
MBeanInfo mbi = xmb.getMBeanInfo();
return mbi;
}
@Override
protected void done() {
try {
MBeanInfo mbi = get();
if (mbi != null && mbi.getAttributes() != null && mbi.getAttributes().length > 0) {
mbeanAttributes.loadAttributes(xmb, mbi);
if (!isSelectedNode(node, currentNode)) {
return;
}
invalidate();
mainPanel.removeAll();
JPanel borderPanel = new JPanel(new BorderLayout());
borderPanel.setBorder(BorderFactory.createTitledBorder(Messages.ATTRIBUTE_VALUES));
borderPanel.add(new JScrollPane(mbeanAttributes));
mainPanel.add(borderPanel, BorderLayout.CENTER);
// add the refresh button to the south panel
southPanel.removeAll();
southPanel.add(refreshButton, BorderLayout.SOUTH);
southPanel.setVisible(true);
refreshButton.setEnabled(true);
validate();
repaint();
}
} catch (Exception e) {
Throwable t = Utils.getActualException(e);
if (JConsole.isDebug()) {
System.err.println("Problem displaying MBean " + "attributes for MBean [" + mbean.getObjectName() + "]");
t.printStackTrace();
}
showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
}
}
};
sw.execute();
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class XSheet method displayMBeanNode.
// Call on EDT
private void displayMBeanNode(final DefaultMutableTreeNode node) {
final XNodeInfo uo = (XNodeInfo) node.getUserObject();
if (!uo.getType().equals(Type.MBEAN)) {
return;
}
mbean = (XMBean) uo.getData();
SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {
@Override
public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
return mbean.getMBeanInfo();
}
@Override
protected void done() {
try {
MBeanInfo mbi = get();
if (mbi != null) {
if (!isSelectedNode(node, currentNode)) {
return;
}
mbeanInfo.addMBeanInfo(mbean, mbi);
invalidate();
mainPanel.removeAll();
mainPanel.add(mbeanInfo, BorderLayout.CENTER);
southPanel.setVisible(false);
southPanel.removeAll();
validate();
repaint();
}
} catch (Exception e) {
Throwable t = Utils.getActualException(e);
if (JConsole.isDebug()) {
System.err.println("Couldn't get MBeanInfo for MBean [" + mbean.getObjectName() + "]");
t.printStackTrace();
}
showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
}
}
};
sw.execute();
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class StandardMBeanSupport method getMBeanInfo.
/* Standard MBeans that are NotificationBroadcasters can return a different
* MBeanNotificationInfo[] every time getMBeanInfo() is called, so we have
* to reconstruct this MBeanInfo if necessary.
*/
@Override
public MBeanInfo getMBeanInfo() {
MBeanInfo mbi = super.getMBeanInfo();
Class<?> resourceClass = getResource().getClass();
if (StandardMBeanIntrospector.isDefinitelyImmutableInfo(resourceClass))
return mbi;
return new MBeanInfo(mbi.getClassName(), mbi.getDescription(), mbi.getAttributes(), mbi.getConstructors(), mbi.getOperations(), MBeanIntrospector.findNotifications(getResource()), mbi.getDescriptor());
}
Aggregations