Search in sources :

Example 86 with MBeanOperationInfo

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;
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) Operation(org.apache.activemq.artemis.api.core.management.Operation) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 87 with MBeanOperationInfo

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);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 88 with MBeanOperationInfo

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();
}
Also used : Set(java.util.Set) MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) MBeanOperationInfo(javax.management.MBeanOperationInfo) Statement(java.sql.Statement) Connection(java.sql.Connection) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 89 with MBeanOperationInfo

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());
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 90 with MBeanOperationInfo

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));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MBeanOperationInfo(javax.management.MBeanOperationInfo) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

MBeanOperationInfo (javax.management.MBeanOperationInfo)117 MBeanInfo (javax.management.MBeanInfo)76 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)59 MBeanParameterInfo (javax.management.MBeanParameterInfo)38 ObjectName (javax.management.ObjectName)33 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)23 ArrayList (java.util.ArrayList)22 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)20 InstanceNotFoundException (javax.management.InstanceNotFoundException)19 ReflectionException (javax.management.ReflectionException)17 Test (org.junit.Test)16 IntrospectionException (javax.management.IntrospectionException)13 MBeanServer (javax.management.MBeanServer)13 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 Test (org.testng.annotations.Test)9 Method (java.lang.reflect.Method)8 Attribute (javax.management.Attribute)8 Descriptor (javax.management.Descriptor)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)5