Search in sources :

Example 31 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo 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 32 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo 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)

Example 33 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project Entitas-Java by Rubentxu.

the class VisualDebbuger method start.

@Override
public void start(Stage primaryStage) throws Exception {
    FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("VisualDebbuger.fxml"));
    Parent root = loader.load();
    primaryStage.setTitle("CodeGenerator");
    primaryStage.setScene(new Scene(root, 560, 575));
    primaryStage.setResizable(false);
    primaryStage.show();
    stage = primaryStage;
    client = new JmxClient("localhost", 1313);
    Set<ObjectName> names = client.getBeanNames();
    beanNames.setText(names.stream().map(n -> n.getKeyPropertyListString()).reduce(String::concat).get());
//        MBeanAttributeInfo[] attributeInfos =
//                client.getAttributesInfo(objectName);
//        MBeanOperationInfo[] operationInfos =
//                client.getOperationsInfo(objectName);
}
Also used : Scene(javafx.scene.Scene) Initializable(javafx.fxml.Initializable) Properties(java.util.Properties) javafx.scene.control(javafx.scene.control) URL(java.net.URL) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) Set(java.util.Set) JmxClient(com.j256.simplejmx.client.JmxClient) ObjectName(javax.management.ObjectName) Application(javafx.application.Application) FXML(javafx.fxml.FXML) Parent(javafx.scene.Parent) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) java.io(java.io) ResourceBundle(java.util.ResourceBundle) FXMLLoader(javafx.fxml.FXMLLoader) DirectoryChooser(javafx.stage.DirectoryChooser) Parent(javafx.scene.Parent) JmxClient(com.j256.simplejmx.client.JmxClient) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) ObjectName(javax.management.ObjectName)

Example 34 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project tdi-studio-se by Talend.

the class AttributeContentProvider method refresh.

/**
     * Refreshes the content provider.
     * 
     * @param jvm The JVM
     * @param objectName The object name
     * @throws JvmCoreException
     */
protected void refresh(IActiveJvm jvm, ObjectName objectName) throws JvmCoreException {
    MBeanInfo mBeanInfo = null;
    List<AttributeNode> nodes = new ArrayList<AttributeNode>();
    try {
        mBeanInfo = jvm.getMBeanServer().getMBeanInfo(objectName);
    } catch (JvmCoreException e) {
        attributeRootNodes = nodes;
        throw e;
    }
    if (mBeanInfo == null) {
        attributeRootNodes = nodes;
        return;
    }
    AttributeParser parser = new AttributeParser();
    for (MBeanAttributeInfo attributeInfo : mBeanInfo.getAttributes()) {
        String name = attributeInfo.getName();
        Object value = getAttributeValue(jvm, objectName, name);
        AttributeNode attributeNode = null;
        for (AttributeNode node : attributeRootNodes) {
            if (node.getName().equals(name)) {
                attributeNode = node;
                attributeNode.setValue(value);
                break;
            }
        }
        if (attributeNode == null) {
            attributeNode = new AttributeNode(name, null, value);
        }
        parser.refreshAttribute(attributeNode);
        attributeNode.setWritable(attributeInfo.isWritable());
        nodes.add(attributeNode);
    }
    Collections.sort(nodes, new Comparator<AttributeNode>() {

        @Override
        public int compare(AttributeNode o1, AttributeNode o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    attributeRootNodes = nodes;
}
Also used : MBeanInfo(javax.management.MBeanInfo) ArrayList(java.util.ArrayList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 35 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo 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)

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