use of javax.management.MBeanAttributeInfo in project geode by apache.
the class LocalProcessControllerJUnitTest method testProcessMBean.
@Test
public void testProcessMBean() throws Exception {
// validate basics of the ProcessMBean
Set<ObjectName> mbeanNames = this.server.queryNames(objectName, null);
assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
assertEquals(1, mbeanNames.size());
final ObjectName name = mbeanNames.iterator().next();
final MBeanInfo info = this.server.getMBeanInfo(name);
final MBeanOperationInfo[] operInfo = info.getOperations();
assertEquals(1, operInfo.length);
assertEquals("stop", operInfo[0].getName());
final MBeanAttributeInfo[] attrInfo = info.getAttributes();
assertEquals(2, attrInfo.length);
// The order of these attributes is indeterminate
assertTrue("Pid".equals(attrInfo[0].getName()) || "Process".equals(attrInfo[0].getName()));
assertTrue("Pid".equals(attrInfo[1].getName()) || "Process".equals(attrInfo[1].getName()));
assertNotNull(this.server.getAttribute(name, "Pid"));
assertNotNull(this.server.getAttribute(name, "Process"));
assertEquals(pid, this.server.getAttribute(name, "Pid"));
assertEquals(true, this.server.getAttribute(name, "Process"));
// validate query using only Pid attribute
QueryExp constraint = Query.eq(Query.attr("Pid"), Query.value(pid));
mbeanNames = this.server.queryNames(objectName, constraint);
assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
// validate query with wrong Pid finds nothing
constraint = Query.eq(Query.attr("Pid"), Query.value(pid + 1));
mbeanNames = this.server.queryNames(objectName, constraint);
assertTrue("Found matching mbeans", mbeanNames.isEmpty());
// validate query using both attributes
constraint = Query.and(Query.eq(Query.attr("Process"), Query.value(true)), Query.eq(Query.attr("Pid"), Query.value(pid)));
mbeanNames = this.server.queryNames(objectName, constraint);
assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
// validate query with wrong attribute finds nothing
constraint = Query.and(Query.eq(Query.attr("Process"), Query.value(false)), Query.eq(Query.attr("Pid"), Query.value(pid)));
mbeanNames = this.server.queryNames(objectName, constraint);
assertTrue("Found matching mbeans", mbeanNames.isEmpty());
}
use of javax.management.MBeanAttributeInfo in project geode by apache.
the class MBeanUtil method printBeanDetails.
public static void printBeanDetails(ObjectName objName) throws Exception {
MBeanAttributeInfo[] attributeInfos;
MBeanInfo info = null;
try {
info = mbeanServer.getMBeanInfo(objName);
} catch (IntrospectionException e1) {
fail("Could not obtain Sender Proxy Details");
} catch (InstanceNotFoundException e1) {
fail("Could not obtain Sender Proxy Details");
} catch (ReflectionException e1) {
fail("Could not obtain Sender Proxy Details");
}
attributeInfos = info.getAttributes();
for (MBeanAttributeInfo attributeInfo : attributeInfos) {
Object propertyValue = null;
String propertyName = null;
try {
propertyName = attributeInfo.getName();
propertyValue = mbeanServer.getAttribute(objName, propertyName);
LogWriterUtils.getLogWriter().info("<ExpectedString> " + propertyName + " = " + propertyValue + "</ExpectedString> ");
} catch (Exception e) {
}
}
}
use of javax.management.MBeanAttributeInfo in project ignite by apache.
the class GridMBeanSelfTest method testCorrectMBeanInfo.
/**
* Tests correct MBean interface.
*
* @throws Exception Thrown if test fails.
*/
public void testCorrectMBeanInfo() throws Exception {
StandardMBean mbean = new IgniteStandardMXBean(new GridMBeanImplementation(), GridMBeanInterface.class);
MBeanInfo info = mbean.getMBeanInfo();
assert info.getDescription().equals("MBeanDescription.") == true;
assert info.getOperations().length == 2;
for (MBeanOperationInfo opInfo : info.getOperations()) {
if (opInfo.getDescription().equals("MBeanOperation."))
assert opInfo.getSignature().length == 2;
else {
assert opInfo.getDescription().equals("MBeanSuperOperation.") == true;
assert opInfo.getSignature().length == 1;
}
}
for (MBeanParameterInfo paramInfo : info.getOperations()[0].getSignature()) {
if (paramInfo.getName().equals("ignored"))
assert paramInfo.getDescription().equals("MBeanOperationParameter1.") == true;
else {
assert paramInfo.getName().equals("someData") == true;
assert paramInfo.getDescription().equals("MBeanOperationParameter2.") == true;
}
}
assert info.getAttributes().length == 4 : "Expected 4 attributes but got " + info.getAttributes().length;
for (MBeanAttributeInfo attrInfo : info.getAttributes()) {
if (attrInfo.isWritable() == false) {
assert (attrInfo.getDescription().equals("MBeanReadonlyGetter.") == true || attrInfo.getDescription().equals("MBeanROGetter."));
} else {
assert (attrInfo.getDescription().equals("MBeanWritableGetter.") == true || attrInfo.getDescription().equals("MBeanWritableIsGetter."));
}
}
}
use of javax.management.MBeanAttributeInfo in project jackrabbit-oak by apache.
the class AnnotatedStandardMBeanTest method test.
@Test
public void test() throws Exception {
MBeanInfo info = server.getMBeanInfo(objectName);
assertEquals("MBean desc.", info.getDescription());
MBeanAttributeInfo a0 = findAttribute(info, "Getter");
assertEquals("getter", a0.getDescription());
MBeanAttributeInfo a1 = findAttribute(info, "It");
assertEquals("is", a1.getDescription());
MBeanAttributeInfo a2 = findAttribute(info, "Setter");
assertEquals("setter", a2.getDescription());
MBeanOperationInfo op0 = info.getOperations()[0];
assertEquals("run", op0.getDescription());
assertEquals(MBeanOperationInfo.INFO, op0.getImpact());
MBeanParameterInfo p0 = op0.getSignature()[0];
assertEquals("timeout", p0.getName());
assertEquals("how long?", p0.getDescription());
}
use of javax.management.MBeanAttributeInfo in project lucene-solr by apache.
the class MetricsMap method getMBeanInfo.
@Override
public MBeanInfo getMBeanInfo() {
ArrayList<MBeanAttributeInfo> attrInfoList = new ArrayList<>();
Map<String, Object> stats = getValue(true);
if (useCachedStatsBetweenGetMBeanInfoCalls) {
cachedValue = stats;
}
try {
stats.forEach((k, v) -> {
Class type = v.getClass();
OpenType typeBox = determineType(type);
if (type.equals(String.class) || typeBox == null) {
attrInfoList.add(new MBeanAttributeInfo(k, String.class.getName(), null, true, false, false));
} else {
attrInfoList.add(new OpenMBeanAttributeInfoSupport(k, k, typeBox, true, false, false));
}
});
} catch (Exception e) {
// don't log issue if the core is closing
if (!(SolrException.getRootCause(e) instanceof AlreadyClosedException))
log.warn("Could not get attributes of MetricsMap: {}", this, e);
}
MBeanAttributeInfo[] attrInfoArr = attrInfoList.toArray(new MBeanAttributeInfo[attrInfoList.size()]);
return new MBeanInfo(getClass().getName(), "MetricsMap", attrInfoArr, null, null, null);
}
Aggregations