use of javax.management.MBeanAttributeInfo in project Activiti by Activiti.
the class MBeanInfoAssemblerTest method testReadAtributeInfoHappyPath.
@Test
public void testReadAtributeInfoHappyPath() throws JMException {
ModelMBeanInfo beanInfo = mbeanInfoAssembler.getMBeanInfo(testMbean, null, "someName");
assertNotNull(beanInfo);
assertEquals("test description", beanInfo.getDescription());
MBeanAttributeInfo[] testAttributes = beanInfo.getAttributes();
assertNotNull(testAttributes);
assertEquals(2, testAttributes.length);
int counter = 0;
for (MBeanAttributeInfo info : testAttributes) {
if (info.getName().equals("TestAttributeBoolean")) {
counter++;
assertEquals("test attribute Boolean description", info.getDescription());
assertEquals("java.lang.Boolean", info.getType());
assertTrue(info.isReadable());
assertFalse(info.isWritable());
} else if (info.getName().equals("TestAttributeString")) {
counter++;
assertEquals("test attribute String description", info.getDescription());
assertEquals("java.lang.String", info.getType());
assertTrue(info.isReadable());
assertFalse(info.isWritable());
}
}
assertEquals(2, counter);
// check the single operation
assertNotNull(beanInfo.getOperations());
assertEquals(3, beanInfo.getOperations().length);
}
use of javax.management.MBeanAttributeInfo in project Activiti by Activiti.
the class DefaultManagementMBeanAssemblerTest method testHappyPath.
@Test
public void testHappyPath() throws MalformedObjectNameException, JMException {
TestMbean testMbean = new TestMbean();
ModelMBean mbean = defaultManagementMBeanAssembler.assemble(testMbean, new ObjectName("org.activiti.jmx.Mbeans:type=something"));
assertNotNull(mbean);
assertNotNull(mbean.getMBeanInfo());
assertNotNull(mbean.getMBeanInfo().getAttributes());
MBeanAttributeInfo[] attributes = mbean.getMBeanInfo().getAttributes();
assertEquals(2, attributes.length);
assertTrue((attributes[0].getName().equals("TestAttributeString") && attributes[1].getName().equals("TestAttributeBoolean") || (attributes[1].getName().equals("TestAttributeString") && attributes[0].getName().equals("TestAttributeBoolean"))));
assertNotNull(mbean.getMBeanInfo().getOperations());
MBeanOperationInfo[] operations = mbean.getMBeanInfo().getOperations();
assertNotNull(operations);
assertEquals(3, operations.length);
}
use of javax.management.MBeanAttributeInfo in project jdk8u_jdk by JetBrains.
the class Monitor method getAttribute.
Object getAttribute(MBeanServerConnection mbsc, ObjectName object, String attribute) throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException {
// Check for "ObservedAttribute" replacement.
// This could happen if a thread A called setObservedAttribute()
// while other thread B was in the middle of the monitor() method
// and received the old observed attribute value.
//
final boolean lookupMBeanInfo;
synchronized (this) {
if (!isActive())
throw new IllegalArgumentException("The monitor has been stopped");
if (!attribute.equals(getObservedAttribute()))
throw new IllegalArgumentException("The observed attribute has been changed");
lookupMBeanInfo = (firstAttribute == null && attribute.indexOf('.') != -1);
}
// Look up MBeanInfo if needed
//
final MBeanInfo mbi;
if (lookupMBeanInfo) {
try {
mbi = mbsc.getMBeanInfo(object);
} catch (IntrospectionException e) {
throw new IllegalArgumentException(e);
}
} else {
mbi = null;
}
// Check for complex type attribute
//
final String fa;
synchronized (this) {
if (!isActive())
throw new IllegalArgumentException("The monitor has been stopped");
if (!attribute.equals(getObservedAttribute()))
throw new IllegalArgumentException("The observed attribute has been changed");
if (firstAttribute == null) {
if (attribute.indexOf('.') != -1) {
MBeanAttributeInfo[] mbaiArray = mbi.getAttributes();
for (MBeanAttributeInfo mbai : mbaiArray) {
if (attribute.equals(mbai.getName())) {
firstAttribute = attribute;
break;
}
}
if (firstAttribute == null) {
String[] tokens = attribute.split("\\.", -1);
firstAttribute = tokens[0];
for (int i = 1; i < tokens.length; i++) remainingAttributes.add(tokens[i]);
isComplexTypeAttribute = true;
}
} else {
firstAttribute = attribute;
}
}
fa = firstAttribute;
}
return mbsc.getAttribute(object, fa);
}
use of javax.management.MBeanAttributeInfo in project jdk8u_jdk by JetBrains.
the class XSheet method displayMetadataNode.
// Call on EDT
private void displayMetadataNode(final DefaultMutableTreeNode node) {
final XNodeInfo uo = (XNodeInfo) node.getUserObject();
final XMBeanInfo mbi = mbeanInfo;
switch(uo.getType()) {
case ATTRIBUTE:
SwingWorker<MBeanAttributeInfo, Void> sw = new SwingWorker<MBeanAttributeInfo, Void>() {
@Override
public MBeanAttributeInfo doInBackground() {
Object attrData = uo.getData();
mbean = (XMBean) ((Object[]) attrData)[0];
MBeanAttributeInfo mbai = (MBeanAttributeInfo) ((Object[]) attrData)[1];
mbeanAttributes.loadAttributes(mbean, new MBeanInfo(null, null, new MBeanAttributeInfo[] { mbai }, null, null, null));
return mbai;
}
@Override
protected void done() {
try {
MBeanAttributeInfo mbai = get();
if (!isSelectedNode(node, currentNode)) {
return;
}
invalidate();
mainPanel.removeAll();
JPanel attributePanel = new JPanel(new BorderLayout());
JPanel attributeBorderPanel = new JPanel(new BorderLayout());
attributeBorderPanel.setBorder(BorderFactory.createTitledBorder(Messages.ATTRIBUTE_VALUE));
JPanel attributeValuePanel = new JPanel(new BorderLayout());
attributeValuePanel.setBorder(LineBorder.createGrayLineBorder());
attributeValuePanel.add(mbeanAttributes.getTableHeader(), BorderLayout.PAGE_START);
attributeValuePanel.add(mbeanAttributes, BorderLayout.CENTER);
attributeBorderPanel.add(attributeValuePanel, BorderLayout.CENTER);
JPanel refreshButtonPanel = new JPanel();
refreshButtonPanel.add(refreshButton);
attributeBorderPanel.add(refreshButtonPanel, BorderLayout.SOUTH);
refreshButton.setEnabled(true);
attributePanel.add(attributeBorderPanel, BorderLayout.NORTH);
mbi.addMBeanAttributeInfo(mbai);
attributePanel.add(mbi, BorderLayout.CENTER);
mainPanel.add(attributePanel, BorderLayout.CENTER);
southPanel.setVisible(false);
southPanel.removeAll();
validate();
repaint();
} catch (Exception e) {
Throwable t = Utils.getActualException(e);
if (JConsole.isDebug()) {
System.err.println("Problem displaying MBean " + "attribute for MBean [" + mbean.getObjectName() + "]");
t.printStackTrace();
}
showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
}
}
};
sw.execute();
break;
case OPERATION:
Object operData = uo.getData();
mbean = (XMBean) ((Object[]) operData)[0];
MBeanOperationInfo mboi = (MBeanOperationInfo) ((Object[]) operData)[1];
mbeanOperations.loadOperations(mbean, new MBeanInfo(null, null, null, null, new MBeanOperationInfo[] { mboi }, null));
invalidate();
mainPanel.removeAll();
JPanel operationPanel = new JPanel(new BorderLayout());
JPanel operationBorderPanel = new JPanel(new BorderLayout());
operationBorderPanel.setBorder(BorderFactory.createTitledBorder(Messages.OPERATION_INVOCATION));
operationBorderPanel.add(new JScrollPane(mbeanOperations));
operationPanel.add(operationBorderPanel, BorderLayout.NORTH);
mbi.addMBeanOperationInfo(mboi);
operationPanel.add(mbi, BorderLayout.CENTER);
mainPanel.add(operationPanel, BorderLayout.CENTER);
southPanel.setVisible(false);
southPanel.removeAll();
validate();
repaint();
break;
case NOTIFICATION:
Object notifData = uo.getData();
invalidate();
mainPanel.removeAll();
mbi.addMBeanNotificationInfo((MBeanNotificationInfo) notifData);
mainPanel.add(mbi, BorderLayout.CENTER);
southPanel.setVisible(false);
southPanel.removeAll();
validate();
repaint();
break;
}
}
use of javax.management.MBeanAttributeInfo in project jdk8u_jdk by JetBrains.
the class XMBeanAttributes method doLoadAttributes.
// Don't call this in EDT, but execute returned Runnable inside
// EDT - typically in the done() method of a SwingWorker
// This method can return null.
private Runnable doLoadAttributes(final XMBean mbean, MBeanInfo infoOrNull) throws JMException, IOException {
if (mbean == null)
return null;
final MBeanInfo curMBeanInfo = (infoOrNull == null) ? mbean.getMBeanInfo() : infoOrNull;
final MBeanAttributeInfo[] attrsInfo = curMBeanInfo.getAttributes();
final HashMap<String, Object> attrs = new HashMap<String, Object>(attrsInfo.length);
final HashMap<String, Object> unavailableAttrs = new HashMap<String, Object>(attrsInfo.length);
final HashMap<String, Object> viewableAttrs = new HashMap<String, Object>(attrsInfo.length);
AttributeList list = null;
try {
list = mbean.getAttributes(attrsInfo);
} catch (Exception e) {
if (JConsole.isDebug()) {
System.err.println("Error calling getAttributes() on MBean \"" + mbean.getObjectName() + "\". JConsole will " + "try to get them individually calling " + "getAttribute() instead. Exception:");
e.printStackTrace(System.err);
}
list = new AttributeList();
//Can't load all attributes, do it one after each other.
for (int i = 0; i < attrsInfo.length; i++) {
String name = null;
try {
name = attrsInfo[i].getName();
Object value = mbean.getMBeanServerConnection().getAttribute(mbean.getObjectName(), name);
list.add(new Attribute(name, value));
} catch (Exception ex) {
if (attrsInfo[i].isReadable()) {
unavailableAttrs.put(name, Utils.getActualException(ex).toString());
}
}
}
}
try {
int att_length = list.size();
for (int i = 0; i < att_length; i++) {
Attribute attribute = (Attribute) list.get(i);
if (isViewable(attribute)) {
viewableAttrs.put(attribute.getName(), attribute.getValue());
} else
attrs.put(attribute.getName(), attribute.getValue());
}
// check them one after the other.
if (att_length < attrsInfo.length) {
for (int i = 0; i < attrsInfo.length; i++) {
MBeanAttributeInfo attributeInfo = attrsInfo[i];
if (!attrs.containsKey(attributeInfo.getName()) && !viewableAttrs.containsKey(attributeInfo.getName()) && !unavailableAttrs.containsKey(attributeInfo.getName())) {
if (attributeInfo.isReadable()) {
// went wrong.
try {
Object v = mbean.getMBeanServerConnection().getAttribute(mbean.getObjectName(), attributeInfo.getName());
//What happens if now it is ok?
// Be pragmatic, add it to readable...
attrs.put(attributeInfo.getName(), v);
} catch (Exception e) {
//Put the exception that will be displayed
// in tooltip
unavailableAttrs.put(attributeInfo.getName(), Utils.getActualException(e).toString());
}
}
}
}
}
} catch (Exception e) {
//sets all attributes unavailable except the writable ones
for (int i = 0; i < attrsInfo.length; i++) {
MBeanAttributeInfo attributeInfo = attrsInfo[i];
if (attributeInfo.isReadable()) {
unavailableAttrs.put(attributeInfo.getName(), Utils.getActualException(e).toString());
}
}
}
//one update at a time
return new Runnable() {
public void run() {
synchronized (XMBeanAttributes.this) {
XMBeanAttributes.this.mbean = mbean;
XMBeanAttributes.this.mbeanInfo = curMBeanInfo;
XMBeanAttributes.this.attributesInfo = attrsInfo;
XMBeanAttributes.this.attributes = attrs;
XMBeanAttributes.this.unavailableAttributes = unavailableAttrs;
XMBeanAttributes.this.viewableAttributes = viewableAttrs;
DefaultTableModel tableModel = (DefaultTableModel) getModel();
// add attribute information
emptyTable(tableModel);
addTableData(tableModel, mbean, attrsInfo, attrs, unavailableAttrs, viewableAttrs);
// update the model with the new data
tableModel.newDataAvailable(new TableModelEvent(tableModel));
// re-register for change events
tableModel.addTableModelListener(attributesListener);
}
}
};
}
Aggregations