use of javax.management.MBeanInfo 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.MBeanInfo 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.MBeanInfo in project geode by apache.
the class MBeanProxyInvocationHandler method invokeBroadcasterMethod.
/**
* The call will delegate to Managed Node for NotificationHub to register a local listener to
* listen for notification from the MBean
*
* Moreover it will also add the client to local listener list by adding to the contained emitter.
*
* @param proxy the proxy object
* @param method method to be invoked
* @param args method arguments
* @return result value if any
* @throws Exception
*/
private Object invokeBroadcasterMethod(Object proxy, Method method, Object[] args) throws Throwable {
final String methodName = method.getName();
final int nargs = (args == null) ? 0 : args.length;
final Class[] paramTypes = method.getParameterTypes();
final String[] signature = new String[paramTypes.length];
if (methodName.equals("addNotificationListener")) {
if (nargs != 3) {
final String msg = "Bad arg count to addNotificationListener: " + nargs;
throw new IllegalArgumentException(msg);
}
/*
* Other inconsistencies will produce ClassCastException below.
*/
NotificationListener listener = (NotificationListener) args[0];
NotificationFilter filter = (NotificationFilter) args[1];
Object handback = args[2];
emitter.addNotificationListener(listener, filter, handback);
delegateToFucntionService(objectName, methodName, null, signature);
return null;
} else if (methodName.equals("removeNotificationListener")) {
/*
* NullPointerException if method with no args, but that shouldn't happen because removeNL
* does have args.
*/
NotificationListener listener = (NotificationListener) args[0];
switch(nargs) {
case 1:
emitter.removeNotificationListener(listener);
/**
* No need to send listener and filter details to other members. We only need to send a
* message saying remove the listner registered for this object on your side. Fixes Bug[
* #47075 ]
*/
delegateToFucntionService(objectName, methodName, null, signature);
return null;
case 3:
NotificationFilter filter = (NotificationFilter) args[1];
Object handback = args[2];
emitter.removeNotificationListener(listener, filter, handback);
delegateToFucntionService(objectName, methodName, null, signature);
return null;
default:
final String msg = "Bad arg count to removeNotificationListener: " + nargs;
throw new IllegalArgumentException(msg);
}
} else if (methodName.equals("getNotificationInfo")) {
if (args != null) {
throw new IllegalArgumentException("getNotificationInfo has " + "args");
}
if (!MBeanJMXAdapter.mbeanServer.isRegistered(objectName)) {
return new MBeanNotificationInfo[0];
}
/**
* MBean info is delegated to function service as intention is to get the info of the actual
* mbean rather than the proxy
*/
Object obj = delegateToFucntionService(objectName, methodName, args, signature);
if (obj instanceof String) {
return new MBeanNotificationInfo[0];
}
MBeanInfo info = (MBeanInfo) obj;
return info.getNotifications();
} else {
throw new IllegalArgumentException("Bad method name: " + methodName);
}
}
use of javax.management.MBeanInfo in project wildfly by wildfly.
the class JMXFilterTestCase method testFilter.
@Test
public void testFilter() throws Exception {
Set<ObjectName> names = connection.queryNames(new ObjectName("*:name=test-sar-1234567890,*"), null);
Assert.assertEquals(1, names.size());
Assert.assertTrue(names.contains(new ObjectName("jboss:name=test-sar-1234567890,type=jmx-sar")));
names = connection.queryNames(new ObjectName("*:subsystem=jsr77,*"), null);
Assert.assertTrue(names.toString(), names.size() == 4);
Assert.assertTrue(names.contains(new ObjectName("jboss.as.expr:subsystem=jsr77")));
Assert.assertTrue(names.contains(new ObjectName("jboss.as:subsystem=jsr77")));
Assert.assertTrue(names.contains(new ObjectName("jboss.as.expr:extension=org.jboss.as.jsr77,subsystem=jsr77")));
Assert.assertTrue(names.contains(new ObjectName("jboss.as:extension=org.jboss.as.jsr77,subsystem=jsr77")));
names = connection.queryNames(new ObjectName("*:j2eeType=J2EEServer,*"), null);
Assert.assertEquals(1, names.size());
final ObjectName name = new ObjectName("jboss.jsr77:j2eeType=J2EEServer,name=default");
Assert.assertTrue(names.contains(name));
MBeanInfo info = connection.getMBeanInfo(name);
Assert.assertNotNull(info);
}
use of javax.management.MBeanInfo in project presto by prestodb.
the class JmxMetadata method getJmxTableHandle.
private JmxTableHandle getJmxTableHandle(SchemaTableName tableName) {
try {
String canonicalName = new ObjectName(tableName.getTableName()).getCanonicalName();
Optional<ObjectName> objectName = mbeanServer.queryNames(WILDCARD, null).stream().filter(name -> canonicalName.equalsIgnoreCase(name.getCanonicalName())).findFirst();
if (!objectName.isPresent()) {
return null;
}
MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName.get());
ImmutableList.Builder<JmxColumnHandle> columns = ImmutableList.builder();
columns.add(new JmxColumnHandle(NODE_COLUMN_NAME, createUnboundedVarcharType()));
// Since this method is being called on all nodes in the cluster, we must ensure (by sorting)
// that attributes are in the same order on all of them.
Arrays.stream(mbeanInfo.getAttributes()).filter(MBeanAttributeInfo::isReadable).map(attribute -> new JmxColumnHandle(attribute.getName(), getColumnType(attribute))).sorted((column1, column2) -> column1.getColumnName().compareTo(column2.getColumnName())).forEach(columns::add);
return new JmxTableHandle(objectName.get().toString(), columns.build(), true);
} catch (JMException e) {
return null;
}
}
Aggregations