1 22 package org.jboss.management.j2ee; 23 24 import org.jboss.logging.Logger; 25 26 import javax.management.MBeanServer ; 27 import javax.management.MalformedObjectNameException ; 28 import javax.management.ObjectName ; 29 import java.net.URL ; 30 import java.security.InvalidParameterException ; 31 import java.util.ArrayList ; 32 import java.util.HashMap ; 33 import java.util.Hashtable ; 34 import java.util.List ; 35 import java.util.Map ; 36 import java.util.Set ; 37 38 47 public class EJBModule 48 extends J2EEModule 49 implements EJBModuleMBean 50 { 51 private static final String [] eventTypes = {NotificationConstants.OBJECT_CREATED, 52 NotificationConstants.OBJECT_DELETED}; 53 54 private static Logger log = Logger.getLogger(EJBModule.class); 56 57 private List mEJBs = new ArrayList (); 59 60 private ObjectName moduleServiceName; 61 private String mJBossDD; 62 private String mJAWSDD; 63 private String mCMPDD; 64 65 68 private static final Map fakeJ2EEApps = new HashMap (); 69 70 72 82 public static ObjectName create(MBeanServer mbeanServer, 83 String earName, 84 String jarName, 85 URL pURL, 86 ObjectName moduleServiceName) 87 { 88 String lDD = null; 89 String lJBossDD = null; 90 String lJAWSDD = null; 91 String lCMPDD = null; 92 ObjectName lParent = null; 93 ObjectName lCreated = null; 94 ObjectName jsr77Name = null; 95 ObjectName j2eeServerName = J2EEDomain.getDomainServerName(mbeanServer); 97 try 98 { 99 Hashtable props = j2eeServerName.getKeyPropertyList(); 100 String j2eeServer = props.get(J2EEManagedObject.TYPE) + "=" + 101 props.get("name"); 102 103 if (earName == null) 104 { 105 lParent = j2eeServerName; 107 } 108 else 109 { 110 ObjectName lApplicationQuery = new ObjectName (J2EEDomain.getDomainName() + ":" + 112 J2EEManagedObject.TYPE + "=" + J2EETypeConstants.J2EEApplication + "," + 113 "name=" + earName + "," + 114 j2eeServer + "," + 115 "*"); 116 Set parentApps = mbeanServer.queryNames(lApplicationQuery, null); 117 118 if (parentApps.isEmpty()) 119 { 120 lCreated = J2EEApplication.create(mbeanServer, 121 earName, 122 null); 123 lParent = lCreated; 124 } else if (parentApps.size() == 1) 126 { 127 lParent = (ObjectName ) parentApps.iterator().next(); 128 } } 130 131 lDD = J2EEDeployedObject.getDeploymentDescriptor(pURL, J2EEDeployedObject.EJB); 133 lJBossDD = J2EEDeployedObject.getDeploymentDescriptor(pURL, J2EEDeployedObject.JBOSS); 135 lJAWSDD = J2EEDeployedObject.getDeploymentDescriptor(pURL, J2EEDeployedObject.JAWS); 137 lCMPDD = J2EEDeployedObject.getDeploymentDescriptor(pURL, J2EEDeployedObject.CMP); 139 } 140 catch (Exception e) 141 { 142 log.debug("Could not create JSR-77 EJBModule: " + jarName, e); 143 return null; 144 } 145 146 try 147 { 148 String [] jvms = (String []) mbeanServer.getAttribute(j2eeServerName, 150 "javaVMs"); 151 152 EJBModule ejbModule = new EJBModule(jarName, lParent, 153 jvms, 154 lDD, 155 moduleServiceName, 156 lJBossDD, 157 lJAWSDD, 158 lCMPDD); 159 jsr77Name = ejbModule.getObjectName(); 160 mbeanServer.registerMBean(ejbModule, jsr77Name); 161 if (lCreated != null) 163 { 164 fakeJ2EEApps.put(jsr77Name, lCreated); 165 } 166 log.debug("Created JSR-77 EJBModule: " + jsr77Name); 167 } 168 catch (Exception e) 169 { 170 log.error("Could not create JSR-77 EJBModule: " + jarName, e); 171 } 172 173 return jsr77Name; 174 } 175 176 182 public static void destroy(MBeanServer mbeanServer, ObjectName jsr77Name) 183 { 184 try 185 { 186 log.debug("destroy(), remove EJB-Module: " + jsr77Name); 187 mbeanServer.unregisterMBean(jsr77Name); 188 189 ObjectName jsr77ParentName = (ObjectName ) fakeJ2EEApps.get(jsr77Name); 190 if (jsr77ParentName != null) 191 { 192 log.debug("Remove fake JSR-77 parent Application: " + jsr77ParentName); 193 J2EEApplication.destroy(mbeanServer, jsr77ParentName); 194 } 195 } 196 catch (Exception e) 197 { 198 log.debug("Could not destroy JSR-77 EJBModule: " + jsr77Name, e); 199 } 200 } 201 202 204 218 public EJBModule(String jarName, 219 ObjectName jsr77ParentName, 220 String [] pJVMs, 221 String pDeploymentDescriptor, 222 ObjectName moduleServiceName, 223 String pJBossDD, 224 String pJAWSDD, 225 String pCMPDD) 226 throws 227 MalformedObjectNameException , 228 InvalidParentException 229 { 230 super(J2EETypeConstants.EJBModule, jarName, jsr77ParentName, pJVMs, pDeploymentDescriptor); 231 this.moduleServiceName = moduleServiceName; 232 mJBossDD = (pJBossDD == null ? "" : pJBossDD); 233 mJAWSDD = (pJAWSDD == null ? "" : pJAWSDD); 234 mCMPDD = (pCMPDD == null ? "" : pCMPDD); 235 } 236 237 239 242 public String [] getejbs() 243 { 244 return (String []) mEJBs.toArray(new String [mEJBs.size()]); 245 } 246 247 250 public String getejb(int pIndex) 251 { 252 if (pIndex >= 0 && pIndex < mEJBs.size()) 253 { 254 return (String ) mEJBs.get(pIndex); 255 } 256 else 257 { 258 return null; 259 } 260 } 261 262 266 public String getjbossDeploymentDescriptor() 267 { 268 return mJBossDD; 269 } 270 271 275 public String getjawsDeploymentDescriptor() 276 { 277 return mJAWSDD; 278 } 279 280 284 public String getcmpDeploymentDescriptor() 285 { 286 return mCMPDD; 287 } 288 289 291 public void addChild(ObjectName pChild) 292 { 293 String lType = J2EEManagedObject.getType(pChild); 294 if (J2EETypeConstants.EntityBean.equals(lType) || 295 J2EETypeConstants.StatelessSessionBean.equals(lType) || 296 J2EETypeConstants.StatefulSessionBean.equals(lType) || 297 J2EETypeConstants.MessageDrivenBean.equals(lType) 298 ) 299 { 300 mEJBs.add(pChild.getCanonicalName()); 301 } 302 } 303 304 public void removeChild(ObjectName pChild) 305 { 306 String lType = J2EEManagedObject.getType(pChild); 307 if (J2EETypeConstants.EntityBean.equals(lType) || 308 J2EETypeConstants.StatelessSessionBean.equals(lType) || 309 J2EETypeConstants.StatefulSessionBean.equals(lType) || 310 J2EETypeConstants.MessageDrivenBean.equals(lType) 311 ) 312 { 313 mEJBs.remove(pChild.getCanonicalName()); 314 } 315 } 316 317 public void postCreation() 318 { 319 sendNotification(NotificationConstants.OBJECT_CREATED, "EJB Module created"); 320 } 321 322 public void preDestruction() 323 { 324 sendNotification(NotificationConstants.OBJECT_DELETED, "EJB Module destroyed"); 325 } 326 327 329 public String [] getEventTypes() 330 { 331 return eventTypes; 332 } 333 334 public String getEventType(int index) 335 { 336 String type = null; 337 if (index >= 0 && index < eventTypes.length) 338 { 339 type = eventTypes[index]; 340 } 341 return type; 342 } 343 344 346 public String toString() 347 { 348 return "EJBModule[ " + super.toString() + 349 ", EJBs: " + mEJBs + 350 ", JBoss-DD: " + mJBossDD + 351 ", JAWS-DD: " + mJAWSDD + 352 ", CMP-2.0-DD: " + mCMPDD + 353 " ]"; 354 } 355 356 358 360 364 protected Hashtable getParentKeys(ObjectName jsr77ParentName) 365 { 366 Hashtable parentKeys = new Hashtable (); 367 Hashtable parentProps = jsr77ParentName.getKeyPropertyList(); 368 String parentName = (String ) parentProps.get("name"); 369 String j2eeType = (String ) parentProps.get(J2EEManagedObject.TYPE); 370 371 if (j2eeType.equals(J2EETypeConstants.J2EEApplication) == false) 373 { 374 parentKeys.put(J2EETypeConstants.J2EEServer, parentName); 376 parentKeys.put(J2EETypeConstants.J2EEApplication, "null"); 377 } 378 else 379 { 380 parentKeys.put(J2EETypeConstants.J2EEApplication, parentName); 382 String j2eeServerName = (String ) parentProps.get(J2EETypeConstants.J2EEServer); 383 parentKeys.put(J2EETypeConstants.J2EEServer, j2eeServerName); 384 } 385 386 return parentKeys; 387 } 388 389 391 } 393 394 397 | Popular Tags |