use of javax.management.MBeanOperationInfo in project activemq-artemis by apache.
the class MBeanInfoHelper method getOperationInfo.
private static MBeanOperationInfo getOperationInfo(final Method operation) {
MBeanOperationInfo info = null;
Class<?> returnType = operation.getReturnType();
MBeanParameterInfo[] paramsInfo = MBeanInfoHelper.getParametersInfo(operation.getParameterAnnotations(), operation.getParameterTypes());
String description = operation.getName();
int impact = MBeanOperationInfo.UNKNOWN;
if (operation.getAnnotation(Operation.class) != null) {
description = operation.getAnnotation(Operation.class).desc();
impact = operation.getAnnotation(Operation.class).impact();
}
info = new MBeanOperationInfo(operation.getName(), description, paramsInfo, returnType.getName(), impact);
return info;
}
use of javax.management.MBeanOperationInfo in project com.revolsys.open by revolsys.
the class JmxService method getOperation.
/**
* Get the description for the operation for an object on a server.
*
* @param serverId The name of the server.
* @param objectId The name of the object.
* @param operationId The name of the operation.
* @return The operations values.
*/
public MBeanOperationInfo getOperation(final String serverId, final String objectId, final String operationId) {
if (hasOperation(serverId, objectId, operationId)) {
final MBeanServerConnection connection = getConnection(serverId);
try {
final ObjectName objectName = getObjectName(serverId, objectId);
final MBeanInfo beanInfo = connection.getMBeanInfo(objectName);
for (final MBeanOperationInfo operation : beanInfo.getOperations()) {
final String name = operation.getName();
if (operationId.equals(name)) {
return operation;
}
}
throw new IllegalArgumentException("MBean Operation not found " + serverId + " " + objectId + "." + operationId);
} catch (final InstanceNotFoundException e) {
throw new IllegalArgumentException("MBean not found " + serverId + " " + objectId);
} catch (final MalformedObjectNameException e) {
throw new IllegalArgumentException("MBean name not valid " + serverId + " " + objectId);
} catch (final Throwable e) {
return Exceptions.throwUncheckedException(e);
}
} else {
throw new IllegalArgumentException("Operation not configured " + serverId + " " + objectId + "." + operationId);
}
}
use of javax.management.MBeanOperationInfo in project h2database by h2database.
the class TestJmx method test.
@Override
public void test() throws Exception {
HashMap<String, MBeanAttributeInfo> attrMap;
HashMap<String, MBeanOperationInfo> opMap;
String result;
MBeanInfo info;
ObjectName name;
Connection conn;
Statement stat;
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
conn = getConnection("mem:jmx;jmx=true");
stat = conn.createStatement();
name = new ObjectName("org.h2:name=JMX,path=mem_jmx");
info = mbeanServer.getMBeanInfo(name);
assertEquals("0", mbeanServer.getAttribute(name, "CacheSizeMax").toString());
// cache size is ignored for in-memory databases
mbeanServer.setAttribute(name, new Attribute("CacheSizeMax", 1));
assertEquals("0", mbeanServer.getAttribute(name, "CacheSizeMax").toString());
assertEquals("0", mbeanServer.getAttribute(name, "CacheSize").toString());
assertEquals("false", mbeanServer.getAttribute(name, "Exclusive").toString());
assertEquals("0", mbeanServer.getAttribute(name, "FileSize").toString());
assertEquals("0", mbeanServer.getAttribute(name, "FileReadCount").toString());
assertEquals("0", mbeanServer.getAttribute(name, "FileWriteCount").toString());
assertEquals("0", mbeanServer.getAttribute(name, "FileWriteCountTotal").toString());
if (config.mvStore) {
assertEquals("1", mbeanServer.getAttribute(name, "LogMode").toString());
mbeanServer.setAttribute(name, new Attribute("LogMode", 2));
assertEquals("2", mbeanServer.getAttribute(name, "LogMode").toString());
}
assertEquals("REGULAR", mbeanServer.getAttribute(name, "Mode").toString());
if (config.multiThreaded) {
assertEquals("true", mbeanServer.getAttribute(name, "MultiThreaded").toString());
} else {
assertEquals("false", mbeanServer.getAttribute(name, "MultiThreaded").toString());
}
if (config.mvStore) {
assertEquals("true", mbeanServer.getAttribute(name, "Mvcc").toString());
} else {
assertEquals("false", mbeanServer.getAttribute(name, "Mvcc").toString());
}
assertEquals("false", mbeanServer.getAttribute(name, "ReadOnly").toString());
assertEquals("1", mbeanServer.getAttribute(name, "TraceLevel").toString());
mbeanServer.setAttribute(name, new Attribute("TraceLevel", 0));
assertEquals("0", mbeanServer.getAttribute(name, "TraceLevel").toString());
assertTrue(mbeanServer.getAttribute(name, "Version").toString().startsWith("1."));
assertEquals(14, info.getAttributes().length);
result = mbeanServer.invoke(name, "listSettings", null, null).toString();
assertContains(result, "ANALYZE_AUTO");
conn.setAutoCommit(false);
stat.execute("create table test(id int)");
stat.execute("insert into test values(1)");
result = mbeanServer.invoke(name, "listSessions", null, null).toString();
assertContains(result, "session id");
if (config.mvcc || config.mvStore) {
assertContains(result, "read lock");
} else {
assertContains(result, "write lock");
}
assertEquals(2, info.getOperations().length);
assertContains(info.getDescription(), "database");
attrMap = new HashMap<>();
for (MBeanAttributeInfo a : info.getAttributes()) {
attrMap.put(a.getName(), a);
}
assertContains(attrMap.get("CacheSize").getDescription(), "KB");
opMap = new HashMap<>();
for (MBeanOperationInfo o : info.getOperations()) {
opMap.put(o.getName(), o);
}
assertContains(opMap.get("listSessions").getDescription(), "lock");
assertEquals(MBeanOperationInfo.INFO, opMap.get("listSessions").getImpact());
conn.close();
conn = getConnection("jmx;jmx=true");
conn.close();
conn = getConnection("jmx;jmx=true");
name = new ObjectName("org.h2:name=JMX,*");
@SuppressWarnings("rawtypes") Set set = mbeanServer.queryNames(name, null);
name = (ObjectName) set.iterator().next();
if (config.memory) {
assertEquals("0", mbeanServer.getAttribute(name, "CacheSizeMax").toString());
} else {
assertEquals("16384", mbeanServer.getAttribute(name, "CacheSizeMax").toString());
}
mbeanServer.setAttribute(name, new Attribute("CacheSizeMax", 1));
if (config.memory) {
assertEquals("0", mbeanServer.getAttribute(name, "CacheSizeMax").toString());
} else if (config.mvStore) {
assertEquals("1024", mbeanServer.getAttribute(name, "CacheSizeMax").toString());
assertEquals("0", mbeanServer.getAttribute(name, "CacheSize").toString());
assertTrue(0 < (Long) mbeanServer.getAttribute(name, "FileReadCount"));
assertTrue(0 < (Long) mbeanServer.getAttribute(name, "FileWriteCount"));
assertEquals("0", mbeanServer.getAttribute(name, "FileWriteCountTotal").toString());
} else {
assertEquals("1", mbeanServer.getAttribute(name, "CacheSizeMax").toString());
assertTrue(0 < (Integer) mbeanServer.getAttribute(name, "CacheSize"));
assertTrue(0 < (Long) mbeanServer.getAttribute(name, "FileSize"));
assertTrue(0 < (Long) mbeanServer.getAttribute(name, "FileReadCount"));
assertTrue(0 < (Long) mbeanServer.getAttribute(name, "FileWriteCount"));
assertTrue(0 < (Long) mbeanServer.getAttribute(name, "FileWriteCountTotal"));
}
mbeanServer.setAttribute(name, new Attribute("LogMode", 0));
assertEquals("0", mbeanServer.getAttribute(name, "LogMode").toString());
conn.close();
}
use of javax.management.MBeanOperationInfo in project spring-integration by spring-projects.
the class MBeanExporterIntegrationTests method testLifecycleInEndpointWithoutMessageSource.
@Test
public void testLifecycleInEndpointWithoutMessageSource() throws Exception {
context = new GenericXmlApplicationContext(getClass(), "lifecycle-no-source.xml");
messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
assertNotNull(messageChannelsMonitor);
MBeanServer server = context.getBean(MBeanServer.class);
Set<ObjectName> names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
assertEquals(1, names.size());
names = server.queryNames(ObjectName.getInstance("org.springframework.integration:name=gateway,*"), null);
assertEquals(1, names.size());
MBeanOperationInfo[] operations = server.getMBeanInfo(names.iterator().next()).getOperations();
String startName = null;
for (MBeanOperationInfo info : operations) {
String name = info.getName();
if (name.startsWith("start")) {
startName = name;
}
}
// Lifecycle method name
assertEquals("start", startName);
context.close();
context = new GenericXmlApplicationContext(getClass(), "lifecycle-no-source.xml");
server = context.getBean(MBeanServer.class);
names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
assertEquals(1, names.size());
names = server.queryNames(ObjectName.getInstance("org.springframework.integration:name=gateway,*"), null);
assertEquals(1, names.size());
}
use of javax.management.MBeanOperationInfo in project spring-integration by spring-projects.
the class MBeanExporterIntegrationTests method testLifecycleInEndpointWithMessageSource.
@Test
public void testLifecycleInEndpointWithMessageSource() throws Exception {
context = new GenericXmlApplicationContext(getClass(), "lifecycle-source.xml");
messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
assertNotNull(messageChannelsMonitor);
MBeanServer server = context.getBean(MBeanServer.class);
Set<ObjectName> names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
assertEquals(2, names.size());
names = server.queryNames(ObjectName.getInstance("org.springframework.integration:name=explicit,*"), null);
assertEquals(1, names.size());
MBeanOperationInfo[] operations = server.getMBeanInfo(names.iterator().next()).getOperations();
String startName = null;
for (MBeanOperationInfo info : operations) {
String name = info.getName();
if (name.startsWith("start")) {
startName = name;
}
}
// Lifecycle method name
assertEquals("start", startName);
assertTrue((Boolean) server.invoke(names.iterator().next(), "isRunning", null, null));
messageChannelsMonitor.stopActiveComponents(3000);
assertFalse((Boolean) server.invoke(names.iterator().next(), "isRunning", null, null));
ActiveChannel activeChannel = context.getBean("activeChannel", ActiveChannel.class);
assertTrue(activeChannel.isStopCalled());
OtherActiveComponent otherActiveComponent = context.getBean(OtherActiveComponent.class);
assertTrue(otherActiveComponent.isBeforeCalled());
assertTrue(otherActiveComponent.isAfterCalled());
assertTrue(otherActiveComponent.isRunning());
assertFalse(context.getBean(AMessageProducer.class).isRunning());
// check pollers are still running
QueueChannel input = (QueueChannel) extractTarget(context.getBean("input"));
QueueChannel input2 = (QueueChannel) extractTarget(context.getBean("input2"));
input.purge(null);
input2.purge(null);
input.send(new GenericMessage<String>("foo"));
assertNotNull(input2.receive(10000));
}
Aggregations