View Javadoc
1 package net.sf.panoptes.model.component.jmx; 2 3 import java.util.Collection; 4 import java.util.HashMap; 5 6 import javax.management.Attribute; 7 import javax.management.AttributeNotFoundException; 8 import javax.management.InstanceNotFoundException; 9 import javax.management.MBeanAttributeInfo; 10 import javax.management.MBeanException; 11 import javax.management.MBeanInfo; 12 import javax.management.MBeanOperationInfo; 13 import javax.management.ObjectName; 14 import javax.management.ReflectionException; 15 16 import net.sf.panoptes.model.component.Component; 17 import net.sf.panoptes.model.node.NodeDescriptor; 18 import net.sf.panoptes.model.node.INode; 19 20 /*** 21 * MBeanComponent.java 22 * 23 * Wraps an MBean and implements helper methods. Original code by Stefan Groschupf(sg@media-style.com). 24 * 25 * @author Dag Liodden 26 * @version 0.1 27 * 28 */ 29 30 public class MBeanComponent extends Component { 31 32 private MBeanServerComponent server; 33 private HashMap mBeanAttributes = null; 34 private HashMap mBeanOperations = null; 35 private ObjectName mBeanName; 36 private MBeanInfo mBeanInfo; 37 38 /*** 39 * Constructor for MBeanComponent. 40 */ 41 public MBeanComponent(MBeanInfo beanInfo, MBeanServerComponent server, ObjectName name) { 42 setMBeanInfo(beanInfo); 43 setName(name); 44 this.server = server; 45 } 46 47 /*** 48 * Method setName. 49 * @param name 50 */ 51 private void setName(ObjectName name) { 52 this.mBeanName = name; 53 } 54 /*** 55 * Method getAttributes. 56 * @return Attribute[] 57 */ 58 public Attribute[] getAttributes() { 59 Collection collection = this.getMBeanAttributes().values(); 60 return (Attribute[]) collection.toArray(new Attribute[collection.size()]); 61 62 } 63 /*** 64 * Method getOperations. 65 */ 66 public Operation[] getOperations() { 67 Collection collection = getMBeanOperations().values(); 68 return (Operation[]) collection.toArray(new Operation[collection.size()]); 69 70 } 71 /*** 72 * Method setMBeanInfo. 73 * @param info 74 */ 75 public void setMBeanInfo(MBeanInfo info) { 76 this.mBeanInfo = info; 77 } 78 79 public MBeanServerComponent getServer() { 80 return server; 81 } 82 83 /*** 84 * Method refresh. 85 */ 86 public void refresh() { 87 refreshOperations(); 88 refreshAttributes(); 89 } 90 /*** 91 * Method refreshAttributes. 92 */ 93 private void refreshAttributes() { 94 MBeanAttributeInfo[] at = mBeanInfo.getAttributes(); 95 mBeanAttributes = new HashMap(); 96 97 for (int i = 0; i < at.length; i++) { 98 Attribute attribute = new Attribute(at[i].getName(), getAttributeValue(at[i].getName())); 99 // Attribute attribute = new Attribute(at[i].getName(), this); 100 getMBeanAttributes().put(attribute.getName(), attribute); 101 } 102 } 103 /*** 104 * Method getAttrbuteValue. 105 * @param string 106 */ 107 private void getAttrbuteValue(String string) { 108 } 109 /*** 110 * Method refreshOperations. 111 */ 112 private void refreshOperations() { 113 //operations 114 MBeanOperationInfo[] op = mBeanInfo.getOperations(); 115 mBeanOperations = new HashMap(); 116 117 for (int k = 0; k < op.length; k++) { 118 Operation operation = new Operation(op[k], this); 119 getMBeanOperations().put(operation.getName(), operation); 120 } 121 122 } 123 124 125 public ObjectName getObjectName() { 126 return this.mBeanName; 127 128 } 129 public String toString() { 130 return this.mBeanName.toString(); 131 } 132 /*** 133 * Method countAttributes. 134 * @return int 135 */ 136 public int countAttributes() { 137 return getMBeanAttributes().size(); 138 } 139 140 141 private HashMap getMBeanAttributes() { 142 if (mBeanAttributes == null) refreshAttributes(); 143 return mBeanAttributes; 144 } 145 146 private HashMap getMBeanOperations() { 147 if (mBeanOperations == null) refreshOperations(); 148 return mBeanOperations; 149 } 150 151 // property stuff. 152 153 /*** 154 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue() 155 */ 156 public Object getEditableValue() { 157 return null; 158 } 159 160 /*** 161 * Method getAttrbute. 162 * @param string 163 * @return String 164 */ 165 public Object getAttributeValue(String attributeName) { 166 Object value = null; 167 try { 168 ObjectName objectName = getObjectName(); 169 value = server.getConnector().getAttribute(objectName, attributeName); 170 } catch (AttributeNotFoundException e) { 171 } catch (InstanceNotFoundException e) { 172 } catch (MBeanException e) { 173 } catch (ReflectionException e) { 174 System.err.println("cant get Attribute" + e); 175 } 176 return value; 177 } 178 179 public void setAttrbuteValue(String attributeName, Object value) { 180 181 /*RMIConnectorImpl server = getParent().getServer(); 182 ObjectName objectName = getObjectName(); 183 javax.management.Attribute attribute = new javax.management.Attribute(attributeName, value); 184 try { 185 server.setAttribute(objectName, attribute); 186 } catch (InstanceNotFoundException e) { 187 System.err.println("InstanceNotFoundException "+e); 188 } catch (AttributeNotFoundException e) { 189 System.err.println("AttributeNotFoundException " +e); 190 } catch (InvalidAttributeValueException e) { 191 System.err.println("InvalidAttributeValueException " + e); 192 } catch (MBeanException e) { 193 System.err.println("MBeanException" + e); 194 } catch (ReflectionException e) { 195 System.err.println("ReflectionException" +e); 196 } 197 198 */ 199 } 200 201 202 /*** 203 * @see com.gllt.troodon.console.INode#getIconName() 204 */ 205 public String getIconName() { 206 return INode.ICON_MBEAN; 207 } 208 209 /*** 210 * @see com.gllt.troodon.console.INode#getConfigDescriptor() 211 */ 212 public NodeDescriptor getConfigDescriptor() { 213 String name = getObjectName().getCanonicalName(); 214 name = name.substring(name.indexOf(':') + 1); 215 return new NodeDescriptor( 216 name, 217 getObjectName().toString()); 218 } 219 220 }

This page was automatically generated by Maven