Search in sources :

Example 36 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project Activiti by Activiti.

the class JobExecutorMBeanTest method testAnnotations.

@Test
public void testAnnotations() throws MalformedObjectNameException, JMException {
    ModelMBean modelBean = assembler.assemble(jobExecutorMbean, new ObjectName("domain", "key", "value"));
    assertNotNull(modelBean);
    MBeanInfo beanInfo = modelBean.getMBeanInfo();
    assertNotNull(beanInfo);
    assertNotNull(beanInfo.getOperations());
    assertEquals(2, beanInfo.getOperations().length);
    int counter = 0;
    for (MBeanOperationInfo op : beanInfo.getOperations()) {
        if (op.getName().equals("setJobExecutorActivate")) {
            counter++;
            assertEquals("set job executor activate", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.Boolean", op.getSignature()[0].getType());
        }
    }
    assertEquals(1, counter);
    // check attributes
    assertNotNull(beanInfo.getAttributes());
    assertEquals(1, beanInfo.getAttributes().length);
    counter = 0;
    for (MBeanAttributeInfo attr : beanInfo.getAttributes()) {
        if (attr.getName().equals("JobExecutorActivated")) {
            counter++;
            assertEquals("check if the job executor is activated", attr.getDescription());
            assertEquals("boolean", attr.getType());
        }
    }
    assertEquals(1, counter);
}
Also used : ModelMBean(javax.management.modelmbean.ModelMBean) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 37 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project Activiti by Activiti.

the class ProcessDefinitionsTest method testAnnotations.

@Test
public void testAnnotations() throws MalformedObjectNameException, JMException {
    ModelMBean modelBean = assembler.assemble(processDefinitionsMBean, new ObjectName("domain", "key", "value"));
    assertNotNull(modelBean);
    MBeanInfo beanInfo = modelBean.getMBeanInfo();
    assertNotNull(beanInfo);
    assertNotNull(beanInfo.getOperations());
    assertEquals(9, beanInfo.getOperations().length);
    int counter = 0;
    for (MBeanOperationInfo op : beanInfo.getOperations()) {
        if (op.getName().equals("deleteDeployment")) {
            counter++;
            assertEquals("delete deployment", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
        } else if (op.getName().equals("suspendProcessDefinitionById")) {
            counter++;
            assertEquals("Suspend given process ID", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
        } else if (op.getName().equals("activatedProcessDefinitionById")) {
            counter++;
            assertEquals("Activate given process ID", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
        } else if (op.getName().equals("suspendProcessDefinitionByKey")) {
            counter++;
            assertEquals("Suspend given process ID", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
        } else if (op.getName().equals("activatedProcessDefinitionByKey")) {
            counter++;
            assertEquals("Activate given process ID", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(1, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
        } else if (op.getName().equals("deployProcessDefinition")) {
            counter++;
            assertEquals("Deploy Process Definition", op.getDescription());
            assertEquals("void", op.getReturnType());
            assertEquals(2, op.getSignature().length);
            assertEquals("java.lang.String", op.getSignature()[0].getType());
            assertEquals("java.lang.String", op.getSignature()[1].getType());
        }
    }
    assertEquals(6, counter);
    // check attributes
    assertNotNull(beanInfo.getAttributes());
    assertEquals(2, beanInfo.getAttributes().length);
    counter = 0;
    for (MBeanAttributeInfo attr : beanInfo.getAttributes()) {
        if (attr.getName().equals("ProcessDefinitions")) {
            counter++;
            assertEquals("List of Process definitions", attr.getDescription());
            assertEquals("java.util.List", attr.getType());
        } else if (attr.getName().equals("Deployments")) {
            counter++;
            assertEquals("List of deployed Processes", attr.getDescription());
            assertEquals("java.util.List", attr.getType());
        }
    }
    assertEquals(2, counter);
}
Also used : ModelMBean(javax.management.modelmbean.ModelMBean) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 38 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project ats-framework by Axway.

the class SystemOperations method getJvmMbeans.

/**
     * @param host the address of the host machine
     * @param jmxPort the jmx port
     * 
     * @return all MBeans with their attributes and type
     * @throws SystemOperationException
     */
@PublicAtsApi
public String getJvmMbeans(String host, String jmxPort) {
    JMXConnector jmxCon = null;
    try {
        // Connect to JMXConnector
        JMXServiceURL serviceUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi");
        jmxCon = JMXConnectorFactory.newJMXConnector(serviceUrl, null);
        jmxCon.connect();
        // Access the MBean
        MBeanServerConnection con = jmxCon.getMBeanServerConnection();
        Set<ObjectName> queryResults = con.queryNames(null, null);
        StringBuilder results = new StringBuilder();
        for (ObjectName theName : queryResults) {
            results.append("\n---");
            results.append("\nMBean name: " + theName.getCanonicalName());
            MBeanAttributeInfo[] attributes = con.getMBeanInfo(theName).getAttributes();
            for (MBeanAttributeInfo attribute : attributes) {
                if (attribute.getType() != null) {
                    if (!"javax.management.openmbean.CompositeData".equals(attribute.getType())) {
                        if ("java.lang.Long".equals(attribute.getType()) || "java.lang.Integer".equals(attribute.getType()) || "int".equals(attribute.getType()) || "long".equals(attribute.getType()))
                            results.append("\r   " + attribute.getName() + " | " + attribute.getType());
                    } else {
                        results.append("\r   " + attribute.getName() + " | " + attribute.getType());
                        CompositeData comdata = (CompositeData) con.getAttribute(theName, attribute.getName());
                        if (comdata != null) {
                            for (String key : comdata.getCompositeType().keySet()) {
                                Object value = comdata.get(key);
                                if (value instanceof Integer || value instanceof Double || value instanceof Long)
                                    results.append("\r      " + key + " | " + value.getClass());
                            }
                        }
                    }
                }
            }
        }
        return results.toString();
    } catch (Exception e) {
        throw new SystemOperationException("MBeans with their attributes cannot be get.", e);
    } finally {
        if (jmxCon != null)
            try {
                jmxCon.close();
            } catch (IOException e) {
                log.error("JMX connection was not closed!");
            }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) SystemOperationException(com.axway.ats.common.system.SystemOperationException) CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IOException(java.io.IOException) SystemOperationException(com.axway.ats.common.system.SystemOperationException) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 39 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project ats-framework by Axway.

the class MBeanWrapper method getMBeanAttribute.

/**
     * Gets the value of a specific attribute of a named MBean
     * 
     * @param objectName the object name
     * @param attributeName the attribute name
     * @return the attribute value
     */
Object getMBeanAttribute(ObjectName objectName, String attributeName) {
    try {
        for (MBeanAttributeInfo attInfo : connection.getMBeanInfo(objectName).getAttributes()) {
            String attName = attInfo.getName();
            if (attName.equals(attributeName)) {
                return connection.getAttribute(objectName, attributeName);
            }
        }
    } catch (Exception e) {
        final String errorMsg = "Error getting the value of the '" + attributeName + "' attribute of MBean with name '" + objectName + "'";
        log.error(errorMsg, e);
        throw new MonitorConfigurationException(errorMsg, e);
    }
    final String errorMsg = "Error getting the value of the '" + attributeName + "' attribute of MBean with name '" + objectName + "': The attribute is not found!";
    log.error(errorMsg);
    throw new MonitorConfigurationException(errorMsg);
}
Also used : MonitorConfigurationException(com.axway.ats.agent.components.monitoring.model.exceptions.MonitorConfigurationException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MonitorConfigurationException(com.axway.ats.agent.components.monitoring.model.exceptions.MonitorConfigurationException)

Example 40 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project geode by apache.

the class MX4JModelMBean method removeAttributeChangeNotificationListener.

// Not in the spec but needed
private void removeAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, ListenerNotFoundException {
    if (listener == null)
        throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString()));
    AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter();
    if (attributeName != null) {
        filter.enableAttribute(attributeName);
    } else {
        MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes();
        for (int i = 0; i < ai.length; i++) {
            Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor();
            filter.enableAttribute((String) d.getFieldValue("name"));
        }
    }
    getAttributeChangeBroadcaster().removeNotificationListener(listener, filter, handback);
    Logger logger = getLogger();
    if (logger.isEnabledFor(Logger.DEBUG))
        logger.debug("Listener " + listener + " for attribute " + attributeName + " removed successfully, handback is " + handback);
}
Also used : ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) AttributeChangeNotificationFilter(javax.management.AttributeChangeNotificationFilter) Descriptor(javax.management.Descriptor) Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

MBeanAttributeInfo (javax.management.MBeanAttributeInfo)106 MBeanInfo (javax.management.MBeanInfo)75 ObjectName (javax.management.ObjectName)45 MBeanOperationInfo (javax.management.MBeanOperationInfo)24 Test (org.junit.Test)21 MBeanServer (javax.management.MBeanServer)15 ArrayList (java.util.ArrayList)13 AttributeNotFoundException (javax.management.AttributeNotFoundException)12 ReflectionException (javax.management.ReflectionException)12 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)11 IOException (java.io.IOException)10 AttributeList (javax.management.AttributeList)10 Attribute (javax.management.Attribute)9 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 IntrospectionException (javax.management.IntrospectionException)9 MBeanParameterInfo (javax.management.MBeanParameterInfo)9 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)9 HashMap (java.util.HashMap)8 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)7 MBeanException (javax.management.MBeanException)7