diff options
Diffstat (limited to 'java/management')
9 files changed, 581 insertions, 140 deletions
diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedBean.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedBean.java index ae01f30f32..8ded3f35c6 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedBean.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ManagedBean.java @@ -29,6 +29,8 @@ import static org.apache.qpid.management.ui.Constants.VIRTUAL_HOST; import java.util.HashMap; +import org.apache.qpid.management.common.mbeans.ManagedBroker; + /** * Class representing a managed bean on the managed server */ @@ -157,6 +159,11 @@ public abstract class ManagedBean extends ManagedObject return _type.endsWith(EXCHANGE); } + public boolean isVirtualHostManager() + { + return _type.endsWith(ManagedBroker.TYPE); + } + public boolean isTempQueue() { return (isQueue() && getName().startsWith("tmp_")); diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java index 23879a779c..6c0b51e584 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java @@ -46,6 +46,8 @@ public abstract class ServerRegistry private ConcurrentMap<String,List<ManagedBean>> _exchanges = new ConcurrentHashMap<String,List<ManagedBean>>(); // map of all queue mbenas private ConcurrentMap<String,List<ManagedBean>> _queues = new ConcurrentHashMap<String,List<ManagedBean>>(); + // map of all virtual host manager mbeans + private ConcurrentMap<String,ManagedBean> _vhostManagers = new ConcurrentHashMap<String,ManagedBean>(); public ServerRegistry() { @@ -98,6 +100,22 @@ public abstract class ServerRegistry _queues.get(vHost).add(mbean); } + protected void addVirtualHostManagerMBean(ManagedBean mbean) + { + String vHost = mbean.getVirtualHostName(); + _vhostManagers.put(vHost, mbean); + } + + protected void removeVirtualHostManagerMBean(ManagedBean mbean) + { + _vhostManagers.remove(mbean); + } + + public ManagedBean getVirtualHostManagerMBean(String virtualHost) + { + return _vhostManagers.get(virtualHost); + } + protected void removeConnectionMBean(ManagedBean mbean) { _connections.get(mbean.getVirtualHostName()).remove(mbean); @@ -128,6 +146,23 @@ public abstract class ServerRegistry return _queues.get(virtualHost); } + //returns the requested ManagedBean, or null if it cant be found + public ManagedBean getQueue(String queueName, String virtualHost) + { + ManagedBean requestedQueue = null; + + for(ManagedBean queue : _queues.get(virtualHost)) + { + if(queueName.equals(queue.getName())) + { + requestedQueue = queue; + break; + } + } + + return requestedQueue; + } + public void addVirtualHost(String name) { if (!_virtualHosts.contains(name)) diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java index 575b98d48a..2b459c858f 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java @@ -157,6 +157,10 @@ public class JMXServerRegistry extends ServerRegistry { addConnectionMBean(mbean); } + else if (mbean.isVirtualHostManager()) + { + addVirtualHostManagerMBean(mbean); + } addVirtualHost(mbean.getVirtualHostName()); _mbeansMap.put(mbean.getUniqueName(), mbean); @@ -183,6 +187,10 @@ public class JMXServerRegistry extends ServerRegistry { removeConnectionMBean(mbean); } + else if (mbean.isVirtualHostManager()) + { + removeVirtualHostManagerMBean(mbean); + } } public void putMBeanInfo(ManagedBean mbean, MBeanInfo mbeanInfo) diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java index a185467e2d..1fef89d6b5 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTabFolderFactory.java @@ -34,6 +34,7 @@ import java.util.Map; import javax.management.MBeanServerConnection; import org.apache.qpid.management.ui.ApplicationRegistry; +import org.apache.qpid.management.ui.ManagedServer; import org.apache.qpid.management.ui.ServerRegistry; import org.apache.qpid.management.ui.jmx.JMXManagedObject; import org.apache.qpid.management.ui.jmx.MBeanUtility; @@ -242,9 +243,9 @@ public class MBeanTabFolderFactory } /** - * Creates TabFolder and tabs for each mbeantype (eg Connection, Queue, Exchange) + * Creates TabFolder and tabs for all mbeantype (Connection, Queue, and Exchange) */ - public static TabFolder generateMBeanTypeTabFolder(final Composite parent) + public static TabFolder generateMBeanTypeTabFolder(final Composite parent, ManagedServer server, String virtualHost) { TabFolder tabFolder = new TabFolder(parent, SWT.NONE); FormData layoutData = new FormData(); @@ -254,24 +255,101 @@ public class MBeanTabFolderFactory layoutData.bottom = new FormAttachment(100); tabFolder.setLayoutData(layoutData); + TabItem tab; TabControl controller; tab = new TabItem(tabFolder, SWT.NONE); tab.setText(CONNECTION); - controller = new ConnectionTypeTabControl(tabFolder); + controller = new ConnectionTypeTabControl(tabFolder,server,virtualHost); tab.setData(TabControl.CONTROLLER, controller); tab.setControl(controller.getControl()); tab = new TabItem(tabFolder, SWT.NONE); tab.setText(EXCHANGE); - controller = new ExchangeTypeTabControl(tabFolder); + controller = new ExchangeTypeTabControl(tabFolder,server,virtualHost); tab.setData(TabControl.CONTROLLER, controller); tab.setControl(controller.getControl()); tab = new TabItem(tabFolder, SWT.NONE); tab.setText(QUEUE); - controller = new QueueTypeTabControl(tabFolder); + controller = new QueueTypeTabControl(tabFolder,server,virtualHost); + tab.setData(TabControl.CONTROLLER, controller); + tab.setControl(controller.getControl()); + + tabFolder.addListener(SWT.Selection, new Listener() + { + public void handleEvent(Event evt) + { + TabItem tab = (TabItem)evt.item; + TabControl controller = (TabControl)tab.getData(TabControl.CONTROLLER); + if(controller != null) + { + controller.refresh(null); + } + } + }); + + return tabFolder; + } + + /** + * Creates TabFolder and tab for the Connection selection view + */ + public static TabFolder generateConnectionTypeTabFolder(final Composite parent, ManagedServer server, String virtualHost) + { + TabFolder tabFolder = new TabFolder(parent, SWT.NONE); + FormData layoutData = new FormData(); + layoutData.left = new FormAttachment(0); + layoutData.top = new FormAttachment(0); + layoutData.right = new FormAttachment(100); + layoutData.bottom = new FormAttachment(100); + tabFolder.setLayoutData(layoutData); + + TabItem tab; + TabControl controller; + + tab = new TabItem(tabFolder, SWT.NONE); + tab.setText(CONNECTION); + controller = new ConnectionTypeTabControl(tabFolder,server,virtualHost); + tab.setData(TabControl.CONTROLLER, controller); + tab.setControl(controller.getControl()); + + tabFolder.addListener(SWT.Selection, new Listener() + { + public void handleEvent(Event evt) + { + TabItem tab = (TabItem)evt.item; + TabControl controller = (TabControl)tab.getData(TabControl.CONTROLLER); + if(controller != null) + { + controller.refresh(null); + } + } + }); + + return tabFolder; + } + + /** + * Creates TabFolder and tab for the Exchange selection view + */ + public static TabFolder generateExchangeTypeTabFolder(final Composite parent, ManagedServer server, String virtualHost) + { + TabFolder tabFolder = new TabFolder(parent, SWT.NONE); + FormData layoutData = new FormData(); + layoutData.left = new FormAttachment(0); + layoutData.top = new FormAttachment(0); + layoutData.right = new FormAttachment(100); + layoutData.bottom = new FormAttachment(100); + tabFolder.setLayoutData(layoutData); + + TabItem tab; + TabControl controller; + + tab = new TabItem(tabFolder, SWT.NONE); + tab.setText(EXCHANGE); + controller = new ExchangeTypeTabControl(tabFolder,server,virtualHost); tab.setData(TabControl.CONTROLLER, controller); tab.setControl(controller.getControl()); @@ -290,7 +368,45 @@ public class MBeanTabFolderFactory return tabFolder; } + + /** + * Creates TabFolder and tab for the Queue selection view + */ + public static TabFolder generateQueueTypeTabFolder(final Composite parent, ManagedServer server, String virtualHost) + { + TabFolder tabFolder = new TabFolder(parent, SWT.NONE); + FormData layoutData = new FormData(); + layoutData.left = new FormAttachment(0); + layoutData.top = new FormAttachment(0); + layoutData.right = new FormAttachment(100); + layoutData.bottom = new FormAttachment(100); + tabFolder.setLayoutData(layoutData); + TabItem tab; + TabControl controller; + + tab = new TabItem(tabFolder, SWT.NONE); + tab.setText(QUEUE); + controller = new QueueTypeTabControl(tabFolder,server,virtualHost); + tab.setData(TabControl.CONTROLLER, controller); + tab.setControl(controller.getControl()); + + tabFolder.addListener(SWT.Selection, new Listener() + { + public void handleEvent(Event evt) + { + TabItem tab = (TabItem)evt.item; + TabControl controller = (TabControl)tab.getData(TabControl.CONTROLLER); + if(controller != null) + { + controller.refresh(null); + } + } + }); + + return tabFolder; + } + private enum QpidMBeanType { QUEUE (MBEANTYPE_QUEUE), diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java index d92e8ef49d..35d1b4a34f 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanView.java @@ -173,11 +173,11 @@ public class MBeanView extends ViewPart if (NODE_TYPE_TYPEINSTANCE.equals(mbeanType)) { // An virtual host instance is selected - refreshTypeTabFolder(_typeTabFolder.getItem(0)); + generateTypeTabFolder(); } else if (NODE_TYPE_MBEANTYPE.equals(mbeanType)) { - refreshTypeTabFolder(_selectedNode.getName()); + showTypeTabFolder(_selectedNode.getName()); } else if (NOTIFICATIONS.equals(mbeanType)) { @@ -307,12 +307,7 @@ public class MBeanView extends ViewPart // Add selection listener for selection events in the Navigation view getSite().getPage().addSelectionListener(NavigationView.ID, _selectionListener); - - // Add mbeantype TabFolder. This will list all the mbeans under a mbeantype (eg Queue, Exchange). - // Using this list mbeans will be added in the navigation view - _typeTabFolder = MBeanTabFolderFactory.generateMBeanTypeTabFolder(_form.getBody()); - _typeTabFolder.setVisible(false); - + createNotificationsTabFolder(); ViewUtility.setMBeanView(this); @@ -370,32 +365,48 @@ public class MBeanView extends ViewPart _notificationTabFolder.setVisible(true); } - /** - * Refreshes the Selected mbeantype tab. The control lists all the available mbeans - * for an mbeantype(eg Queue, Exchange etc) - * @param tab - * @throws Exception - */ - private void refreshTypeTabFolder(TabItem tab) throws Exception + + + private void generateTypeTabFolder() throws Exception { - refreshTab(tab); - _typeTabFolder.setSelection(tab); - _typeTabFolder.setVisible(true); + if (_typeTabFolder != null && !_typeTabFolder.isDisposed()) + { + _typeTabFolder.dispose(); + } + + //Generates the full Queue/Connection/Exchange selection tab set + _typeTabFolder = MBeanTabFolderFactory.generateMBeanTypeTabFolder( + _form.getBody(), getServer(), getVirtualHost()); + refreshTab(_typeTabFolder.getItem(0)); } - private void refreshTypeTabFolder(String type) throws Exception + private void showTypeTabFolder(String type) throws Exception { + if (_typeTabFolder != null && !_typeTabFolder.isDisposed()) + { + _typeTabFolder.dispose(); + } + if (CONNECTION.equals(type)) { - refreshTypeTabFolder(_typeTabFolder.getItem(0)); + //Generates the Connection selection tab + _typeTabFolder = MBeanTabFolderFactory.generateConnectionTypeTabFolder( + _form.getBody(), getServer(), getVirtualHost()); + refreshTab(_typeTabFolder.getItem(0)); } else if (EXCHANGE.equals(type)) { - refreshTypeTabFolder(_typeTabFolder.getItem(1)); + //Generates the Exchange selection tab + _typeTabFolder = MBeanTabFolderFactory.generateExchangeTypeTabFolder( + _form.getBody(), getServer(), getVirtualHost()); + refreshTab(_typeTabFolder.getItem(0)); } else if (QUEUE.equals(type)) { - refreshTypeTabFolder(_typeTabFolder.getItem(2)); + //Generates the Queue selection tab + _typeTabFolder = MBeanTabFolderFactory.generateQueueTypeTabFolder( + _form.getBody(), getServer(), getVirtualHost()); + refreshTab(_typeTabFolder.getItem(0)); } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ConnectionTypeTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ConnectionTypeTabControl.java index e0d850bd1e..f1f7b07b6f 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ConnectionTypeTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ConnectionTypeTabControl.java @@ -24,10 +24,8 @@ import java.util.List; import static org.apache.qpid.management.ui.Constants.CONNECTION; -import org.apache.qpid.management.ui.ApplicationRegistry; import org.apache.qpid.management.ui.ManagedBean; -import org.apache.qpid.management.ui.ServerRegistry; -import org.apache.qpid.management.ui.views.MBeanView; +import org.apache.qpid.management.ui.ManagedServer; import org.eclipse.swt.widgets.TabFolder; /** @@ -38,16 +36,15 @@ import org.eclipse.swt.widgets.TabFolder; public class ConnectionTypeTabControl extends MBeanTypeTabControl { - public ConnectionTypeTabControl(TabFolder tabFolder) + public ConnectionTypeTabControl(TabFolder tabFolder, ManagedServer server, String virtualHost) { - super(tabFolder,CONNECTION); + super(tabFolder, server, virtualHost, CONNECTION); } - @Override - protected List<ManagedBean> getMbeans() - { - ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(MBeanView.getServer()); - return serverRegistry.getConnections(MBeanView.getVirtualHost()); - } + @Override + protected List<ManagedBean> getMbeans() + { + return _serverRegistry.getConnections(_virtualHost); + } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ExchangeTypeTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ExchangeTypeTabControl.java index 710422ab6e..5d587c7158 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ExchangeTypeTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/ExchangeTypeTabControl.java @@ -24,25 +24,22 @@ import java.util.List; import static org.apache.qpid.management.ui.Constants.EXCHANGE; -import org.apache.qpid.management.ui.ApplicationRegistry; import org.apache.qpid.management.ui.ManagedBean; -import org.apache.qpid.management.ui.ServerRegistry; -import org.apache.qpid.management.ui.views.MBeanView; +import org.apache.qpid.management.ui.ManagedServer; import org.eclipse.swt.widgets.TabFolder; public class ExchangeTypeTabControl extends MBeanTypeTabControl { - public ExchangeTypeTabControl(TabFolder tabFolder) + public ExchangeTypeTabControl(TabFolder tabFolder, ManagedServer server, String virtualHost) { - super(tabFolder,EXCHANGE); + super(tabFolder, server, virtualHost, EXCHANGE); } @Override protected List<ManagedBean> getMbeans() { - ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(MBeanView.getServer()); - return serverRegistry.getExchanges(MBeanView.getVirtualHost()); + return _serverRegistry.getExchanges(_virtualHost); } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/MBeanTypeTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/MBeanTypeTabControl.java index a16fbf8c98..4863323aac 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/MBeanTypeTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/MBeanTypeTabControl.java @@ -23,7 +23,12 @@ package org.apache.qpid.management.ui.views.type; import java.util.List; +import org.apache.qpid.management.ui.ApiVersion; +import org.apache.qpid.management.ui.ApplicationRegistry; import org.apache.qpid.management.ui.ManagedBean; +import org.apache.qpid.management.ui.ManagedServer; +import org.apache.qpid.management.ui.jmx.JMXManagedObject; +import org.apache.qpid.management.ui.jmx.JMXServerRegistry; import org.apache.qpid.management.ui.jmx.MBeanUtility; import org.apache.qpid.management.ui.views.MBeanView; import org.apache.qpid.management.ui.views.NavigationView; @@ -64,13 +69,20 @@ public abstract class MBeanTypeTabControl extends TabControl protected Table _table = null; protected TableViewer _tableViewer = null; - private List<ManagedBean> _mbeans = null; + protected List<ManagedBean> _mbeans = null; private String _type; + protected ApiVersion _ApiVersion; + protected JMXManagedObject _vhostMbean; + protected String _virtualHost; + protected JMXServerRegistry _serverRegistry; - - public MBeanTypeTabControl(TabFolder tabFolder, String type) + public MBeanTypeTabControl(TabFolder tabFolder, ManagedServer server, String virtualHost, String type) { super(tabFolder); + _virtualHost = virtualHost; + _serverRegistry = (JMXServerRegistry) ApplicationRegistry.getServerRegistry(server); + _ApiVersion = _serverRegistry.getManagementApiVersion(); + _vhostMbean = (JMXManagedObject) _serverRegistry.getVirtualHostManagerMBean(_virtualHost); _type = type; _toolkit = new FormToolkit(_tabFolder.getDisplay()); _form = _toolkit.createForm(_tabFolder); @@ -194,24 +206,7 @@ public abstract class MBeanTypeTabControl extends TabControl { public void widgetSelected(SelectionEvent e) { - int selectionIndex = _table.getSelectionIndex(); - - if (selectionIndex != -1) - { - final ManagedBean selectedMBean = (ManagedBean)_table.getItem(selectionIndex).getData(); - - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - NavigationView view = (NavigationView)window.getActivePage().findView(NavigationView.ID); - try - { - view.addManagedBean(selectedMBean); - } - catch (Exception ex) - { - MBeanUtility.handleException(selectedMBean, ex); - } - - } + addMBeanToFavourites(); } }); @@ -222,23 +217,7 @@ public abstract class MBeanTypeTabControl extends TabControl { public void widgetSelected(SelectionEvent e) { - int selectionIndex = _table.getSelectionIndex(); - - if (selectionIndex != -1) - { - final ManagedBean selectedMBean = (ManagedBean)_table.getItem(selectionIndex).getData(); - - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - MBeanView view = (MBeanView) window.getActivePage().findView(MBeanView.ID); - try - { - view.openMBean(selectedMBean); - } - catch (Exception ex) - { - MBeanUtility.handleException(selectedMBean, ex); - } - } + openMBean(); } }); @@ -275,23 +254,7 @@ public abstract class MBeanTypeTabControl extends TabControl // MouseListener implementation public void mouseDoubleClick(MouseEvent event) { - int selectionIndex = _table.getSelectionIndex(); - - if (selectionIndex != -1) - { - final ManagedBean selectedMBean = (ManagedBean)_table.getItem(selectionIndex).getData(); - - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - MBeanView view = (MBeanView) window.getActivePage().findView(MBeanView.ID); - try - { - view.openMBean(selectedMBean); - } - catch (Exception ex) - { - MBeanUtility.handleException(selectedMBean, ex); - } - } + openMBean(); } public void mouseDown(MouseEvent e){} @@ -403,4 +366,48 @@ public abstract class MBeanTypeTabControl extends TabControl return comparison; } } + + protected void addMBeanToFavourites() + { + int selectionIndex = _table.getSelectionIndex(); + + if (selectionIndex != -1) + { + final ManagedBean selectedMBean = (ManagedBean)_table.getItem(selectionIndex).getData(); + + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + NavigationView view = (NavigationView)window.getActivePage().findView(NavigationView.ID); + try + { + view.addManagedBean(selectedMBean); + } + catch (Exception ex) + { + MBeanUtility.handleException(selectedMBean, ex); + } + } + } + + protected void openMBean() + { + int selectionIndex = _table.getSelectionIndex(); + + if (selectionIndex == -1) + { + return; + } + + final ManagedBean selectedMBean = (ManagedBean)_table.getItem(selectionIndex).getData(); + + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + MBeanView view = (MBeanView) window.getActivePage().findView(MBeanView.ID); + try + { + view.openMBean(selectedMBean); + } + catch (Exception ex) + { + MBeanUtility.handleException(selectedMBean, ex); + } + } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java index 0e48c80a79..69edde9464 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java @@ -23,16 +23,24 @@ package org.apache.qpid.management.ui.views.type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; + +import javax.management.MBeanServerConnection; +import javax.management.MBeanServerInvocationHandler; import static org.apache.qpid.management.ui.Constants.QUEUE; +import static org.apache.qpid.management.ui.Constants.ATTRIBUTE_QUEUE_DEPTH; +import org.apache.qpid.management.common.mbeans.ManagedBroker; 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.ManagedServer; 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.apache.qpid.management.ui.views.MBeanView; +import org.apache.qpid.management.ui.views.NavigationView; +import org.apache.qpid.management.ui.views.ViewUtility; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; @@ -49,22 +57,60 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; public class QueueTypeTabControl extends MBeanTypeTabControl { - private HashMap<ManagedBean, Long> _queueDepths = new HashMap<ManagedBean, Long>(); - private HashMap<ManagedBean, Long> _activeConsumerCounts = new HashMap<ManagedBean, Long>(); - + private MBeanServerConnection _mbsc; + private ManagedBroker _vhmb; + //Map for storing queue depths for servers using Qpid JMX API 1.2 and below + private Map<ManagedBean,Long> _queueDepths = new HashMap<ManagedBean, Long>(); - public QueueTypeTabControl(TabFolder tabFolder) + public QueueTypeTabControl(TabFolder tabFolder, ManagedServer server, String virtualHost) { - super(tabFolder,QUEUE); + super(tabFolder,server,virtualHost,QUEUE); + _mbsc = (MBeanServerConnection) _serverRegistry.getServerConnection(); + _vhmb = (ManagedBroker) MBeanServerInvocationHandler.newProxyInstance(_mbsc, + _vhostMbean.getObjectName(), ManagedBroker.class, false); + } + + @Override + public void refresh(ManagedBean mbean) + { + if(_ApiVersion.greaterThanOrEqualTo(1, 3)) + { + //Qpid JMX API 1.3+, use this virtualhosts VirtualHostManager MBean + //to retrieve the Queue Name and Queue Depth + + Map<String,Long> queueNamesDepths = null; + try + { + queueNamesDepths = _vhmb.viewQueueNamesDepths(); + } + catch(Exception e) + { + MBeanUtility.handleException(_vhostMbean, e); + } + + _tableViewer.setInput(queueNamesDepths); + } + else + { + //Qpid JMX API 1.2 or below, use the ManagedBeans and look + //up the attribute value for each + _mbeans = getMbeans(); + _tableViewer.setInput(_mbeans); + } + + layout(); } @Override protected List<ManagedBean> getMbeans() { ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(MBeanView.getServer()); + try { return extractQueueDetails(serverRegistry.getQueues(MBeanView.getVirtualHost())); @@ -80,22 +126,19 @@ public class QueueTypeTabControl extends MBeanTypeTabControl private List<ManagedBean> extractQueueDetails(List<ManagedBean> list) throws Exception { _queueDepths.clear(); - _activeConsumerCounts.clear(); - + List<ManagedBean> items = new ArrayList<ManagedBean>(); for (ManagedBean mbean : list) { - AttributeData data = MBeanUtility.getAttributeData(mbean, Constants.ATTRIBUTE_QUEUE_DEPTH); + AttributeData data = MBeanUtility.getAttributeData(mbean, ATTRIBUTE_QUEUE_DEPTH); _queueDepths.put(mbean, Long.valueOf(data.getValue().toString())); - data = MBeanUtility.getAttributeData(mbean, Constants.ATTRIBUTE_QUEUE_CONSUMERCOUNT); - _activeConsumerCounts.put(mbean, Long.valueOf(data.getValue().toString())); - + items.add(mbean); } return items; } - + @Override protected void createTable(Composite tableComposite) { @@ -106,10 +149,24 @@ public class QueueTypeTabControl extends MBeanTypeTabControl _table.setLayoutData(data); _tableViewer = new TableViewer(_table); - final TableSorter tableSorter = new TableSorter(); + + String[] titles = new String[]{"Queue Name", "Queue Depth"}; + int[] bounds = new int[]{325, 200}; + + final TableSorter tableSorter; - String[] titles = { "Name", "QueueDepth", "Active Consumer Count"}; - int[] bounds = { 250, 175, 175}; + if(_ApiVersion.greaterThanOrEqualTo(1, 3)) + { + //QpidJMX API 1.3+ using the new getQueueNamesDepths method in VHostManager MBean. + //requires sorting Map.Entry elements + tableSorter = new NewerTableSorter(); + } + else + { + //QpidJMX API 1.2 or below. Requires sorting ManagedBeans and using the _queueDepths map + tableSorter = new OlderTableSorter(); + } + for (int i = 0; i < titles.length; i++) { final int index = i; @@ -145,17 +202,27 @@ public class QueueTypeTabControl extends MBeanTypeTabControl } - _tableViewer.setContentProvider(new ContentProviderImpl()); - _tableViewer.setLabelProvider(new LabelProviderImpl()); + if(_ApiVersion.greaterThanOrEqualTo(1, 3)) + { + _tableViewer.setContentProvider(new NewerContentProviderImpl()); + _tableViewer.setLabelProvider(new NewerLabelProviderImpl()); + } + else + { + _tableViewer.setContentProvider(new OlderContentProviderImpl()); + _tableViewer.setLabelProvider(new OlderLabelProviderImpl()); + } + + _tableViewer.setUseHashlookup(true); _tableViewer.setSorter(tableSorter); _table.setSortColumn(_table.getColumn(0)); _table.setSortDirection(SWT.UP); } /** - * Content Provider class for the table viewer + * Content Provider class for the table viewer for Qpid JMX API 1.2 and below. */ - private class ContentProviderImpl implements IStructuredContentProvider + private class OlderContentProviderImpl implements IStructuredContentProvider { public void inputChanged(Viewer v, Object oldInput, Object newInput) @@ -176,9 +243,9 @@ public class QueueTypeTabControl extends MBeanTypeTabControl } /** - * Label Provider class for the table viewer + * Label Provider class for the table viewer for Qpid JMX API 1.2 and below. */ - private class LabelProviderImpl extends LabelProvider implements ITableLabelProvider + private class OlderLabelProviderImpl extends LabelProvider implements ITableLabelProvider { @Override public String getColumnText(Object element, int columnIndex) @@ -190,9 +257,7 @@ public class QueueTypeTabControl extends MBeanTypeTabControl case 0 : // name column return mbean.getName(); case 1 : // queue depth column - return getQueueDepthString(mbean, _queueDepths.get(mbean)); - case 2 : // consumer count column - return String.valueOf(_activeConsumerCounts.get(mbean)); + return getQueueDepthString(_queueDepths.get(mbean)); default: return "-"; } @@ -205,12 +270,18 @@ public class QueueTypeTabControl extends MBeanTypeTabControl } } - private String getQueueDepthString(ManagedBean mbean, Long value) + private String getQueueDepthString(Long value) { - if (mbean.getVersion() == 1) //mbean is v1 and returns KB - { - Double mb = 1024.0; - + if(value == null) + { + return "-"; + } + + if (_ApiVersion.lessThanOrEqualTo(1,1)) + { + //Qpid JMX API 1.1 or below, returns KB + double mb = 1024.0; + if(value > mb) //MB { return String.format("%.3f", (Double)(value / mb)) + " MB"; @@ -220,11 +291,12 @@ public class QueueTypeTabControl extends MBeanTypeTabControl return value + " KB"; } } - else //mbean is v2+ and returns Bytes + else { + //Qpid JMX API 1.2 or above, returns Bytes double mb = 1024.0 * 1024.0; double kb = 1024.0; - + if(value >= mb) //MB { return String.format("%.3f", (Double)(value / mb)) + " MB"; @@ -239,18 +311,19 @@ public class QueueTypeTabControl extends MBeanTypeTabControl } } } + /** - * Sorter class for the table viewer. + * Abstract sorter class for the table viewer. * */ - private class TableSorter extends ViewerSorter + private abstract class TableSorter extends ViewerSorter { - private int column; - private static final int ASCENDING = 0; - private static final int DESCENDING = 1; + protected int column; + protected static final int ASCENDING = 0; + protected static final int DESCENDING = 1; - private int direction; + protected int direction; public TableSorter() { @@ -274,6 +347,21 @@ public class QueueTypeTabControl extends MBeanTypeTabControl } @Override + public abstract int compare(Viewer viewer, Object e1, Object e2); + } + + /** + * sorter class for the table viewer for Qpid JMX API 1.2 and below. + * + */ + private class OlderTableSorter extends TableSorter + { + public OlderTableSorter() + { + super(); + } + + @Override public int compare(Viewer viewer, Object e1, Object e2) { ManagedBean mbean1 = (ManagedBean) e1; @@ -287,9 +375,44 @@ public class QueueTypeTabControl extends MBeanTypeTabControl break; case 1: //queue depth comparison = _queueDepths.get(mbean1).compareTo(_queueDepths.get(mbean2)); + default: + comparison = 0; + } + // If descending order, flip the direction + if(direction == DESCENDING) + { + comparison = -comparison; + } + return comparison; + } + } + + /** + * sorter class for the table viewer for Qpid JMX API 1.3 and above. + * + */ + private class NewerTableSorter extends TableSorter + { + public NewerTableSorter() + { + super(); + } + + @SuppressWarnings("unchecked") + @Override + public int compare(Viewer viewer, Object e1, Object e2) + { + Map.Entry<String, Long> queue1 = (Map.Entry<String, Long>) e1; + Map.Entry<String, Long> queue2 = (Map.Entry<String, Long>) e2; + + int comparison = 0; + switch(column) + { + case 0://name + comparison = (queue1.getKey()).compareTo(queue2.getKey()); break; - case 2: //active consumer count - comparison = _activeConsumerCounts.get(mbean1).compareTo(_activeConsumerCounts.get(mbean2)); + case 1://queue depth + comparison = (queue1.getValue()).compareTo(queue2.getValue());; break; default: comparison = 0; @@ -303,4 +426,144 @@ public class QueueTypeTabControl extends MBeanTypeTabControl } } + /** + * Content Provider class for the table viewer for Qpid JMX API 1.3 and above. + */ + private class NewerContentProviderImpl implements IStructuredContentProvider + { + + public void inputChanged(Viewer v, Object oldInput, Object newInput) + { + + } + + public void dispose() + { + + } + + @SuppressWarnings("unchecked") + public Object[] getElements(Object parent) + { + Map<String, Long> map = (Map<String, Long>) parent; + return map.entrySet().toArray(new Map.Entry[0]); + } + } + + /** + * Label Provider class for the table viewer for for Qpid JMX API 1.3 and above. + */ + private class NewerLabelProviderImpl extends LabelProvider implements ITableLabelProvider + { + @SuppressWarnings("unchecked") + @Override + public String getColumnText(Object element, int columnIndex) + { + Map.Entry<String, Long> queue = (Map.Entry<String, Long>) element; + + switch (columnIndex) + { + case 0 : // name column + return queue.getKey(); + case 1 : // depth column + return getQueueDepthString(queue.getValue()); + default : + return "-"; + } + } + + @Override + public Image getColumnImage(Object element, int columnIndex) + { + return null; + } + } + + @Override + protected void addMBeanToFavourites() + { + int selectionIndex = _table.getSelectionIndex(); + + if (selectionIndex == -1) + { + return; + } + + ManagedBean selectedMBean; + + if(_ApiVersion.greaterThanOrEqualTo(1, 3)) + { + //if we have Qpid JMX API 1.3+ the entries are created from Map.Entry<String,Long> + Map.Entry<String, Long> queueEntry = (Map.Entry<String, Long>) _table.getItem(selectionIndex).getData(); + + String queueName = queueEntry.getKey(); + selectedMBean = _serverRegistry.getQueue(queueName, _virtualHost); + } + else + { + //if we have a Qpid JMX API 1.2 or less server, entries are created from ManagedBeans directly + selectedMBean = (ManagedBean)_table.getItem(selectionIndex).getData(); + } + + if(selectedMBean == null) + { + ViewUtility.popupErrorMessage("Error", "Unable to retrieve the selected MBean to add it to favourites"); + return; + } + + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + NavigationView view = (NavigationView)window.getActivePage().findView(NavigationView.ID); + try + { + view.addManagedBean(selectedMBean); + } + catch (Exception ex) + { + MBeanUtility.handleException(selectedMBean, ex); + } + } + + @Override + protected void openMBean() + { + int selectionIndex = _table.getSelectionIndex(); + + if (selectionIndex == -1) + { + return; + } + + ManagedBean selectedMBean; + + if(_ApiVersion.greaterThanOrEqualTo(1, 3)) + { + //if we have Qpid JMX API 1.3+ the entries are created from Map.Entry<String,Long> + Map.Entry<String, Long> queueEntry = (Map.Entry<String, Long>) _table.getItem(selectionIndex).getData(); + + String queueName = queueEntry.getKey(); + selectedMBean = _serverRegistry.getQueue(queueName, _virtualHost); + } + else + { + //if we have a Qpid JMX API 1.2 or less server, entries are created from ManagedBeans directly + selectedMBean = (ManagedBean)_table.getItem(selectionIndex).getData(); + } + + if(selectedMBean == null) + { + ViewUtility.popupErrorMessage("Error", "Unable to retrieve the selected MBean to open it"); + return; + } + + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + MBeanView view = (MBeanView) window.getActivePage().findView(MBeanView.ID); + try + { + view.openMBean(selectedMBean); + } + catch (Exception ex) + { + MBeanUtility.handleException(selectedMBean, ex); + } + } } |
