1 package net.sf.panoptes.component.jmx.model; 2 3 import java.io.IOException ; 4 import java.lang.reflect.UndeclaredThrowableException ; 5 import java.rmi.ConnectException ; 6 import java.rmi.UnmarshalException ; 7 import java.util.ArrayList ; 8 import java.util.Iterator ; 9 import java.util.List ; 10 import java.util.Map ; 11 12 import javax.management.AttributeNotFoundException ; 13 import javax.management.InstanceNotFoundException ; 14 import javax.management.IntrospectionException ; 15 import javax.management.InvalidAttributeValueException ; 16 import javax.management.MBeanAttributeInfo ; 17 import javax.management.MBeanException ; 18 import javax.management.MBeanInfo ; 19 import javax.management.MBeanNotificationInfo ; 20 import javax.management.MBeanOperationInfo ; 21 import javax.management.ObjectName ; 22 import javax.management.ReflectionException ; 23 import javax.management.relation.Relation ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 import net.sf.panoptes.model.node.GroupNode; 29 import net.sf.panoptes.model.node.Leaf; 30 import net.sf.panoptes.model.node.Node; 31 import net.sf.panoptes.model.node.NodeDescriptor; 32 import net.sf.panoptes.model.node.NodeSupport; 33 34 44 45 public class MBeanWrapper { 46 private static Log log = LogFactory.getLog(MBeanWrapper.class); 47 private MBeanServerNode server; 48 private DomainNode domain; 49 50 private ObjectName objectName; 51 private MBeanInfo mBeanInfo; 52 private Object proxy = null; 53 54 55 56 59 public MBeanWrapper(MBeanServerNode server, ObjectName objectName) 60 throws InstanceNotFoundException , IntrospectionException , ReflectionException , IOException { 61 this.objectName = objectName; 62 this.server = server; 63 64 mBeanInfo = server.getServerConnection().getMBeanInfo(objectName); 65 String name = getObjectName().getCanonicalName(); 66 name = name.substring(name.indexOf(':') + 1); 67 } 68 69 73 protected void setObjectName(ObjectName name) { 74 this.objectName = name; 75 } 76 77 public void setMBeanServerComponent(MBeanServerNode server) { 78 this.server = server; 79 } 80 81 85 public MBeanAttributeInfo [] getAttributes() { 86 return mBeanInfo.getAttributes(); 87 } 88 89 public MBeanNotificationInfo [] getNotifications() { 90 return mBeanInfo.getNotifications(); 91 } 92 93 96 public MBeanOperationInfo [] getOperations() { 97 return mBeanInfo.getOperations(); 98 } 99 100 104 public void setMBeanInfo(MBeanInfo info) { 105 this.mBeanInfo = info; 106 } 107 108 public MBeanInfo getMBeanInfo() { 109 return this.mBeanInfo; 110 } 111 112 public MBeanServerNode getServer() { 113 return server; 114 } 115 116 public Object getProxy() throws Exception { 117 if (proxy == null) 118 proxy = 119 MBeanProxyFactory.getInstance().createProxy( 120 this.getObjectName(), 121 this.getServer().getServerConnection()); 122 return proxy; 123 } 124 125 128 public void refresh() { 129 } 132 133 public ObjectName getObjectName() { 134 return this.objectName; 135 136 } 137 public String toString() { 138 return this.objectName.toString(); 139 } 140 141 143 148 public Object getAttributeValue(String attributeName) { 149 Object value = "unable to get attribute '" + attributeName + "'"; 150 try { 151 ObjectName objectName = getObjectName(); 152 value = server.getServerConnection().getAttribute(objectName, attributeName); 153 } catch (UndeclaredThrowableException e) { 154 if (e.getCause().getCause() instanceof UnmarshalException ) 156 value = "unknown attribute class"; 157 } catch (MBeanException e) { 158 if (e.getCause() instanceof UnmarshalException ) 160 value = "unknown or not serializable attribute class"; 161 } catch (AttributeNotFoundException e) { 162 value = "attribute does not exist"; 163 } catch (NoClassDefFoundError e) { 164 value = "unknown attribute class"; 165 } catch (ConnectException ce) { 166 log.warn("Server disconnected"); 167 try { 168 server.disconnect(); 169 } catch (Exception e1) { 170 } 171 } catch (Exception e) { 172 log.warn("Unable to get attribute '" + attributeName + "'", e); 173 } 174 return value; 175 } 176 177 public void setAttrbuteValue(String attributeName, Object value) { 178 javax.management.Attribute attribute = new javax.management.Attribute (attributeName, value); 179 try { 180 server.getServerConnection().setAttribute(getObjectName(), attribute); 181 } catch (InstanceNotFoundException e) { 182 System.err.println("InstanceNotFoundException " + e); 183 } catch (AttributeNotFoundException e) { 184 System.err.println("AttributeNotFoundException " + e); 185 } catch (InvalidAttributeValueException e) { 186 System.err.println("InvalidAttributeValueException " + e); 187 } catch (MBeanException e) { 188 System.err.println("MBeanException" + e); 189 } catch (Exception e) { 190 log.error("Unable to set attribute " + attributeName + "'", e); 191 } 192 193 } 194 195 196 } 197 | Popular Tags |