1 22 package org.jboss.console.plugins; 23 24 import org.jboss.console.manager.interfaces.ManageableResource; 25 import org.jboss.console.manager.interfaces.TreeNode; 26 import org.jboss.console.manager.interfaces.TreeNodeMenuEntry; 27 import org.jboss.console.manager.interfaces.impl.GraphMBeanAttributeAction; 28 import org.jboss.console.manager.interfaces.impl.SimpleTreeNodeMenuEntryImpl; 29 import org.jboss.console.manager.interfaces.impl.HttpLinkTreeAction; 30 import org.jboss.console.plugins.helpers.AbstractPluginWrapper; 31 import org.jboss.console.plugins.helpers.jmx.DomainData; 32 import org.jboss.console.plugins.helpers.jmx.MBeanData; 33 import org.jboss.console.plugins.helpers.jmx.Server; 34 35 import javax.management.MBeanAttributeInfo ; 36 import javax.management.ObjectName ; 37 import java.util.ArrayList ; 38 import java.util.Iterator ; 39 import java.util.HashSet ; 40 56 public class MBeansLister 57 extends AbstractPluginWrapper 58 { 59 private static HashSet graphableClasses = new HashSet (); 60 61 static 62 { 63 graphableClasses.add("java.lang.Integer"); 64 graphableClasses.add("java.lang.Short"); 65 graphableClasses.add("java.lang.Double"); 66 graphableClasses.add("java.lang.Float"); 67 graphableClasses.add("java.lang.Long"); 68 graphableClasses.add("int"); 69 graphableClasses.add("short"); 70 graphableClasses.add("double"); 71 graphableClasses.add("float"); 72 graphableClasses.add("long"); 73 } 74 public MBeansLister () { super(); } 75 76 TreeNode createJmxAttributeSubResource(MBeanAttributeInfo attr, ObjectName mbeanName) throws Exception 77 { 78 TreeNodeMenuEntry[] entries = null; 79 if (graphableClasses.contains(attr.getType())) 80 { 81 SimpleTreeNodeMenuEntryImpl entry = new SimpleTreeNodeMenuEntryImpl("graph", new GraphMBeanAttributeAction(mbeanName, attr.getName())); 82 SimpleTreeNodeMenuEntryImpl entry2 = new SimpleTreeNodeMenuEntryImpl("create monitor", new HttpLinkTreeAction( 83 "/web-console/createThresholdMonitor.jsp?attribute=" + attr.getName() + "&objectName=" + encode(mbeanName.toString()))); 84 SimpleTreeNodeMenuEntryImpl entry3 = new SimpleTreeNodeMenuEntryImpl("create snapshot", new HttpLinkTreeAction( 85 "/web-console/createSnapshot.jsp?attribute=" + attr.getName() + "&objectName=" + encode(mbeanName.toString()))); 86 entries = new TreeNodeMenuEntry[3]; 87 entries[0] = entry; 88 entries[1] = entry2; 89 entries[2] = entry3; 90 } 91 else if (attr.getType().equals("String") || attr.getType().equals("java.lang.String")) 92 { 93 SimpleTreeNodeMenuEntryImpl entry = new SimpleTreeNodeMenuEntryImpl("create monitor", new HttpLinkTreeAction( 94 "/web-console/createStringThresholdMonitor.jsp?attribute=" + attr.getName() + "&objectName=" + encode(mbeanName.toString()))); 95 entries = new TreeNodeMenuEntry[1]; 96 entries[0] = entry; 97 } 98 99 return createTreeNode( 100 attr.getName(), 101 attr.getDescription(), 102 "images/container.gif", 103 "/jmx-console/HtmlAdaptor?action=inspectMBean&name=" + encode("" + mbeanName), entries, 105 null, 106 null 107 ); 110 } 111 TreeNode createJmxMBeanSubResources (MBeanData data) throws Exception 112 { 113 String name = "" + data.getObjectName(); 114 String displayName = data.getName (); 115 116 if (displayName == null) 117 { 118 int index = name.indexOf( ":" ); 120 displayName = ( index >= 0 ) ? name.substring( index + 1 ) : name; 121 } 122 123 MBeanAttributeInfo [] attributes = data.getMetaData().getAttributes(); 124 TreeNode[] attrNodes = new TreeNode[attributes.length]; 125 for (int i = 0; i < attributes.length; i++) 126 { 127 attrNodes[i] = createJmxAttributeSubResource(attributes[i], data.getObjectName()); 128 } 129 130 return createTreeNode ( 131 displayName, name, "images/server.gif", "/jmx-console/HtmlAdaptor?action=inspectMBean&name=" + encode(name), null, 136 attrNodes, 137 null 138 ); 141 } 142 143 TreeNode[] createJmxDomainsSubNodes () throws Exception 144 { 145 Iterator mbeans = Server.getDomainData(null); 146 147 TreeNode[] result = null; 148 149 ArrayList domains = new ArrayList (); 150 151 while( mbeans.hasNext() ) 152 { 153 DomainData domainData = (DomainData) mbeans.next(); 154 String domainName = domainData.getDomainName(); 155 MBeanData[] data = domainData.getData(); 156 TreeNode[] subResources = new TreeNode[data.length]; 157 158 for(int d = 0; d < data.length; d ++) 159 { 160 subResources[d] = createJmxMBeanSubResources (data[d]); 161 } 162 163 TreeNodeMenuEntry[] menu = createMenus (new String [] 164 { 165 "Number of MBeans: " + data.length, null, 166 } 167 ); 168 169 domains.add(createTreeNode ( 170 domainName, "MBeans for domain " + domainName, "images/serviceset.gif", null, menu, subResources, null ) 178 ); 179 180 } 181 182 if (domains.size() == 0) 183 { 184 result = null; 185 } 186 else 187 { 188 result = (TreeNode[]) domains.toArray(new TreeNode[domains.size()]); 189 } 190 191 return result; 192 } 193 194 protected TreeNode getTreeForResource(String profile, ManageableResource resource) 195 { 196 try 197 { 198 return createTreeNode ( 199 "JMX MBeans", "Display all JMX MBeans", "images/flash.gif", "/jmx-console/HtmlAdaptor?action=displayMBeans", null, 204 createJmxDomainsSubNodes (), null ); 207 } 208 catch (Exception e) 209 { 210 e.printStackTrace (); 211 return null; 212 } 213 } 214 } 215 | Popular Tags |