You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2007/01/07 18:03:19 UTC
svn commit: r493771 [2/2] - in
/incubator/qpid/branches/new_persistence/java: ./ broker/etc/
broker/src/main/java/org/apache/qpid/server/protocol/ client/example/bin/
common/src/main/java/org/apache/qpid/framing/
distribution/src/main/assembly/ distrib...
Modified: incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java?view=diff&rev=493771&r1=493770&r2=493771
==============================================================================
--- incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java (original)
+++ incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java Sun Jan 7 09:03:17 2007
@@ -28,13 +28,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
-import java.util.Set;
-
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectInstance;
-import javax.management.ObjectName;
import org.apache.qpid.management.ui.ApplicationRegistry;
import org.apache.qpid.management.ui.Constants;
@@ -42,8 +36,9 @@
import org.apache.qpid.management.ui.ManagedServer;
import org.apache.qpid.management.ui.ServerRegistry;
import org.apache.qpid.management.ui.exceptions.InfoRequiredException;
-import org.apache.qpid.management.ui.jmx.JMXManagedObject;
+import org.apache.qpid.management.ui.exceptions.ManagementConsoleException;
import org.apache.qpid.management.ui.jmx.JMXServerRegistry;
+import org.apache.qpid.management.ui.jmx.MBeanUtility;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IFontProvider;
@@ -64,7 +59,11 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.part.ViewPart;
-
+/**
+ * Navigation View for navigating the managed servers and managed beans on
+ * those servers
+ * @author Bhupendra Bhardwaj
+ */
public class NavigationView extends ViewPart
{
public static final String ID = "org.apache.qpid.management.ui.navigationView";
@@ -73,8 +72,6 @@
private TreeViewer _treeViewer = null;
private TreeObject _rootNode = null;
private TreeObject _serversRootNode = null;
- // List of all server nodes (connecged or removed)
- //private List<TreeObject> _serverNodeList = new ArrayList<TreeObject>();
// Map of connected servers
private HashMap<ManagedServer, TreeObject> _managedServerMap = new HashMap<ManagedServer, TreeObject>();
@@ -98,6 +95,9 @@
createListeners();
}
+ /**
+ * Creates listeners for the JFace treeviewer
+ */
private void createListeners()
{
_treeViewer.addDoubleClickListener(new IDoubleClickListener()
@@ -132,12 +132,17 @@
});
}
+ /**
+ * Creates Qpid Server connection using JMX RMI protocol
+ * @param server
+ * @throws Exception
+ */
private void createRMIServerConnection(ManagedServer server) throws Exception
{
try
{
// Currently Qpid Management Console only supports JMX MBeanServer
- JMXServerRegistry serverRegistry = new JMXServerRegistry(server);
+ ServerRegistry serverRegistry = new JMXServerRegistry(server);
ApplicationRegistry.addServer(server, serverRegistry);
}
catch(Exception ex)
@@ -151,14 +156,24 @@
return "service:jmx:rmi:///jndi/rmi://" + host + "/jmxrmi";
}
-
+ /**
+ * Adds a new server node in the navigation view if server connection is successful.
+ * @param transportProtocol
+ * @param host
+ * @param port
+ * @param domain
+ * @throws Exception
+ */
public void addNewServer(String transportProtocol, String host, String port, String domain)
throws Exception
{
+ String serverAddress = host + ":" + port;
+ String url = null;
+ ManagedServer managedServer = null;
+
if ("RMI".equals(transportProtocol))
- {
- String serverAddress = host + ":" + port;
- String url = getRMIURL(serverAddress);
+ {
+ url = getRMIURL(serverAddress);
List<TreeObject> list = _serversRootNode.getChildren();
for (TreeObject node : list)
{
@@ -166,30 +181,36 @@
throw new InfoRequiredException("Server " + serverAddress + " is already added");
}
- ManagedServer managedServer = new ManagedServer(url, domain);
+ managedServer = new ManagedServer(url, domain);
managedServer.setName(serverAddress);
- createRMIServerConnection(managedServer);
-
- // RMI server connection is successful. Now add the server in the tree
- TreeObject serverNode = new TreeObject(serverAddress, Constants.SERVER);
- serverNode.setUrl(url);
- serverNode.setManagedObject(managedServer);
- _serversRootNode.addChild(serverNode);
-
- // Add server in the connected server map
- _managedServerMap.put(managedServer, serverNode);
- populateServer(serverNode);
- _treeViewer.refresh();
-
- // save server address in file
- addServerAddressInFile(serverAddress);
+ createRMIServerConnection(managedServer);
}
else
{
throw new InfoRequiredException(transportProtocol + " transport is not supported");
}
+
+ // Server connection is successful. Now add the server in the tree
+ TreeObject serverNode = new TreeObject(serverAddress, Constants.SERVER);
+ serverNode.setUrl(url);
+ serverNode.setManagedObject(managedServer);
+ _serversRootNode.addChild(serverNode);
+
+ // Add server in the connected server map
+ _managedServerMap.put(managedServer, serverNode);
+ populateServer(serverNode);
+ _treeViewer.refresh();
+
+ // save server address in file
+ addServerAddressInFile(serverAddress);
}
+ /**
+ * Server addresses are stored in a file. When user launches the application again, the
+ * server addresses are picked up from the file and shown in the navigfation view. This method
+ * adds the server address in a file, when a new server is added in the navigation view.
+ * @param serverAddress
+ */
private void addServerAddressInFile(String serverAddress)
{
File file = new File(INI_FILENAME);
@@ -210,11 +231,14 @@
}
}
-
+ /**
+ * Queries the qpid server for MBeans and populates the navigation view with all MBeans for
+ * the given server node.
+ * @param serverNode
+ */
private void populateServer(TreeObject serverNode)
{
ManagedServer server = (ManagedServer)serverNode.getManagedObject();
- JMXServerRegistry serverRegistry = (JMXServerRegistry)ApplicationRegistry.getServerRegistry(server);
String domain = server.getDomain();
try
{
@@ -228,11 +252,10 @@
else
{
List<TreeObject> domainList = new ArrayList<TreeObject>();
- MBeanServerConnection mbsc = serverRegistry.getServerConnection();
- String[] domains = mbsc.getDomains();
- for (int i = 0; i < domains.length; i++)
+ List<String> domains = MBeanUtility.getAllDomains(server);;
+ for (String domainName : domains)
{
- TreeObject domainNode = new TreeObject(domains[i], Constants.DOMAIN);
+ TreeObject domainNode = new TreeObject(domainName, Constants.DOMAIN);
domainNode.setParent(serverNode);
domainList.add(domainNode);
@@ -247,80 +270,118 @@
}
}
+ /**
+ * Queries the Qpid Server and populates the given domain node with all MBeans undser that domain.
+ * @param domain
+ * @throws IOException
+ * @throws Exception
+ */
@SuppressWarnings("unchecked")
private void populateDomain(TreeObject domain) throws IOException, Exception
{
ManagedServer server = (ManagedServer)domain.getParent().getManagedObject();
- JMXServerRegistry serverRegistry = (JMXServerRegistry)ApplicationRegistry.getServerRegistry(server);
- String domainName = domain.getName();
- MBeanServerConnection mbsc = serverRegistry.getServerConnection();
-
-
- ObjectName objName = new ObjectName(domainName + ":*");
- Set queryMBeans = mbsc.queryMBeans(objName, null);
- final Set<ObjectInstance> objectInstances = queryMBeans;
-
- for (Iterator<ObjectInstance> itr = objectInstances.iterator(); itr.hasNext();)
- {
- ObjectInstance instance = itr.next();
- ManagedBean obj = new JMXManagedObject(instance.getObjectName());
- obj.setServer(server);
- addManagedBean(domain, obj);
+ // Add these three types - Connection, Exchange, Queue
+ // By adding these, these will always be available, even if there are no mbeans under thse types
+ // This is required because, the mbeans will be added from mbeanview, by selecting from the list
+ TreeObject typeChild = new TreeObject(Constants.CONNECTION, Constants.TYPE);
+ typeChild.setParent(domain);
+ typeChild = new TreeObject(Constants.EXCHANGE, Constants.TYPE);
+ typeChild.setParent(domain);
+ typeChild = new TreeObject(Constants.QUEUE, Constants.TYPE);
+ typeChild.setParent(domain);
+
+
+ // Now populate the mbenas under those types
+ List<ManagedBean> mbeans = MBeanUtility.getManagedObjectsForDomain(server, domain.getName());
+ for (ManagedBean mbean : mbeans)
+ {
+ mbean.setServer(server);
+ ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(server);
+ serverRegistry.addManagedObject(mbean);
+
+ // Add all mbeans other than Connections, Exchanges and Queues. Because these will be added
+ // manually by selecting from MBeanView
+ if (!(mbean.getType().equals(Constants.CONNECTION) || mbean.getType().equals(Constants.EXCHANGE) || mbean.getType().equals(Constants.QUEUE)))
+ {
+ addManagedBean(domain, mbean);
+ }
}
}
- private TreeObject getIfTypeAlreadyExists(TreeObject domain, String type)
+ /**
+ * Checks if a particular mbeantype is already there in the navigation view for a domain.
+ * This is used while populating domain with mbeans.
+ * @param domain
+ * @param typeName
+ * @return Node if given mbeantype already exists, otherwise null
+ */
+ private TreeObject getMBeanTypeNode(TreeObject domain, String typeName)
{
- List<TreeObject> types = domain.getChildren();
+ List<TreeObject> childNodes = domain.getChildren();
- for (TreeObject child : types)
+ for (TreeObject child : childNodes)
{
- if (Constants.TYPE.equals(child.getType()) && type.equals(child.getName()))
+ if (Constants.TYPE.equals(child.getType()) && typeName.equals(child.getName()))
return child;
}
return null;
}
- private void addManagedBean(TreeObject domain, ManagedBean obj)
+ private boolean doesMBeanNodeAlreadyExist(TreeObject typeNode, String mbeanName)
{
- ManagedServer server = (ManagedServer)domain.getParent().getManagedObject();
- JMXServerRegistry serverRegistry = (JMXServerRegistry)ApplicationRegistry.getServerRegistry(server);
- serverRegistry.addManagedObject(obj);
-
- String type = obj.getType();
- String name = obj.getName();
+ List<TreeObject> childNodes = typeNode.getChildren();
+ for (TreeObject child : childNodes)
+ {
+ if (Constants.MBEAN.equals(child.getType()) && mbeanName.equals(child.getName()))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Adds the given MBean to the given domain node. Creates Notification node for the MBean.
+ * @param domain
+ * @param mbean mbean
+ */
+ private void addManagedBean(TreeObject domain, ManagedBean mbean) throws Exception
+ {
+ String type = mbean.getType();
+ String name = mbean.getName();
+
+ TreeObject typeNode = getMBeanTypeNode(domain, type);
+ if (typeNode != null && doesMBeanNodeAlreadyExist(typeNode, name))
+ return;
- TreeObject typeChild = getIfTypeAlreadyExists(domain, type);
TreeObject mbeanNode = null;
- if (typeChild != null) // if type is already added as a TreeItem
+ if (typeNode != null) // type node already exists
{
if (name == null)
{
- System.out.println("Two mbeans can't exist without a name and with same type");
- return;
+ throw new ManagementConsoleException("Two mbeans can't exist without a name and with same type");
}
- mbeanNode = new TreeObject(obj);
- mbeanNode.setParent(typeChild);
+ mbeanNode = new TreeObject(mbean);
+ mbeanNode.setParent(typeNode);
}
else
{
- if (name != null) // An managedObject with type and name
+ // type node does not exist. Now check if node to be created as mbeantype or MBean
+ if (name != null) // A managedObject with type and name
{
- typeChild = new TreeObject(type, Constants.TYPE);
- typeChild.setParent(domain);
- mbeanNode = new TreeObject(obj);
- mbeanNode.setParent(typeChild);
+ typeNode = new TreeObject(type, Constants.TYPE);
+ typeNode.setParent(domain);
+ mbeanNode = new TreeObject(mbean);
+ mbeanNode.setParent(typeNode);
}
- else // An managedObject with only type
+ else // A managedObject with only type
{
- mbeanNode = new TreeObject(obj);
+ mbeanNode = new TreeObject(mbean);
mbeanNode.setParent(domain);
}
}
// Add notification node
- // TODO: show this only of the mbean sends any notification
+ // TODO: show this only if the mbean sends any notification
TreeObject notificationNode = new TreeObject(Constants.NOTIFICATION, Constants.NOTIFICATION);
notificationNode.setParent(mbeanNode);
}
@@ -373,6 +434,9 @@
}
+ /**
+ * Closes the Qpid server connection
+ */
public void disconnect() throws Exception
{
TreeObject selectedNode = getSelectedServerNode();
@@ -408,6 +472,11 @@
_treeViewer.refresh();
}
+ /**
+ * Closes the Qpid server connection if not already closed and removes the server node from the navigation view and
+ * also from the ini file stored in the system.
+ * @throws Exception
+ */
public void removeServer() throws Exception
{
disconnect();
@@ -430,7 +499,6 @@
list.remove(objectToRemove);
}
- //_serverNodeList.remove(objectToRemove);
_treeViewer.refresh();
// Remove from the ini file
@@ -445,6 +513,10 @@
out.close();
}
+ /**
+ * @return the server addresses from the ini file
+ * @throws Exception
+ */
private List<String> getServerListFromFile() throws Exception
{
BufferedReader in = new BufferedReader(new FileReader(INI_FILENAME));
@@ -538,6 +610,9 @@
_treeViewer.refresh();
}
+ /**
+ * Content provider class for the tree viewer
+ */
private class ContentProviderImpl implements ITreeContentProvider
{
public Object[] getElements(Object parent)
@@ -574,6 +649,9 @@
}
}
+ /**
+ * Label provider class for the tree viewer
+ */
private class LabelProviderImpl extends LabelProvider implements IFontProvider
{
public Image getImage(Object element)
@@ -615,24 +693,6 @@
}
return ApplicationRegistry.getFont(Constants.FONT_NORMAL);
}
-
- /*
- public Color getForeground(Object element)
- {
- TreeObject node = (TreeObject)element;
- if (node.getType().equals(Constants.SERVER))
- {
- if (!node.getChildren().isEmpty())
- return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN);
- else
- return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY);
- }
- return Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
- }
- public Color getBackground(Object element)
- {
- return _treeViewer.getControl().getBackground();
- }*/
} // End of LabelProviderImpl
@@ -641,12 +701,12 @@
public int category(Object element)
{
TreeObject node = (TreeObject)element;
- if (node.getType().equals(Constants.MBEAN))
+ if (node.getType().equals(Constants.MBEAN))
return 1;
return 2;
}
}
-
+
/**
* Worker thread, which keeps looking for new ManagedObjects to be added and
* unregistered objects to be removed from the tree.
@@ -668,60 +728,36 @@
catch(Exception ex)
{
- }
- refreshAddedObjects();
+ }
refreshRemovedObjects();
refreshClosedServerConnections();
}// end of while loop
}// end of run method.
}// end of Worker class
-
- private void refreshAddedObjects()
+ public void addManagedBean(ManagedBean mbean) throws Exception
{
- for (ManagedServer server : _managedServerMap.keySet())
+ TreeObject treeServerObject = _managedServerMap.get(mbean.getServer());
+ List<TreeObject> domains = treeServerObject.getChildren();
+ TreeObject domain = null;
+ for (TreeObject child : domains)
{
- JMXServerRegistry serverRegistry = (JMXServerRegistry)ApplicationRegistry.getServerRegistry(server);
- if (serverRegistry == null) // server connection is closed
- continue;
-
- final List<ManagedBean> list = serverRegistry.getObjectsToBeAdded();
- if (list != null)
+ if (child.getName().equals(mbean.getDomain()))
{
- Display display = getSite().getShell().getDisplay();
- display.syncExec(new Runnable()
- {
- public void run()
- {
- for (ManagedBean obj : list)
- {
- System.out.println("adding " + obj.getName() + " " + obj.getType());
- TreeObject treeServerObject = _managedServerMap.get(obj.getServer());
- List<TreeObject> domains = treeServerObject.getChildren();
- TreeObject domain = null;
- for (TreeObject child : domains)
- {
- if (child.getName().equals(obj.getDomain()))
- {
- domain = child;
- break;
- }
- }
-
- addManagedBean(domain, obj);
- }
- _treeViewer.refresh();
- }
- });
+ domain = child;
+ break;
}
}
+
+ addManagedBean(domain, mbean);
+ _treeViewer.refresh();
}
private void refreshRemovedObjects()
{
for (ManagedServer server : _managedServerMap.keySet())
{
- final JMXServerRegistry serverRegistry = (JMXServerRegistry)ApplicationRegistry.getServerRegistry(server);
+ final ServerRegistry serverRegistry = ApplicationRegistry.getServerRegistry(server);
if (serverRegistry == null) // server connection is closed
continue;
@@ -758,8 +794,8 @@
}
/**
- *
- *
+ * Gets the list of closed server connection from the ApplicationRegistry and then removes
+ * the closed server nodes from the navigation view
*/
private void refreshClosedServerConnections()
{
Modified: incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java?view=diff&rev=493771&r1=493770&r2=493771
==============================================================================
--- incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java (original)
+++ incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NotificationsTabControl.java Sun Jan 7 09:03:17 2007
@@ -196,7 +196,7 @@
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));
Modified: incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java?view=diff&rev=493771&r1=493770&r2=493771
==============================================================================
--- incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java (original)
+++ incubator/qpid/branches/new_persistence/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java Sun Jan 7 09:03:17 2007
@@ -388,10 +388,10 @@
return response;
}
- public static void popupError(String title, String message, Exception ex)
+ public static void popupError(String title, String message, Throwable ex)
{
IStatus status = new Status(IStatus.ERROR, ApplicationWorkbenchAdvisor.PERSPECTIVE_ID,
- IStatus.ERROR, ex.getMessage(), ex);
+ IStatus.ERROR, ex.toString(), ex);
ErrorDialog.openError(Display.getCurrent().getActiveShell(), title, message, status);
}