use of javax.management.MBeanInfo in project Payara by payara.
the class BulkAccessImpl method bulkGetAttributeNames.
public Object[] bulkGetAttributeNames(final ObjectName[] objectNames) {
final Object[] results = new Object[objectNames.length];
final Object[] mbeanInfos = bulkGetMBeanInfo(objectNames);
for (int i = 0; i < results.length; ++i) {
if (mbeanInfos[i] instanceof MBeanInfo) {
final MBeanInfo info = (MBeanInfo) mbeanInfos[i];
results[i] = JMXUtil.getAttributeNames(info.getAttributes());
} else {
results[i] = mbeanInfos[i];
}
}
return (results);
}
use of javax.management.MBeanInfo in project quickstart by wildfly.
the class AnnotatedComponentHelloWorldIT method testHello.
@Test
public void testHello() throws Exception {
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName("quickstarts", "type", AnnotatedComponentHelloWorld.class.getSimpleName());
MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName);
Assert.assertNotNull(mbeanInfo);
Assert.assertEquals(0L, mbeanServer.getAttribute(objectName, "Count"));
Assert.assertEquals("Hello", mbeanServer.getAttribute(objectName, "WelcomeMessage"));
Assert.assertEquals("Hello jer!", mbeanServer.invoke(objectName, "sayHello", new Object[] { "jer" }, new String[] { "java.lang.String" }));
Assert.assertEquals(1L, mbeanServer.getAttribute(objectName, "Count"));
mbeanServer.setAttribute(objectName, new Attribute("WelcomeMessage", "Hi"));
Assert.assertEquals("Hi jer!", mbeanServer.invoke(objectName, "sayHello", new Object[] { "jer" }, new String[] { "java.lang.String" }));
Assert.assertEquals(2L, mbeanServer.getAttribute(objectName, "Count"));
}
use of javax.management.MBeanInfo in project quickstart by wildfly.
the class MXPojoHelloWorldIT method testHello.
@Test
public void testHello() throws Exception {
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName("quickstarts", "type", MXPojoHelloWorld.class.getSimpleName());
MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName);
Assert.assertNotNull(mbeanInfo);
Assert.assertEquals(0L, mbeanServer.getAttribute(objectName, "Count"));
Assert.assertEquals("Welcome", mbeanServer.getAttribute(objectName, "WelcomeMessage"));
Assert.assertEquals("Welcome jer!", mbeanServer.invoke(objectName, "sayHello", new Object[] { "jer" }, new String[] { "java.lang.String" }));
Assert.assertEquals(1L, mbeanServer.getAttribute(objectName, "Count"));
mbeanServer.setAttribute(objectName, new Attribute("WelcomeMessage", "Hi"));
Assert.assertEquals("Hi jer!", mbeanServer.invoke(objectName, "sayHello", new Object[] { "jer" }, new String[] { "java.lang.String" }));
Assert.assertEquals(2L, mbeanServer.getAttribute(objectName, "Count"));
}
use of javax.management.MBeanInfo in project tomee by apache.
the class LocalJMXCommand method invoke.
private void invoke(final String value) {
if (!value.contains("(") || !value.contains(")")) {
streamManager.writeErr("method should follow the format: <methoName>(<arg1>,<arg2>,...)");
return;
}
int open = value.indexOf("(");
int close = value.lastIndexOf(")");
final String name = value.substring(0, open).trim();
final String rawArgs = value.substring(open + 1, close).trim();
final ObjectName on;
try {
on = new ObjectName(value.substring(close + 1).trim());
} catch (MalformedObjectNameException e) {
streamManager.writeErr(e);
return;
}
final MBeanServer server = LocalMBeanServer.get();
final String[] args;
if (rawArgs == null || rawArgs.isEmpty()) {
args = new String[0];
} else {
args = rawArgs.split(",");
}
try {
final MBeanInfo minfo = server.getMBeanInfo(on);
final MBeanOperationInfo[] methods = minfo.getOperations();
MBeanOperationInfo operation = null;
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals(name)) {
operation = methods[i];
break;
}
}
if (operation == null) {
streamManager.writeErr("can't find operation '" + name + "'");
return;
}
final Object[] passedArgs = new Object[args.length];
final String[] passedArgTypes = new String[args.length];
for (int i = 0; i < passedArgs.length; i++) {
final String expected = operation.getSignature()[i].getType();
if (!String.class.getName().equals(expected)) {
passedArgs[i] = PropertyEditors.getValue(expected, args[i], Thread.currentThread().getContextClassLoader());
} else {
passedArgs[i] = args[i];
}
passedArgTypes[i] = expected;
}
streamManager.writeOut(stringify(server.invoke(on, name, passedArgs, passedArgTypes)));
} catch (Exception e) {
streamManager.writeErr(e);
return;
}
}
use of javax.management.MBeanInfo in project tomee by apache.
the class LocalJMXCommand method listMBeans.
private void listMBeans() {
final MBeanServer mBeanServer = LocalMBeanServer.get();
final Set<ObjectName> names;
try {
names = mBeanServer.queryNames(null, null);
} catch (Exception e) {
streamManager.writeErr(e);
return;
}
final Iterator<ObjectName> it = names.iterator();
while (it.hasNext()) {
ObjectName oname = it.next();
streamManager.writeOut("Name: " + oname.toString());
try {
final MBeanInfo minfo = mBeanServer.getMBeanInfo(oname);
String code = minfo.getClassName();
if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
code = (String) mBeanServer.getAttribute(oname, "modelerType");
}
streamManager.writeOut(" + modelerType: " + code);
MBeanAttributeInfo[] attrs = minfo.getAttributes();
Object value = null;
for (int i = 0; i < attrs.length; i++) {
if (!attrs[i].isReadable()) {
continue;
}
final String attName = attrs[i].getName();
if ("modelerType".equals(attName)) {
continue;
}
if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0 || attName.indexOf(" ") >= 0) {
continue;
}
try {
value = mBeanServer.getAttribute(oname, attName);
} catch (RuntimeMBeanException uoe) {
// ignored
} catch (Throwable t) {
streamManager.writeErr(new Exception(t));
continue;
}
try {
String valueString = stringify(value);
streamManager.writeOut(" + " + attName + ": " + valueString);
} catch (Throwable t) {
streamManager.writeErr(new Exception(t));
}
}
} catch (Throwable t) {
streamManager.writeErr(new Exception(t));
}
streamManager.writeOut("");
}
}
Aggregations