Source Code Cross Referenced for MBeansTab.java in  » 6.0-JDK-Modules-sun » tools » sun » tools » jconsole » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules sun » tools » sun.tools.jconsole 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2006 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package sun.tools.jconsole;
027:
028:        import java.awt.BorderLayout;
029:        import java.awt.event.MouseAdapter;
030:        import java.awt.event.MouseEvent;
031:        import java.awt.event.MouseListener;
032:        import java.beans.*;
033:        import java.io.*;
034:        import java.util.Set;
035:        import javax.management.*;
036:        import javax.swing.*;
037:        import javax.swing.event.*;
038:        import javax.swing.tree.*;
039:        import sun.tools.jconsole.inspector.*;
040:
041:        import com.sun.tools.jconsole.JConsoleContext;
042:
043:        @SuppressWarnings("serial")
044:        public class MBeansTab extends Tab implements  NotificationListener,
045:                PropertyChangeListener, TreeSelectionListener {
046:
047:            private XTree tree;
048:            private XSheet sheet;
049:            private XDataViewer viewer;
050:
051:            public static String getTabName() {
052:                return Resources.getText("MBeans");
053:            }
054:
055:            public MBeansTab(final VMPanel vmPanel) {
056:                super (vmPanel, getTabName());
057:                addPropertyChangeListener(this );
058:                setupTab();
059:            }
060:
061:            public XDataViewer getDataViewer() {
062:                return viewer;
063:            }
064:
065:            public XTree getTree() {
066:                return tree;
067:            }
068:
069:            public XSheet getSheet() {
070:                return sheet;
071:            }
072:
073:            public void dispose() {
074:                super .dispose();
075:                sheet.dispose();
076:            }
077:
078:            public int getUpdateInterval() {
079:                return vmPanel.getUpdateInterval();
080:            }
081:
082:            void synchroniseMBeanServerView() {
083:                // Register listener for MBean registration/unregistration
084:                //
085:                try {
086:                    getMBeanServerConnection()
087:                            .addNotificationListener(
088:                                    MBeanServerDelegate.DELEGATE_NAME, this ,
089:                                    null, null);
090:                } catch (InstanceNotFoundException e) {
091:                    // Should never happen because the MBeanServerDelegate
092:                    // is always present in any standard MBeanServer
093:                    //
094:                    if (JConsole.isDebug()) {
095:                        e.printStackTrace();
096:                    }
097:                } catch (IOException e) {
098:                    if (JConsole.isDebug()) {
099:                        e.printStackTrace();
100:                    }
101:                    vmPanel.getProxyClient().markAsDead();
102:                    return;
103:                }
104:                // Retrieve MBeans from MBeanServer
105:                //
106:                Set<ObjectName> newSet = null;
107:                try {
108:                    newSet = getMBeanServerConnection().queryNames(null, null);
109:                } catch (IOException e) {
110:                    if (JConsole.isDebug()) {
111:                        e.printStackTrace();
112:                    }
113:                    vmPanel.getProxyClient().markAsDead();
114:                    return;
115:                }
116:                // Cleanup current tree
117:                //
118:                tree.removeAll();
119:                // Do not display anything until the new tree has been built
120:                //
121:                tree.setVisible(false);
122:                // Add MBeans to tree
123:                //
124:                for (ObjectName mbean : newSet) {
125:                    tree.addMBeanToView(mbean);
126:                }
127:                // Display the new tree
128:                //
129:                tree.setVisible(true);
130:            }
131:
132:            public MBeanServerConnection getMBeanServerConnection() {
133:                return vmPanel.getProxyClient().getMBeanServerConnection();
134:            }
135:
136:            public void update() {
137:                // Ping the connection to see if it is still alive. At
138:                // some point the ProxyClient class should centralize
139:                // the connection aliveness monitoring and no longer
140:                // rely on the custom tabs to ping the connections.
141:                //
142:                try {
143:                    getMBeanServerConnection().getDefaultDomain();
144:                } catch (IOException ex) {
145:                    vmPanel.getProxyClient().markAsDead();
146:                }
147:            }
148:
149:            private void setupTab() {
150:                // set up the split pane with the MBean tree and MBean sheet panels
151:                setLayout(new BorderLayout());
152:                JSplitPane mainSplit = new JSplitPane(
153:                        JSplitPane.HORIZONTAL_SPLIT);
154:                mainSplit.setDividerLocation(160);
155:                mainSplit.setBorder(BorderFactory.createEmptyBorder());
156:
157:                // set up the MBean tree panel (left pane)
158:                tree = new XTree(this );
159:                tree.setCellRenderer(new XTreeRenderer());
160:                tree.getSelectionModel().setSelectionMode(
161:                        TreeSelectionModel.SINGLE_TREE_SELECTION);
162:                tree.addTreeSelectionListener(this );
163:                tree.addMouseListener(ml);
164:                JScrollPane theScrollPane = new JScrollPane(tree,
165:                        JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
166:                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
167:                JPanel treePanel = new JPanel(new BorderLayout());
168:                treePanel.add(theScrollPane, BorderLayout.CENTER);
169:                mainSplit.add(treePanel, JSplitPane.LEFT, 0);
170:
171:                // set up the MBean sheet panel (right pane)
172:                viewer = new XDataViewer(this );
173:                sheet = new XSheet(this );
174:                mainSplit.add(sheet, JSplitPane.RIGHT, 0);
175:
176:                add(mainSplit);
177:            }
178:
179:            /* notification listener */
180:            public void handleNotification(Notification notification,
181:                    Object handback) {
182:                if (notification instanceof  MBeanServerNotification) {
183:                    ObjectName mbean = ((MBeanServerNotification) notification)
184:                            .getMBeanName();
185:                    if (notification.getType().equals(
186:                            MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
187:                        tree.addMBeanToView(mbean);
188:                    } else if (notification
189:                            .getType()
190:                            .equals(
191:                                    MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
192:                        tree.delMBeanFromView(mbean);
193:                    }
194:                }
195:            }
196:
197:            /* property change listener */
198:            public void propertyChange(PropertyChangeEvent evt) {
199:                if (evt.getPropertyName() == JConsoleContext.CONNECTION_STATE_PROPERTY) {
200:                    boolean connected = (Boolean) evt.getNewValue();
201:                    if (connected) {
202:                        workerAdd(new Runnable() {
203:                            public void run() {
204:                                synchroniseMBeanServerView();
205:                            }
206:                        });
207:                    } else {
208:                        sheet.dispose();
209:                    }
210:                }
211:
212:            }
213:
214:            /* tree selection listener */
215:            public void valueChanged(TreeSelectionEvent e) {
216:                DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
217:                        .getLastSelectedPathComponent();
218:                sheet.displayNode(node);
219:            }
220:
221:            /* tree mouse listener */
222:            private MouseListener ml = new MouseAdapter() {
223:                public void mousePressed(MouseEvent e) {
224:                    if (e.getClickCount() == 1) {
225:                        int selRow = tree.getRowForLocation(e.getX(), e.getY());
226:                        if (selRow != -1) {
227:                            TreePath selPath = tree.getPathForLocation(
228:                                    e.getX(), e.getY());
229:                            DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath
230:                                    .getLastPathComponent();
231:                            if (sheet.isMBeanNode(node)) {
232:                                tree.expandPath(selPath);
233:                            }
234:                        }
235:                    }
236:                }
237:            };
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.