1 22 package org.jboss.management.j2ee; 23 24 import java.net.URL ; 25 import java.security.InvalidParameterException ; 26 import java.util.ArrayList ; 27 import java.util.Hashtable ; 28 import java.util.List ; 29 30 import javax.management.MBeanServer ; 31 import javax.management.MalformedObjectNameException ; 32 import javax.management.ObjectName ; 33 34 import org.jboss.logging.Logger; 35 36 45 public class ServiceModule extends J2EEModule 46 implements ServiceModuleMBean 47 { 48 private static final String [] eventTypes = {NotificationConstants.OBJECT_CREATED, 49 NotificationConstants.OBJECT_DELETED}; 50 51 private static Logger log = Logger.getLogger(ServiceModule.class); 53 54 private List mbeans = new ArrayList (); 56 57 59 public static ObjectName create(MBeanServer mbeanServer, String moduleName, URL url) 60 { 61 String lDD = null; 62 ObjectName jsr77Name = null; 63 ObjectName j2eeServerName = J2EEDomain.getDomainServerName(mbeanServer); 64 65 if (url != null && url.getFile().endsWith(".xml")) 67 { 68 lDD = J2EEDeployedObject.getDeploymentDescriptor(url, null); 70 } 71 else 72 { 73 lDD = J2EEDeployedObject.getDeploymentDescriptor(url, J2EEDeployedObject.SAR); 75 } 76 77 try 78 { 79 String [] jvms = (String []) mbeanServer.getAttribute(j2eeServerName, "javaVMs"); 81 ServiceModule serviceModule = new ServiceModule(moduleName, j2eeServerName, jvms, lDD); 83 jsr77Name = serviceModule.getObjectName(); 84 mbeanServer.registerMBean(serviceModule, jsr77Name); 85 log.debug("Created JSR-77 ServiceModule, name: " + moduleName); 86 } 87 catch (Exception e) 88 { 89 log.debug("Could not create JSR-77 ServiceModule: " + moduleName, e); 90 } 91 return jsr77Name; 92 } 93 94 public static void destroy(MBeanServer mbeanServer, String pModuleName) 95 { 96 try 97 { 98 log.debug("destroy(), remove Service Module: " + pModuleName); 99 if (pModuleName.indexOf(J2EEManagedObject.TYPE + "=" + J2EETypeConstants.ServiceModule) >= 0) 101 { 102 J2EEManagedObject.removeObject(mbeanServer, pModuleName); 103 } 104 else 105 { 106 J2EEManagedObject.removeObject(mbeanServer, 107 pModuleName, 108 J2EEDomain.getDomainName() + ":" + 109 J2EEManagedObject.TYPE + "=" + J2EETypeConstants.ServiceModule + 110 "," + "*"); 111 } 112 } 113 catch (javax.management.InstanceNotFoundException infe) 114 { 115 } 116 catch (Throwable e) 117 { 118 log.error("Could not destroy JSR-77 ServiceModule: " + pModuleName, e); 119 } 120 } 121 122 124 132 public ServiceModule(String moduleName, ObjectName j2eeServerName, 133 String [] jvmNames, String pDeploymentDescriptor) 134 throws MalformedObjectNameException , 135 InvalidParentException 136 { 137 super(J2EETypeConstants.ServiceModule, moduleName, j2eeServerName, jvmNames, pDeploymentDescriptor); 138 } 139 140 142 144 147 public String [] getMBeans() 148 { 149 return (String []) mbeans.toArray(new String [mbeans.size()]); 150 } 151 152 155 public String getMBean(int pIndex) 156 { 157 if (pIndex >= 0 && pIndex < mbeans.size()) 158 { 159 return (String ) mbeans.get(pIndex); 160 } 161 else 162 { 163 return null; 164 } 165 } 166 167 169 public void addChild(ObjectName pChild) 170 { 171 String lType = J2EEManagedObject.getType(pChild); 172 if (J2EETypeConstants.MBean.equals(lType)) 173 { 174 mbeans.add(pChild.getCanonicalName()); 175 } 176 } 177 178 public void removeChild(ObjectName pChild) 179 { 180 String lType = J2EEManagedObject.getType(pChild); 181 if (J2EETypeConstants.MBean.equals(lType)) 182 { 183 mbeans.remove(pChild.getCanonicalName()); 184 } 185 } 186 187 189 public String [] getEventTypes() 190 { 191 return eventTypes; 192 } 193 194 public String getEventType(int index) 195 { 196 String type = null; 197 if (index >= 0 && index < eventTypes.length) 198 { 199 type = eventTypes[index]; 200 } 201 return type; 202 } 203 204 205 207 public void postCreation() 208 { 209 sendNotification(NotificationConstants.OBJECT_CREATED, "SAR module created"); 210 } 211 212 public void preDestruction() 213 { 214 sendNotification(NotificationConstants.OBJECT_DELETED, "SAR module destroyed"); 215 } 216 217 219 public String toString() 220 { 221 return "ServiceModule[ " + super.toString() + 222 "MBeans: " + mbeans + 223 " ]"; 224 } 225 226 228 230 233 protected Hashtable getParentKeys(ObjectName pParent) 234 { 235 Hashtable lReturn = new Hashtable (); 236 Hashtable lProperties = pParent.getKeyPropertyList(); 237 lReturn.put(J2EETypeConstants.J2EEServer, lProperties.get("name")); 238 239 return lReturn; 240 } 241 } 242 | Popular Tags |