diff options
| author | Bhupendra Bhusman Bhardwaj <bhupendrab@apache.org> | 2007-01-04 10:52:06 +0000 |
|---|---|---|
| committer | Bhupendra Bhusman Bhardwaj <bhupendrab@apache.org> | 2007-01-04 10:52:06 +0000 |
| commit | 9330086f7b8a88f0cb405f5716b56b9d6bd9d474 (patch) | |
| tree | 5f4d83676214c59ec35fe5d345a2f39318156810 /java/management/eclipse-plugin/src | |
| parent | 1f6c4e5d1d5966bc994613227525d47d0426ada6 (diff) | |
| download | qpid-python-9330086f7b8a88f0cb405f5716b56b9d6bd9d474.tar.gz | |
QPID-213
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@492514 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/management/eclipse-plugin/src')
6 files changed, 198 insertions, 34 deletions
diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java index 479dc05a68..756d404596 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java @@ -39,6 +39,8 @@ public class Constants public final static String NOTIFICATION = "Notifications"; public final static String RESULT = "Result"; + public final static String ATTRIBUTE_QUEUE_DEPTH = "QueueDepth"; + public final static String ALL = "All"; public final static String NAVIGATION_ROOT = "Qpid Connections"; diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java index aab163cac3..8334beeeb9 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java @@ -176,7 +176,7 @@ public class MBeanUtility { ViewUtility.popupErrorMessage(mbean.getName(), ex.toString()); } - //ex.printStackTrace(); + ex.printStackTrace(); } /** @@ -207,7 +207,36 @@ public class MBeanUtility serverRegistry.removeNotificationListener(mbean, name, type); } - public static int refreshAttribute(ManagedBean mbean, String attribute) throws Exception + /** + * Checks if the server registry contains attribute information for this mbean. If not then it queries the + * mbean server for complete mbean information, else it gets the latest value of the given attribute + * from mbean server. + * @return attribute data for the given mbean attribute + */ + public static AttributeData getAttributeData(ManagedBean mbean, String attribute) throws Exception + { + JMXServerRegistry serverRegistry = (JMXServerRegistry)ApplicationRegistry.getServerRegistry(mbean); + ManagedAttributeModel attributeModel = serverRegistry.getAttributeModel(mbean); + if (attributeModel == null) + { + // If process is here, it means the mbeanInfo is not retrieved from mbean server even once for this mbean + getMBeanInfo(mbean); + } + else + { + // refresh attribute value from mbean server + refreshAttribute(mbean, attribute); + } + attributeModel = serverRegistry.getAttributeModel(mbean); + return attributeModel.getAttribute(attribute); + } + + /** + * Retrieves the latest attribute value from mbean server for the given mbean attribute + * and also sets that value in the attribute model in the server registry + * @return latest attribute value for the given mbean attribute + */ + public static Object refreshAttribute(ManagedBean mbean, String attribute) throws Exception { JMXServerRegistry serverRegistry = (JMXServerRegistry)ApplicationRegistry.getServerRegistry(mbean); MBeanServerConnection mbsc = serverRegistry.getServerConnection(); @@ -218,10 +247,10 @@ public class MBeanUtility } Object value = mbsc.getAttribute(((JMXManagedObject)mbean).getObjectName(), attribute); - + // update the attribute data in server registry for this attribute ManagedAttributeModel attributeModel = serverRegistry.getAttributeModel(mbean); attributeModel.setAttributeValue(attribute, value); - return Integer.parseInt(String.valueOf(value)); + return value; } /** @@ -240,9 +269,12 @@ public class MBeanUtility MBeanServerConnection mbsc = serverRegistry.getServerConnection(); MBeanAttributeInfo[] attributesInfo = null; ManagedAttributeModel attributeModel = serverRegistry.getAttributeModel(mbean); - // If retrieving attributeInfo for the first time. + if (attributeModel == null) { + // If the process is here, then it means the attribute values are not retrieved from mbean server + // even once for this mbean. Create attribute model, retrieve values from mbean server and + // set the attribute model in server registry for this mbean attributeModel = new ManagedAttributeModel(); attributesInfo = serverRegistry.getMBeanInfo(mbean).getAttributes(); attributes = new String[attributesInfo.length]; @@ -314,8 +346,8 @@ public class MBeanUtility OperationDataModel dataModel = serverRegistry.getOperationModel(mbean); if (dataModel == null) { - MBeanInfo mbeanInfo = serverRegistry.getMBeanInfo(mbean); - MBeanOperationInfo[] operationsInfo = mbeanInfo.getOperations(); + // Create operation model and set it in server registry for this mbean + MBeanOperationInfo[] operationsInfo = serverRegistry.getMBeanInfo(mbean).getOperations(); dataModel = new OperationDataModel(); for (int i = 0; i < operationsInfo.length; i++) @@ -325,7 +357,6 @@ public class MBeanUtility serverRegistry.setOperationModel(mbean, dataModel); } - return dataModel; } @@ -336,15 +367,15 @@ public class MBeanUtility */ public static NotificationInfoModel[] getNotificationInfo(ManagedBean mbean) { - JMXServerRegistry serverRegistry = (JMXServerRegistry)ApplicationRegistry.getServerRegistry(mbean); MBeanNotificationInfo[] info = serverRegistry.getMBeanInfo(mbean).getNotifications(); + // Check if this mbean sends any notification if (info == null || info.length == 0) return null; + // Create notification model if not already set in the server registry for this mbean List<NotificationInfoModel> list = serverRegistry.getNotificationInfo(mbean); - if (list != null) return list.toArray(new NotificationInfoModel[0]); else @@ -354,11 +385,16 @@ public class MBeanUtility { list.add(new NotificationInfoModel(info[i].getName(), info[i].getDescription(), info[i].getNotifTypes())); } - serverRegistry.setNotificationInfo(mbean, list); + // Set the notification model in the server registry for this mbean + serverRegistry.setNotificationInfo(mbean, list); return list.toArray(new NotificationInfoModel[0]); } + /** + * Retrieves all the MBeans from mbean server for a given domain + * @return list of ManagedBeans + */ public static List<ManagedBean> getManagedObjectsForDomain(ManagedServer server, String domain) throws Exception { List<ManagedBean> mbeans = new ArrayList<ManagedBean>(); @@ -377,6 +413,10 @@ public class MBeanUtility return mbeans; } + /** + * Returns all the domains for the given server. This method can be removed as now this RCP is specific to + * Qpid and domain is also fixed + */ public static List<String> getAllDomains(ManagedServer server) throws Exception { JMXServerRegistry serverRegistry = (JMXServerRegistry)ApplicationRegistry.getServerRegistry(server); diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/model/ManagedAttributeModel.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/model/ManagedAttributeModel.java index 692e72fc5a..b3219f15ea 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/model/ManagedAttributeModel.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/model/ManagedAttributeModel.java @@ -106,6 +106,11 @@ public class ManagedAttributeModel return _attributeMap.values().toArray(new AttributeData[0]); } + public AttributeData getAttribute(String name) + { + return _attributeMap.get(name); + } + public int getCount() { return _attributeMap.size(); diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java index 36e808a043..8bf4e30c64 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java @@ -126,7 +126,7 @@ public class AttributesTabControl extends TabControl _tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); _tableComposite.setLayout(new GridLayout()); _buttonsComposite = _toolkit.createComposite(_form.getBody()); - _tableComposite.setLayoutData(new GridData()); + _buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true)); _buttonsComposite.setLayout(new GridLayout()); image = Display.getCurrent().getSystemImage(SWT.ICON_INFORMATION); @@ -175,7 +175,6 @@ public class AttributesTabControl extends TabControl /** * Creates tableviewer for the attribute's table - * */ private void createTableViewer() { @@ -200,7 +199,7 @@ public class AttributesTabControl extends TabControl // Create and configure the button for attribute details _detailsButton = _toolkit.createButton(_buttonsComposite, Constants.BUTTON_DETAILS, SWT.PUSH | SWT.CENTER); _detailsButton.setFont(ApplicationRegistry.getFont(Constants.FONT_BUTTON)); - GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); + GridData gridData = new GridData(SWT.CENTER, SWT.TOP, false, false); gridData.widthHint = 80; _detailsButton.setLayoutData(gridData); _detailsButton.addSelectionListener(new SelectionAdapter() @@ -225,7 +224,7 @@ public class AttributesTabControl extends TabControl // Create and configure the button for editing attribute _editButton = _toolkit.createButton(_buttonsComposite, Constants.BUTTON_EDIT_ATTRIBUTE, SWT.PUSH | SWT.CENTER); _editButton.setFont(ApplicationRegistry.getFont(Constants.FONT_BUTTON)); - GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); + GridData gridData = new GridData(SWT.CENTER, SWT.TOP, false, false); gridData.widthHint = 80; _editButton.setLayoutData(gridData); _editButton.addSelectionListener(new SelectionAdapter() @@ -247,7 +246,7 @@ public class AttributesTabControl extends TabControl { _graphButton = _toolkit.createButton(_buttonsComposite, Constants.BUTTON_GRAPH, SWT.PUSH | SWT.CENTER); _graphButton.setFont(ApplicationRegistry.getFont(Constants.FONT_BUTTON)); - GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); + GridData gridData = new GridData(SWT.CENTER, SWT.TOP, false, false); gridData.widthHint = 80; _graphButton.setLayoutData(gridData); _graphButton.addSelectionListener(new SelectionAdapter() @@ -270,7 +269,7 @@ public class AttributesTabControl extends TabControl _refreshButton = _toolkit.createButton(_buttonsComposite, Constants.BUTTON_REFRESH, SWT.PUSH | SWT.CENTER); _refreshButton.setFont(ApplicationRegistry.getFont(Constants.FONT_BUTTON)); - GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); + GridData gridData = new GridData(SWT.CENTER, SWT.TOP, false, false); gridData.widthHint = 80; _refreshButton.setLayoutData(gridData); _refreshButton.addSelectionListener(new SelectionAdapter() @@ -429,12 +428,14 @@ public class AttributesTabControl extends TabControl } Display display = Display.getCurrent(); - Shell shell = ViewUtility.createPopupShell("Attribute", width, height); + Shell shell = ViewUtility.createPopupShell(Constants.ATTRIBUTE, width, height); createDetailsPopupContents(shell, data); shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { + while (!shell.isDisposed()) + { + if (!display.readAndDispatch()) + { display.sleep(); } } @@ -818,7 +819,8 @@ public class AttributesTabControl extends TabControl private void animate(Canvas canvas, AttributeData data) throws Exception { String attribute = data.getName(); - int value = MBeanUtility.refreshAttribute(_mbean, attribute); + Object valueObj = MBeanUtility.refreshAttribute(_mbean, attribute); + int value = Integer.parseInt(String.valueOf(valueObj)); Object canvasData = canvas.getData(GRAPH_VALUES); long[] graphValues = (long[]) canvasData; diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java index fbd7084e3e..73d56634ec 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java @@ -1,13 +1,17 @@ package org.apache.qpid.management.ui.views; -import java.util.Arrays; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; import org.apache.qpid.management.ui.ApplicationRegistry; import org.apache.qpid.management.ui.Constants; import org.apache.qpid.management.ui.ManagedBean; import org.apache.qpid.management.ui.ServerRegistry; import org.apache.qpid.management.ui.jmx.MBeanUtility; +import org.apache.qpid.management.ui.model.AttributeData; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -24,6 +28,12 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.widgets.Form; import org.eclipse.ui.forms.widgets.FormToolkit; +/** + * Class to create widgets and control display for mbeantype(eg Connection, Queue, Exchange) selection + * on the navigation view. + * @author Bhupendra Bhardwaj + * + */ public class MBeanTypeTabControl { private FormToolkit _toolkit = null; @@ -31,18 +41,26 @@ public class MBeanTypeTabControl private TabFolder _tabFolder = null; private Composite _composite = null; private Composite _listComposite = null; + private Composite _buttonsComposite = null; private Label _labelName = null; private Label _labelDesc = null; private Label _labelList = null; + private org.eclipse.swt.widgets.List _list = null; private Button _refreshButton = null; private Button _addButton = null; + private Button _sortBySizeButton = null; private String _type = null; - // maps an mbena name with the mbean object. Required to get mbean object when an mbean + // maps an mbean name with the mbean object. Required to get mbean object when an mbean // is to be added to the navigation view. private HashMap<String, ManagedBean> _objectsMap = new HashMap<String, ManagedBean>(); + // Map required for sorting queues based on attribute values + private Map<AttributeData, ManagedBean> _queueMap = new LinkedHashMap<AttributeData, ManagedBean>(); + + private Sorter _sorterByName = new Sorter(); + private ComparatorImpl _sorterByQueueDepth = new ComparatorImpl(); public MBeanTypeTabControl(TabFolder tabFolder) { @@ -58,6 +76,9 @@ public class MBeanTypeTabControl return _form; } + /** + * Adds listeners to all the buttons + */ private void addListeners() { _addButton.addSelectionListener(new SelectionAdapter(){ @@ -69,7 +90,13 @@ public class MBeanTypeTabControl String[] selectedItems = _list.getSelection(); for (int i = 0; i < selectedItems.length; i++) { - String name = selectedItems[i]; + String name = selectedItems[i];; + if (Constants.QUEUE.equals(_type)) + { + int endIndex = name.lastIndexOf("("); + name = name.substring(0, endIndex -1); + } + // pass the ManagedBean to the navigation view to be added ManagedBean mbean = _objectsMap.get(name); IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); NavigationView view = (NavigationView)window.getActivePage().findView(NavigationView.ID); @@ -98,6 +125,20 @@ public class MBeanTypeTabControl } } }); + + _sortBySizeButton.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) + { + try + { + sortQueueByQueueDepth(); + } + catch (Exception ex) + { + MBeanUtility.handleException(ex); + } + } + }); } private void createWidgets() @@ -119,20 +160,22 @@ public class MBeanTypeTabControl _labelDesc.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false, 2, 1)); _labelDesc.setFont(ApplicationRegistry.getFont(Constants.FONT_ITALIC)); - _refreshButton = _toolkit.createButton(_composite, Constants.BUTTON_REFRESH, SWT.PUSH); - gridData = new GridData(SWT.CENTER, SWT.CENTER, false, false, 2, 1); - gridData.widthHint = 80; - _refreshButton.setLayoutData(gridData); - _addButton = _toolkit.createButton(_composite, "<- Add to Navigation", SWT.PUSH); gridData = new GridData(SWT.CENTER, SWT.CENTER, false, false); _addButton.setLayoutData(gridData); + _refreshButton = _toolkit.createButton(_composite, Constants.BUTTON_REFRESH, SWT.PUSH); + gridData = new GridData(SWT.CENTER, SWT.CENTER, false, false); + gridData.widthHint = 80; + _refreshButton.setLayoutData(gridData); + // Composite to contain the item list _listComposite = _toolkit.createComposite(_composite); gridData = new GridData(SWT.FILL, SWT.FILL, true, true); _listComposite.setLayoutData(gridData); - _listComposite.setLayout(new GridLayout()); + layout = new GridLayout(); + layout.verticalSpacing = 0; + _listComposite.setLayout(layout); // Label for item name _labelList = _toolkit.createLabel(_listComposite, " ", SWT.NONE); @@ -142,6 +185,18 @@ public class MBeanTypeTabControl _list = new List(_listComposite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); gridData = new GridData(SWT.FILL, SWT.FILL, true, true); _list.setLayoutData(gridData); + + + // Composite to contain buttons like - Sort by size + _buttonsComposite = _toolkit.createComposite(_composite); + gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + _buttonsComposite.setLayoutData(gridData); + _buttonsComposite.setLayout(new GridLayout()); + + _sortBySizeButton = _toolkit.createButton(_buttonsComposite, "Sort by Queue Depth", SWT.PUSH); + gridData = new GridData(SWT.CENTER, SWT.CENTER, true, false); + _sortBySizeButton.setLayoutData(gridData); + } public void refresh(String typeName) throws Exception @@ -170,6 +225,7 @@ public class MBeanTypeTabControl { // map should be cleared before populating it with new values _objectsMap.clear(); + _queueMap.clear(); ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(MBeanView.getServer()); String[] items = null; java.util.List<ManagedBean> list = null; @@ -178,27 +234,33 @@ public class MBeanTypeTabControl if (_type.equals(Constants.QUEUE)) { list = serverRegistry.getQueues(); + items = getQueueItems(list); + _sortBySizeButton.setVisible(true); } else if (_type.equals(Constants.EXCHANGE)) { - list = serverRegistry.getExchanges();; + list = serverRegistry.getExchanges(); + items = getItems(list); + _sortBySizeButton.setVisible(false); } else if (_type.equals(Constants.CONNECTION)) { list = serverRegistry.getConnections(); + items = getItems(list); + _sortBySizeButton.setVisible(false); } else { throw new Exception("Unknown mbean type " + _type); } - items = getItems(list); _list.setItems(items); } // sets the map with appropriate mbean and name private String[] getItems(java.util.List<ManagedBean> list) { + Collections.sort(list, _sorterByName); String[] items = new String[list.size()]; int i = 0; for (ManagedBean mbean : list) @@ -206,7 +268,60 @@ public class MBeanTypeTabControl items[i++] = mbean.getName(); _objectsMap.put(mbean.getName(), mbean); } - Arrays.sort(items); return items; } + + private String[] getQueueItems(java.util.List<ManagedBean> list) throws Exception + { + // Sort the list. It will keep the mbeans in sorted order in the _queueMap, which is required for + // sorting the queue according to size etc + Collections.sort(list, _sorterByName); + String[] items = new String[list.size()]; + int i = 0; + for (ManagedBean mbean : list) + { + AttributeData data = MBeanUtility.getAttributeData(mbean, Constants.ATTRIBUTE_QUEUE_DEPTH); + String value = data.getValue().toString(); + items[i] = mbean.getName() + " (" + value + " KB)"; + _objectsMap.put(mbean.getName(), mbean); + _queueMap.put(data, mbean); + i++; + } + return items; + } + + private void sortQueueByQueueDepth() throws Exception + { + // Queues are already in the alphabetically sorted order in _queueMap, now sort for queueDepth + java.util.List<AttributeData> list = new ArrayList<AttributeData>(_queueMap.keySet()); + Collections.sort(list, _sorterByQueueDepth); + + String[] items = new String[list.size()]; + int i = 0; + for (AttributeData data : list) + { + ManagedBean mbean = _queueMap.get(data); + String value = data.getValue().toString(); + items[i++] = mbean.getName() + " (" + value + " KB)"; + } + _list.setItems(items); + } + + private class ComparatorImpl implements java.util.Comparator<AttributeData> + { + public int compare(AttributeData data1, AttributeData data2) + { + Integer int1 = Integer.parseInt(data1.getValue().toString()); + Integer int2 = Integer.parseInt(data2.getValue().toString()); + return int1.compareTo(int2) * -1; + } + } + + private class Sorter implements java.util.Comparator<ManagedBean> + { + public int compare(ManagedBean mbean1, ManagedBean mbean2) + { + return mbean1.getName().compareTo(mbean2.getName()); + } + } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java index c1784d0bf1..3eb93f55d3 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java @@ -196,7 +196,7 @@ public class NotificationsTabControl extends TabControl formData = new FormData(); formData.top = new FormAttachment(notificationNameCombo, 5); formData.left = new FormAttachment(fixedLabel, 10); - formData.right = new FormAttachment(80); + formData.right = new FormAttachment(100); descriptionLabel.setLayoutData(formData); descriptionLabel.setText(" "); descriptionLabel.setFont(ApplicationRegistry.getFont(Constants.FONT_ITALIC)); |
