1 23 24 37 package com.sun.enterprise.server; 38 39 import java.util.Set ; 40 import com.sun.enterprise.loader.EJBClassPathUtils; 41 import com.sun.enterprise.config.ConfigException; 42 import com.sun.enterprise.instance.EjbModulesManager; 43 44 import java.util.logging.Level ; 45 import java.util.logging.Logger ; 46 import com.sun.logging.LogDomains; 47 import com.sun.enterprise.loader.EJBClassLoader; 48 49 import com.sun.enterprise.instance.InstanceEnvironment; 51 import com.sun.enterprise.deployment.io.EjbDeploymentDescriptorFile; 52 import com.sun.enterprise.deployment.node.J2EEDocumentBuilder; 53 import com.sun.enterprise.deployment.BundleDescriptor; 54 import com.sun.enterprise.deployment.Descriptor; 55 import com.sun.enterprise.deployment.EjbDescriptor; 56 import com.sun.enterprise.deployment.EjbBundleDescriptor; 57 import com.sun.enterprise.deployment.Application; 58 import java.util.Iterator ; 59 import javax.enterprise.deploy.shared.ModuleType ; 60 import javax.management.MBeanException ; 61 import com.sun.enterprise.Switch; 62 63 import com.sun.enterprise.server.event.ApplicationEvent; 64 65 72 class EJBModuleLoader extends AbstractLoader { 73 74 static Logger _logger=LogDomains.getLogger(LogDomains.LOADER_LOGGER); 75 76 83 EJBModuleLoader(String modID, ClassLoader parentClassLoader, 84 EjbModulesManager ejbModulesManager) { 85 86 super(modID, parentClassLoader, ejbModulesManager); 87 boolean createClassLoader = true; 88 try { 89 application = ejbModulesManager.getRegisteredDescriptor(modID); 90 91 if (application == null) { 94 application= (Application) 95 ejbModulesManager.getDescriptor(modID, parentClassLoader); 96 createClassLoader = false; 97 } 98 else { 102 try { 103 ClassLoader clazzloader = application.getClassLoader(); 108 if (clazzloader != null 109 && (clazzloader instanceof EJBClassLoader) 110 && !((EJBClassLoader)clazzloader).isDone()) { 111 createClassLoader = false; 112 } 113 } catch (Exception ex) {} 114 } 115 116 if (createClassLoader) { 117 String [] classPath = (String []) 118 EJBClassPathUtils.getModuleClasspath( 119 modID, null, ejbModulesManager).toArray(new String [0]); 120 initializeLoader(classPath, ejbModulesManager.getLocation(modID), ModuleType.EJB); 121 application.setClassLoader(this.ejbClassLoader); 122 if (application.isVirtual()) { BundleDescriptor bd = 124 application.getStandaloneBundleDescriptor(); 125 bd.setClassLoader(ejbClassLoader); 126 } 127 } else { 128 initializeLoader(application.getClassLoader()); 129 } 130 } catch (Exception confEx) { 131 _logger.log(Level.SEVERE, "ERROR while loading application " + modID); 133 _logger.log(Level.SEVERE,"loader.error_while_loading_app_desc", 134 confEx); 135 } 136 } 137 138 145 boolean load(boolean jsr77) { 146 notifyAppEvent(ApplicationEvent.BEFORE_APPLICATION_LOAD); 148 boolean pusLoaded = false; 149 if(application.isVirtual()) { if(!loadPersistenceUnits()) { 153 return false; } else { 155 pusLoaded = true; 156 } 157 } 158 boolean status = loadEjbs(jsr77); 159 160 if (status == true) { 161 notifyAppEvent(ApplicationEvent.AFTER_APPLICATION_LOAD); 162 loadWebserviceEndpoints(jsr77); 163 } else { 164 if(pusLoaded) { unloadPersistenceUnits(); 166 } 167 } 168 169 return status; 170 } 171 172 178 boolean unload(boolean jsr77) { 179 181 notifyAppEvent(ApplicationEvent.BEFORE_APPLICATION_UNLOAD); 183 184 boolean result = unloadEjbs(jsr77); 185 unloadWebserviceEndpoints(jsr77); 186 187 if(application.isVirtual()) { result &= unloadPersistenceUnits(); 191 } 192 193 configManager.unregisterDescriptor(id); 194 195 notifyAppEvent(ApplicationEvent.AFTER_APPLICATION_UNLOAD); 196 197 done(); 199 return result; 200 } 201 202 203 206 void createRootMBean() throws MBeanException { 207 208 EjbDeploymentDescriptorFile eddf = null; 209 210 java.util.Set ejbBundles = this.application.getEjbBundleDescriptors(); 211 212 for(Iterator it=ejbBundles.iterator(); it.hasNext(); ) { 213 214 EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor)it.next(); 215 216 try { 217 Switch.getSwitch().getManagementObjectManager().createEJBModuleMBean( 218 bundleDesc, 219 this.configManager.getInstanceEnvironment().getName(), 220 this.configManager.getLocation(this.id)); 221 } catch (Exception e) { 222 throw new MBeanException (e); 223 } 224 } 225 } 226 227 228 231 void deleteRootMBean() throws MBeanException { 232 233 java.util.Set ejbBundles = this.application.getEjbBundleDescriptors(); 234 235 for(Iterator it=ejbBundles.iterator(); it.hasNext(); ) { 236 237 EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor)it.next(); 238 239 Switch.getSwitch().getManagementObjectManager().deleteEJBModuleMBean(bundleDesc, 240 this.configManager.getInstanceEnvironment().getName()); 241 } 242 } 243 244 245 248 void createLeafMBeans() throws MBeanException { 249 250 java.util.Set ejbBundles = this.application.getEjbBundleDescriptors(); 251 252 for(Iterator it=ejbBundles.iterator(); it.hasNext(); ) { 253 254 EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor)it.next(); 255 256 Switch.getSwitch().getManagementObjectManager().createEJBMBeans(bundleDesc, 257 this.configManager.getInstanceEnvironment().getName()); 258 } 259 } 260 261 262 265 void createLeafMBean(Descriptor descriptor) throws MBeanException { 266 267 EjbDescriptor ejbDescriptor = null; 268 try { 269 ejbDescriptor = (EjbDescriptor) descriptor; 270 } catch (Exception e) { 271 throw new MBeanException (e); 272 } 273 274 Switch.getSwitch().getManagementObjectManager().createEJBMBean(ejbDescriptor, 275 this.configManager.getInstanceEnvironment().getName()); 276 } 277 278 279 282 void deleteLeafMBeans() throws MBeanException { 283 284 java.util.Set ejbBundles = this.application.getEjbBundleDescriptors(); 285 286 for(Iterator it=ejbBundles.iterator(); it.hasNext(); ) { 287 288 EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor)it.next(); 289 290 Switch.getSwitch().getManagementObjectManager().deleteEJBMBeans(bundleDesc, 291 this.configManager.getInstanceEnvironment().getName()); 292 } 293 } 294 295 298 void deleteLeafMBean(Descriptor descriptor) throws MBeanException { 299 300 EjbDescriptor ejbDescriptor = null; 301 try { 302 ejbDescriptor = (EjbDescriptor) descriptor; 303 } catch (Exception e) { 304 throw new MBeanException (e); 305 } 306 Switch.getSwitch().getManagementObjectManager().deleteEJBMBean(ejbDescriptor, 307 this.configManager.getInstanceEnvironment().getName()); 308 } 309 310 311 314 void deleteLeafAndRootMBeans() throws MBeanException { 315 deleteLeafMBeans(); 316 deleteRootMBean(); 317 } 318 319 320 323 void setState(int state) throws MBeanException { 324 325 java.util.Set ejbBundles = this.application.getEjbBundleDescriptors(); 326 327 for(Iterator it=ejbBundles.iterator(); it.hasNext(); ) { 328 329 EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor)it.next(); 330 331 Switch.getSwitch().getManagementObjectManager().setEJBModuleState(state, bundleDesc, 332 this.configManager.getInstanceEnvironment().getName()); 333 } 334 } 335 336 } 337 | Popular Tags |