Search in sources :

Example 21 with MBeanInfo

use of javax.management.MBeanInfo in project tesb-studio-se by Talend.

the class OpenRuntimeInfoAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    MBeanServerConnection mbsc;
    try {
        mbsc = JMXUtil.createJMXconnection();
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        //$NON-NLS-1$
        String JOB_MBEAN = "TalendAgent:type=O.S. Informations";
        ObjectName objectJob = new ObjectName(JOB_MBEAN);
        MBeanInfo info = mbsc.getMBeanInfo(objectJob);
        MBeanAttributeInfo[] attrInfo = info.getAttributes();
        for (int i = 0; i < attrInfo.length; i++) {
            try {
                Map<String, String> attributeMap = new HashMap<String, String>();
                String attributeName = attrInfo[i].getName();
                //$NON-NLS-1$
                attributeMap.put("name", attributeName);
                String attributeDesc = attrInfo[i].getType();
                //$NON-NLS-1$
                attributeMap.put("desc", attributeDesc);
                String attributeValue = mbsc.getAttribute(objectJob, attributeName).toString();
                attributeMap.put(attributeName, attributeValue);
                //$NON-NLS-1$
                attributeMap.put("value", attributeValue);
                list.add(attributeMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        RuntimeInfoDialog dlg = new RuntimeInfoDialog(list);
        dlg.open();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) RuntimeInfoDialog(org.talend.designer.esb.runcontainer.ui.dialog.RuntimeInfoDialog) HashMap(java.util.HashMap) Map(java.util.Map) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 22 with MBeanInfo

use of javax.management.MBeanInfo 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 23 with MBeanInfo

use of javax.management.MBeanInfo 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 24 with MBeanInfo

use of javax.management.MBeanInfo in project opennms by OpenNMS.

the class QueryCommand method prettyPrint.

private void prettyPrint(QueryResult result) {
    for (QueryResult.MBeanResult eachMBeanResult : result.getMBeanResults()) {
        MBeanInfo mbeanInfo = eachMBeanResult.mbeanInfo;
        ObjectName objectName = eachMBeanResult.objectName;
        QueryResult.AttributeResult attributeResult = eachMBeanResult.attributeResult;
        LOG.info(String.format("%s", objectName));
        LOG.info(String.format("\tdescription: %s", toString(mbeanInfo.getDescription())));
        LOG.info(String.format("\tclass name: %s", mbeanInfo.getClassName()));
        LOG.info(String.format("\tattributes: (%d/%d)", attributeResult.attributes.size(), attributeResult.totalCount));
        for (MBeanAttributeInfo eachAttribute : attributeResult.attributes) {
            LOG.info(String.format("\t\t%s", eachAttribute.getName()));
            LOG.info(String.format("\t\t\tid: %s", toAttributeId(objectName, eachAttribute)));
            LOG.info(String.format("\t\t\tdescription: %s", toString(eachAttribute.getDescription())));
            LOG.info(String.format("\t\t\ttype: %s", eachAttribute.getType()));
            LOG.info(String.format("\t\t\tisReadable: %s", eachAttribute.isReadable()));
            LOG.info(String.format("\t\t\tisWritable: %s", eachAttribute.isWritable()));
            LOG.info(String.format("\t\t\tisIs: %s", eachAttribute.isIs()));
            if (includeValues) {
                LOG.info(String.format("\t\t\tvalue: %s", toString(attributeResult.getValue(eachAttribute))));
            }
        }
    }
    if (filter != null && !filter.isEmpty()) {
        LOG.info(String.format("Your query '%s' shows %d/%d MBeans.", filter, result.getMBeanResults().size(), result.getTotalMBeanCount()));
    } else {
        LOG.info(String.format("There are %d registered MBeans", result.getTotalMBeanCount()));
    }
    if (ignoreFilter != null && !ignoreFilter.isEmpty()) {
        LOG.info(String.format("While querying, the following query was used to exclude MBeans/Attributes: '%s'", ignoreFilter));
    }
}
Also used : QueryResult(org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult) MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName)

Example 25 with MBeanInfo

use of javax.management.MBeanInfo in project opennms by OpenNMS.

the class MBeanServerQuery method executeQuery.

private static QueryResult executeQuery(List<FilterCriteria> filterCriteriaList, MBeanServerConnection mbeanServerConnection) throws IOException, JMException {
    QueryResult result = new QueryResult();
    for (FilterCriteria eachFilterCriteria : filterCriteriaList) {
        ObjectName query = eachFilterCriteria.objectName != null ? new ObjectName(eachFilterCriteria.objectName) : null;
        Set<ObjectName> tmpObjectNames = mbeanServerConnection.queryNames(query, null);
        // Now we filter the MBeans attributes (Default: show all)
        for (ObjectName eachObjectName : tmpObjectNames) {
            MBeanInfo mbeanInfo = mbeanServerConnection.getMBeanInfo(eachObjectName);
            result.put(eachObjectName, mbeanInfo);
            result.setAttributeTotalCount(eachObjectName, mbeanInfo.getAttributes().length);
            for (MBeanAttributeInfo eachAttribute : mbeanInfo.getAttributes()) {
                if (eachFilterCriteria.matches(eachAttribute)) {
                    result.put(eachObjectName, eachAttribute);
                }
            }
        }
    }
    return result;
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName)

Aggregations

MBeanInfo (javax.management.MBeanInfo)154 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)87 ObjectName (javax.management.ObjectName)79 MBeanOperationInfo (javax.management.MBeanOperationInfo)38 MBeanServer (javax.management.MBeanServer)27 Test (org.junit.Test)27 Attribute (javax.management.Attribute)19 ArrayList (java.util.ArrayList)17 IntrospectionException (javax.management.IntrospectionException)16 ReflectionException (javax.management.ReflectionException)16 HashMap (java.util.HashMap)15 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 IOException (java.io.IOException)12 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)12 MBeanParameterInfo (javax.management.MBeanParameterInfo)12 MBeanServerConnection (javax.management.MBeanServerConnection)10 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 AttributeList (javax.management.AttributeList)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)9 Descriptor (javax.management.Descriptor)8