Search in sources :

Example 6 with ManagedBeanInfo

use of com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo in project cuba by cuba-platform.

the class MbeansDisplayWindow method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    objectNameField.addValueChangeListener(new ObjectNameFieldListener());
    mbeansTable.addAction(new RefreshAction(mbeansTable));
    Action inspectAction = new ItemTrackingAction("inspect").withCaption(getMessage("action.inspect")).withHandler(event -> {
        Set<ManagedBeanInfo> selected = mbeansTable.getSelected();
        if (!selected.isEmpty()) {
            ManagedBeanInfo mbi = selected.iterator().next();
            if (mbi.getObjectName() != null) {
                // otherwise it's a fake root node
                Window editor = openEditor("jmxConsoleInspectMbean", mbi, OpenType.THIS_TAB);
                editor.addCloseListener(actionId -> {
                    mbeansTable.requestFocus();
                });
            } else {
                // expand / collapse fake root node
                UUID itemId = mbi.getId();
                if (mbeansTable.isExpanded(itemId)) {
                    mbeansTable.collapse(itemId);
                } else {
                    mbeansTable.expand(itemId);
                }
            }
        }
    });
    mbeansTable.addAction(inspectAction);
    mbeansTable.setItemClickAction(inspectAction);
    localJmxInstance = jmxControlAPI.getLocalInstance();
    jmxInstancesDs.refresh();
    jmxConnectionField.setValue(localJmxInstance);
    jmxConnectionField.setRequired(true);
    jmxConnectionField.addValueChangeListener(e -> {
        JmxInstance jmxInstance = (JmxInstance) e.getValue();
        try {
            mbeanDs.setJmxInstance(jmxInstance);
            mbeanDs.refresh();
        } catch (JmxControlException ex) {
            showNotification(getMessage("unableToConnectToInterface"), NotificationType.WARNING);
            if (jmxInstance != localJmxInstance) {
                jmxConnectionField.setValue(localJmxInstance);
            }
        }
    });
    jmxConnectionField.removeAllActions();
    jmxConnectionField.addAction(new PickerField.LookupAction(jmxConnectionField) {

        @Override
        public void afterCloseLookup(String actionId) {
            jmxInstancesDs.refresh();
        }
    });
    jmxConnectionField.addAction(new BaseAction("actions.Add").withIcon("icons/plus-btn.png").withHandler(event -> {
        JmxInstanceEditor instanceEditor = (JmxInstanceEditor) openEditor(metadata.create(JmxInstance.class), OpenType.DIALOG);
        instanceEditor.addCloseListener(actionId -> {
            if (COMMIT_ACTION_ID.equals(actionId)) {
                jmxInstancesDs.refresh();
                jmxConnectionField.setValue(instanceEditor.getItem());
            }
        });
    }));
    mbeanDs.setJmxInstance(localJmxInstance);
    mbeanDs.refresh();
    localJmxField.setValue(jmxControlAPI.getLocalNodeName());
    localJmxField.setEditable(false);
    mbeansTable.setStyleProvider((entity, property) -> {
        if (entity != null && entity.getObjectName() == null) {
            return "c-jmx-tree-table-domain";
        }
        return null;
    });
}
Also used : JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) StringUtils(org.apache.commons.lang.StringUtils) RefreshAction(com.haulmont.cuba.gui.components.actions.RefreshAction) ManagedBeanInfoDatasource(com.haulmont.cuba.web.app.ui.jmxcontrol.ds.ManagedBeanInfoDatasource) Resource(javax.annotation.Resource) ParamsMap(com.haulmont.bali.util.ParamsMap) Set(java.util.Set) UUID(java.util.UUID) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) Metadata(com.haulmont.cuba.core.global.Metadata) Inject(javax.inject.Inject) JmxControlAPI(com.haulmont.cuba.web.jmx.JmxControlAPI) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) Map(java.util.Map) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) RefreshAction(com.haulmont.cuba.gui.components.actions.RefreshAction) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) RefreshAction(com.haulmont.cuba.gui.components.actions.RefreshAction) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) UUID(java.util.UUID)

Example 7 with ManagedBeanInfo

use of com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo in project cuba by cuba-platform.

the class ManagedBeanAttributeDatasource method loadData.

@Override
protected void loadData(Map<String, Object> params) {
    data.clear();
    Datasource mbeanDs = getDsContext().get("mbeanDs");
    ManagedBeanInfo mbean = (ManagedBeanInfo) mbeanDs.getItem();
    if (mbean != null) {
        try {
            jmxControlAPI.loadAttributes(mbean);
        } catch (JmxControlException e) {
            log.error("Error loading attributes", e);
        }
        if (mbean.getAttributes() != null) {
            for (ManagedBeanAttribute attr : mbean.getAttributes()) {
                data.put(attr.getId(), attr);
            }
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) ManagedBeanAttribute(com.haulmont.cuba.web.jmx.entity.ManagedBeanAttribute) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException)

Example 8 with ManagedBeanInfo

use of com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo in project cuba by cuba-platform.

the class ThreadsDatasource method getStackTrace.

protected String getStackTrace(Long threadId) {
    JmxInstance node = (JmxInstance) savedParameters.get("node");
    ManagedBeanInfo threadingBean = jmxControlAPI.getManagedBean(node, "java.lang:type=Threading");
    ManagedBeanOperation getThreadInfo = jmxControlAPI.getOperation(threadingBean, "getThreadInfo", new String[] { "long", "int" });
    CompositeData threadInfo = (CompositeData) jmxControlAPI.invokeOperation(getThreadInfo, new Object[] { threadId, Integer.MAX_VALUE });
    StringBuilder sb = new StringBuilder();
    if (threadInfo != null) {
        CompositeData[] traces = (CompositeData[]) threadInfo.get("stackTrace");
        ThreadSnapshot t = getThreadSnapshot(threadId);
        sb.append(t.getName()).append(" [id=").append(threadId).append("] (").append(t.getStatus()).append(")\n");
        for (CompositeData trace : traces) {
            String className = (String) trace.get("className");
            String methodName = (String) trace.get("methodName");
            int line = (int) trace.get("lineNumber");
            sb.append(className).append(".").append(methodName).append(":").append(line).append("\n");
        }
    }
    return sb.toString();
}
Also used : ManagedBeanOperation(com.haulmont.cuba.web.jmx.entity.ManagedBeanOperation) CompositeData(javax.management.openmbean.CompositeData) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance)

Aggregations

ManagedBeanInfo (com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo)8 JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)3 ManagedBeanAttribute (com.haulmont.cuba.web.jmx.entity.ManagedBeanAttribute)3 JmxControlException (com.haulmont.cuba.web.jmx.JmxControlException)2 ManagedBeanOperation (com.haulmont.cuba.web.jmx.entity.ManagedBeanOperation)2 CompositeData (javax.management.openmbean.CompositeData)2 Node (com.haulmont.bali.datastruct.Node)1 Tree (com.haulmont.bali.datastruct.Tree)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)1 ItemTrackingAction (com.haulmont.cuba.gui.components.actions.ItemTrackingAction)1 RefreshAction (com.haulmont.cuba.gui.components.actions.RefreshAction)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 UIPerformanceLogger (com.haulmont.cuba.gui.logging.UIPerformanceLogger)1 ManagedBeanInfoDatasource (com.haulmont.cuba.web.app.ui.jmxcontrol.ds.ManagedBeanInfoDatasource)1 JmxInstanceEditor (com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor)1