use of javax.management.MBeanInfo 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);
}
}
};
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class TooManyFooTest method test.
private static void test(Object child, String name, boolean mxbean) throws Exception {
final ObjectName childName = new ObjectName("test:type=Child,name=" + name);
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child, childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name + ": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name + ": OK, only " + OPCOUNT + " operations here...");
} else {
final String qual = (len > OPCOUNT) ? "many" : "few";
System.err.println(name + ": Too " + qual + " foos! Found " + len + ", expected " + OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public " + op.getReturnType() + " " + op.getName() + "();");
}
throw new RuntimeException("Too " + qual + " foos for " + name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb = (mxstr == null) ? false : Boolean.valueOf(mxstr).booleanValue();
System.out.println(name + ": mxbean=" + mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation " + mboi.getName() + "() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String) mboi.getDescriptor().getFieldValue("originalType");
if (type == null)
type = mboi.getReturnType();
if (type.equals(exp))
continue;
System.err.println("Bad return type for " + mboi.getName() + "! Found " + type + ", expected " + exp);
throw new RuntimeException("Bad return type for " + mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class MBeanInfoEqualsNPETest method main.
public static void main(String[] args) throws Exception {
System.out.println("---MBeanInfoEqualsNPETest-main ...");
// ----
System.out.println("\n---Testing on MBeanAttributeInfo...");
MBeanAttributeInfo mbeanAttributeInfo0 = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), "description", true, true, false);
MBeanAttributeInfo mbeanAttributeInfo = new MBeanAttributeInfo(null, SimpleType.INTEGER.getClassName(), "description", true, true, false);
test(mbeanAttributeInfo0, mbeanAttributeInfo, "class name");
mbeanAttributeInfo = new MBeanAttributeInfo("name", null, "description", true, true, false);
test(mbeanAttributeInfo0, mbeanAttributeInfo, "type");
mbeanAttributeInfo = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), null, true, true, false);
test(mbeanAttributeInfo0, mbeanAttributeInfo, "description");
// ----
System.out.println("\n---Testing on MBeanConstructorInfo...");
MBeanConstructorInfo mbeanConstructorInfo0 = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, new DescriptorSupport());
MBeanConstructorInfo mbeanConstructorInfo = new MBeanConstructorInfo(null, "", new MBeanParameterInfo[] {}, new DescriptorSupport());
test(mbeanConstructorInfo0, mbeanConstructorInfo, "name");
mbeanConstructorInfo = new MBeanConstructorInfo("", null, new MBeanParameterInfo[] {}, new DescriptorSupport());
test(mbeanConstructorInfo0, mbeanConstructorInfo, "description");
mbeanConstructorInfo = new MBeanConstructorInfo("", "", null, new DescriptorSupport());
test(mbeanConstructorInfo0, mbeanConstructorInfo, "MBeanParameterInfo");
mbeanConstructorInfo = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, null);
test(mbeanConstructorInfo0, mbeanConstructorInfo, "descriptor");
// ----
System.out.println("\n---Testing on MBeanOperationInfo...");
MBeanOperationInfo mbeanOperationInfo0 = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo(null, "description", new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "name");
mbeanOperationInfo = new MBeanOperationInfo("name", null, new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "description");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", null, "type", 1, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "MBeanParameterInfo");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "type");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, MBeanOperationInfo.UNKNOWN, null);
test(mbeanOperationInfo0, mbeanOperationInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanParameterInfo...");
MBeanParameterInfo mbeanParameterInfo0 = new MBeanParameterInfo("name", "type", "description", new DescriptorSupport());
MBeanParameterInfo mbeanParameterInfo = new MBeanParameterInfo(null, "type", "description", new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "name");
mbeanParameterInfo = new MBeanParameterInfo("name", null, "description", new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "type");
mbeanParameterInfo = new MBeanParameterInfo("name", "type", null, new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "description");
mbeanParameterInfo = new MBeanParameterInfo("name", "type", "description", null);
test(mbeanParameterInfo0, mbeanParameterInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanFeatureInfo ...");
MBeanFeatureInfo mbeanFeatureInfo0 = new MBeanFeatureInfo("name", "description", new DescriptorSupport());
MBeanFeatureInfo mbeanFeatureInfo = new MBeanFeatureInfo(null, "description", new DescriptorSupport());
test(mbeanFeatureInfo0, mbeanFeatureInfo, "name");
mbeanFeatureInfo = new MBeanFeatureInfo("name", null, new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "description");
mbeanFeatureInfo = new MBeanFeatureInfo("name", "description", null);
test(mbeanParameterInfo0, mbeanParameterInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanInfo...");
String className = "toto";
String description = "titi";
MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[] {};
MBeanConstructorInfo[] constrInfos = new MBeanConstructorInfo[] {};
MBeanOperationInfo[] operaInfos = new MBeanOperationInfo[] {};
MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[] {};
MBeanInfo minfo0 = new MBeanInfo("toto", description, attrInfos, constrInfos, operaInfos, notifInfos);
MBeanInfo minfo = new MBeanInfo(null, description, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo0, minfo, "class name");
minfo = new MBeanInfo(className, null, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo0, minfo, "description");
minfo = new MBeanInfo(className, description, null, constrInfos, operaInfos, notifInfos);
test(minfo0, minfo, "attrInfos");
minfo = new MBeanInfo(className, description, attrInfos, null, operaInfos, notifInfos);
test(minfo0, minfo, "constrInfos");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, null, notifInfos);
test(minfo0, minfo, "operaInfos");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, null);
test(minfo0, minfo, "notifInfos");
if (failed > 0) {
throw new RuntimeException("Test failed: " + failed);
} else {
System.out.println("---Test: PASSED");
}
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class MBeanInfoHashCodeNPETest method main.
public static void main(String[] args) throws Exception {
System.out.println("---MBeanInfoHashCodeNPETest-main ...");
// ----
System.out.println("\n---Testing on MBeanAttributeInfo...");
MBeanAttributeInfo mbeanAttributeInfo = new MBeanAttributeInfo(null, SimpleType.INTEGER.getClassName(), "description", true, true, false);
test(mbeanAttributeInfo, "class name");
mbeanAttributeInfo = new MBeanAttributeInfo("name", null, "description", true, true, false);
test(mbeanAttributeInfo, "type");
mbeanAttributeInfo = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), null, true, true, false);
test(mbeanAttributeInfo, "description");
// ----
System.out.println("\n---Testing on MBeanConstructorInfo...");
MBeanConstructorInfo mbeanConstructorInfo = new MBeanConstructorInfo(null, "", new MBeanParameterInfo[] {}, new DescriptorSupport());
test(mbeanConstructorInfo, "name");
mbeanConstructorInfo = new MBeanConstructorInfo("", null, new MBeanParameterInfo[] {}, new DescriptorSupport());
test(mbeanConstructorInfo, "description");
mbeanConstructorInfo = new MBeanConstructorInfo("", "", null, new DescriptorSupport());
test(mbeanConstructorInfo, "MBeanParameterInfo");
mbeanConstructorInfo = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, null);
test(mbeanConstructorInfo, "descriptor");
// ----
System.out.println("\n---Testing on MBeanOperationInfo...");
MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo(null, "description", new MBeanParameterInfo[] {}, "type", 1, new DescriptorSupport());
test(mbeanOperationInfo, "name");
mbeanOperationInfo = new MBeanOperationInfo("name", null, new MBeanParameterInfo[] {}, "type", 1, new DescriptorSupport());
test(mbeanOperationInfo, "description");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", null, "type", 1, new DescriptorSupport());
test(mbeanOperationInfo, "MBeanParameterInfo");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, 1, new DescriptorSupport());
test(mbeanOperationInfo, "type");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, "type", -1, new DescriptorSupport());
test(mbeanOperationInfo, "native impact");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, "type", 1, null);
test(mbeanOperationInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanParameterInfo...");
MBeanParameterInfo mbeanParameterInfo = new MBeanParameterInfo(null, "type", "description", new DescriptorSupport());
test(mbeanParameterInfo, "name");
mbeanParameterInfo = new MBeanParameterInfo("name", null, "description", new DescriptorSupport());
test(mbeanParameterInfo, "description");
mbeanParameterInfo = new MBeanParameterInfo("name", "type", null, new DescriptorSupport());
test(mbeanParameterInfo, "description");
mbeanParameterInfo = new MBeanParameterInfo("name", "type", "description", null);
test(mbeanParameterInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanInfo...");
String className = "toto";
String description = "titi";
MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[] {};
MBeanConstructorInfo[] constrInfos = new MBeanConstructorInfo[] {};
MBeanOperationInfo[] operaInfos = new MBeanOperationInfo[] {};
MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[] {};
MBeanInfo minfo = new MBeanInfo(null, description, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo, "class name");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo, "name");
minfo = new MBeanInfo(className, null, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo, "description");
minfo = new MBeanInfo(className, description, null, constrInfos, operaInfos, notifInfos);
test(minfo, "attrInfos");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, null, notifInfos);
test(minfo, "operaInfos");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, null);
test(minfo, "notifInfos");
Thread.sleep(100);
if (failed > 0) {
throw new RuntimeException("Test failed: " + failed);
} else {
System.out.println("---Test: PASSED");
}
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class TypeNameTest method main.
public static void main(String[] args) throws Exception {
TestMXBean testImpl = (TestMXBean) Proxy.newProxyInstance(TestMXBean.class.getClassLoader(), new Class<?>[] { TestMXBean.class }, nullIH);
Object mxbean = new StandardMBean(testImpl, TestMXBean.class, true);
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName name = new ObjectName("a:b=c");
mbs.registerMBean(mxbean, name);
MBeanInfo mbi = mbs.getMBeanInfo(name);
MBeanAttributeInfo[] mbais = mbi.getAttributes();
boolean sawTabular = false;
for (MBeanAttributeInfo mbai : mbais) {
String attrName = mbai.getName();
String attrTypeName = (String) mbai.getDescriptor().getFieldValue("originalType");
String fieldName = attrName + "Name";
Field nameField = TestMXBean.class.getField(fieldName);
String expectedTypeName = (String) nameField.get(null);
if (expectedTypeName.equals(attrTypeName)) {
System.out.println("OK: " + attrName + ": " + attrTypeName);
} else {
fail("For attribute " + attrName + " expected type name \"" + expectedTypeName + "\", found type name \"" + attrTypeName + "\"");
}
if (mbai.getType().equals(TabularData.class.getName())) {
sawTabular = true;
TabularType tt = (TabularType) mbai.getDescriptor().getFieldValue("openType");
if (tt.getTypeName().equals(attrTypeName)) {
System.out.println("OK: TabularType name for " + attrName);
} else {
fail("For attribute " + attrName + " expected TabularType " + "name \"" + attrTypeName + "\", found \"" + tt.getTypeName());
}
}
}
if (!sawTabular)
fail("Test bug: did not test TabularType name");
if (failure == null)
System.out.println("TEST PASSED");
else
throw new Exception("TEST FAILED: " + failure);
}
Aggregations