View Javadoc

1   /*
2    * Copyright 2010 James Pether Sörling
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id: JmxPanel.java 5034 2010-11-23 22:22:12Z pether $
17   *  $HeadURL: https://cia.svn.sourceforge.net/svnroot/cia/trunk/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/page/admin/JmxPanel.java $
18  */
19  package com.hack23.cia.web.impl.ui.page.admin;
20  
21  import java.util.Arrays;
22  import java.util.Set;
23  
24  import javax.management.MBeanAttributeInfo;
25  import javax.management.MBeanInfo;
26  import javax.management.MBeanOperationInfo;
27  import javax.management.MBeanServer;
28  import javax.management.ObjectName;
29  
30  import org.springframework.jmx.support.JmxUtils;
31  
32  import com.hack23.cia.web.impl.ui.page.common.AbstractPanel;
33  import com.vaadin.data.Item;
34  import com.vaadin.ui.Tree;
35  import com.vaadin.ui.VerticalLayout;
36  
37  /***
38   * The Class JmxPanel.
39   */
40  public class JmxPanel extends AbstractPanel {
41  
42  	/*** The content. */
43  	private VerticalLayout content = null;
44  
45  	/*** The Constant serialVersionUID. */
46  	private static final long serialVersionUID = 1L;
47  
48  	/***
49  	 * Instantiates a new jmx panel.
50  	 */
51  	public JmxPanel() {
52  		super();
53  		content =new VerticalLayout();
54  		setContent(content);
55  		content.setHeight(null);
56  		content.setWidth("100%");
57  		//content.setSizeFull();
58  		content.setSpacing(true);
59  		content.setMargin(true);
60  
61  
62  		String[] domains;
63  		try {
64  			MBeanServer mBeanServer = JmxUtils.locateMBeanServer();
65  			
66  			
67  			domains = mBeanServer.getDomains();
68  			Arrays.sort(domains);
69  
70  			final Tree tree = new Tree("Domains");
71  
72  			for (int i=0; i<domains.length; i++) {
73  			    final String domain = (domains[i]);
74  			    final Item domainItem = tree.addItem(domain);
75  			    Set<ObjectName> queryNames = mBeanServer.queryNames(new ObjectName(domain + ":*"), null);
76  			    
77  				for (final ObjectName objectName: queryNames)
78  				{
79  					MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(objectName);
80  					
81  					final String objectCaption = mBeanInfo.getClassName();
82  
83  					final Item objectNameItem = tree.addItem(objectCaption);
84  					tree.setParent(objectCaption, domain);
85  
86  					
87  					final String attributeHeaderCaption = objectCaption +".Attributes";
88  					final Item attributeHeaderItem = tree.addItem(attributeHeaderCaption);
89  					tree.setParent(attributeHeaderCaption,objectCaption);
90  					
91  					MBeanAttributeInfo[] attributes = mBeanInfo.getAttributes();
92  					for (MBeanAttributeInfo mBeanAttributeInfo: attributes) {
93  						String attributeCaption = objectCaption + "." +  mBeanAttributeInfo.getDescription();						
94  						final Item attributeItem = tree.addItem(attributeCaption);
95  						tree.setParent(attributeCaption, objectCaption);
96  					}
97  					
98  
99  					final String opHeaderCaption = objectCaption +".Operations";
100 					final Item opHeaderItem = tree.addItem(opHeaderCaption);
101 					tree.setParent(opHeaderCaption,objectCaption);
102 					
103 					MBeanOperationInfo[] operations = mBeanInfo.getOperations();
104 					
105 					for (MBeanOperationInfo mBeanOperationInfo: operations) {
106 						String opCaption =  objectCaption + "." + mBeanOperationInfo.getDescription();						
107 						final Item opItem = tree.addItem(opCaption);
108 						tree.setParent(opCaption, opHeaderCaption);
109 					}
110 					
111 				}
112 
113 			}
114 
115 			content.addComponent(tree);
116 			tree.setSizeFull();
117 		} catch (final Exception e) {
118 			e.printStackTrace();
119 		}
120 
121 		setSizeFull();
122 
123 		setCaption(translateFromEnglish("Jmx Panel"));
124 	}
125 
126 
127 }