1 23 24 37 package com.sun.enterprise.server; 38 39 import java.io.File ; 40 import java.io.IOException ; 41 import java.net.URL ; 42 import java.util.ArrayList ; 43 import java.util.Set ; 44 import java.util.List ; 45 import java.util.Iterator ; 46 import com.sun.enterprise.Switch; 47 import com.sun.enterprise.loader.EJBClassPathUtils; 48 import com.sun.enterprise.instance.AppsManager; 49 import com.sun.enterprise.config.ConfigException; 50 import java.util.jar.Attributes ; 51 import java.util.jar.JarFile ; 52 import java.util.jar.Manifest ; 53 import java.util.logging.Logger ; 54 import java.util.logging.Level ; 55 import com.sun.logging.LogDomains; 56 import com.sun.enterprise.loader.EJBClassLoader; 57 import javax.management.MBeanException ; 58 import javax.enterprise.deploy.shared.ModuleType ; 59 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 60 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 61 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 62 import com.sun.enterprise.deployment.*; 63 import com.sun.enterprise.deployment.util.ModuleDescriptor; 64 65 import com.sun.enterprise.server.event.ApplicationEvent; 66 67 74 public class ApplicationLoader extends AbstractLoader { 75 76 77 static Logger _logger = LogDomains.getLogger(LogDomains.LOADER_LOGGER); 78 79 80 private boolean isForceDeploy = false; 81 82 89 public ApplicationLoader(String appID, ClassLoader parentClassLoader, 90 AppsManager appsManager) { 91 92 super(appID, parentClassLoader, appsManager); 93 boolean createClassLoader = true; 94 try { 95 application = appsManager.getRegisteredDescriptor(appID); 96 boolean finishLoading = application==null; 99 100 if (application==null) { 103 application = appsManager.getAppDescriptor(appID, parentClassLoader); 104 createClassLoader = false; 105 } 106 else { 110 try { 111 ClassLoader clazzloader = application.getClassLoader(); 116 if (clazzloader != null 117 && (clazzloader instanceof EJBClassLoader) 118 && !((EJBClassLoader)clazzloader).isDone()) { 119 createClassLoader = false; 120 } 121 } catch (Exception ex) {} 122 } 123 124 if (createClassLoader) { 125 String [] classPath = (String []) 126 EJBClassPathUtils.getAppClasspath(application, appsManager).toArray(new String [0]); 127 128 initializeLoader(classPath, appsManager.getLocation(application.getRegistrationName()), 129 ModuleType.EAR); 130 application.setClassLoader(this.ejbClassLoader); 131 } else { 132 initializeLoader(application.getClassLoader()); 133 } 134 135 if (finishLoading) { 137 application = appsManager.getAppDescriptor(application); 138 } 139 initializeRegistry(); 140 } catch (Exception confEx) { 141 _logger.log(Level.SEVERE, "ERROR while loading application " + appID); 143 _logger.log(Level.SEVERE,"loader.error_while_loading_app_desc", 144 confEx); 145 } 146 } 147 148 155 boolean load(boolean jsr77) { 156 boolean allModulesDeployed = false; 157 158 165 if (loadUnloadAction == Constants.LOAD_UNSET) { 167 loadUnloadAction = Constants.LOAD_ALL; 168 } 169 170 if (loadUnloadAction == Constants.LOAD_ALL || 171 loadUnloadAction == Constants.LOAD_RAR) { 172 notifyAppEvent(ApplicationEvent.BEFORE_APPLICATION_LOAD); 173 allModulesDeployed = loadRars(jsr77); 174 if (loadUnloadAction == Constants.LOAD_RAR) { 175 return allModulesDeployed; 176 } 177 } 178 179 allModulesDeployed = loadPersistenceUnits(); 181 if(!allModulesDeployed) return false; 182 183 if (allModulesDeployed) { 184 allModulesDeployed = loadEjbs(jsr77); 185 notifyAppEvent(ApplicationEvent.AFTER_APPLICATION_LOAD); 186 } 187 if (!allModulesDeployed) { 188 unloadPersistenceUnits(); 190 return allModulesDeployed; 191 } 192 loadWebserviceEndpoints(jsr77); 193 194 198 return allModulesDeployed; 199 } 200 201 202 208 boolean unload(boolean jsr77) { 209 210 217 if (loadUnloadAction == Constants.LOAD_UNSET) { 219 loadUnloadAction = Constants.UNLOAD_ALL; 220 } 221 222 boolean wsUnloaded = false; 223 boolean ejbUnloaded = false; 224 boolean pusUnloaded = false; 225 226 if (loadUnloadAction == Constants.UNLOAD_ALL || 227 loadUnloadAction == Constants.UNLOAD_REST) { 228 notifyAppEvent(ApplicationEvent.BEFORE_APPLICATION_UNLOAD); 229 wsUnloaded = unloadWebserviceEndpoints(jsr77); 230 231 ejbUnloaded = unloadEjbs(jsr77); 233 234 237 pusUnloaded = unloadPersistenceUnits(); 239 240 if (loadUnloadAction == Constants.UNLOAD_REST) { 241 if (wsUnloaded && ejbUnloaded && pusUnloaded) { 243 return true; 244 } else { 245 return false; 246 } 247 } 248 } 249 250 boolean rarUnloaded = unloadRars(jsr77); 253 255 configManager.unregisterDescriptor(id); 256 257 notifyAppEvent(ApplicationEvent.AFTER_APPLICATION_UNLOAD); 258 259 done(); 261 262 if (loadUnloadAction == Constants.UNLOAD_RAR) { 263 return rarUnloaded; 264 } else { 265 return (wsUnloaded && ejbUnloaded && pusUnloaded && rarUnloaded); 266 } 267 } 268 269 272 void createRootMBean() throws MBeanException { 273 274 try { 275 276 Switch.getSwitch().getManagementObjectManager().createAppMBean( 277 this.application, 278 this.configManager.getInstanceEnvironment().getName(), 279 this.configManager.getLocation(this.id)); 280 281 Switch.getSwitch().getManagementObjectManager().createAppMBeanModules( 282 this.application, 283 this.configManager.getInstanceEnvironment().getName(), 284 this.configManager.getLocation(this.id)); 285 286 } catch (Exception e) { 287 throw new MBeanException (e); 288 } 289 } 290 291 294 void deleteRootMBean() throws MBeanException { 295 Switch.getSwitch().getManagementObjectManager().deleteAppMBean(this.application, 296 this.configManager.getInstanceEnvironment().getName()); 297 } 298 299 300 303 void createLeafMBeans() throws MBeanException { 304 try { 305 Switch.getSwitch().getManagementObjectManager().createAppMBeans( 306 this.application, 307 this.configManager.getInstanceEnvironment().getName(), 308 this.configManager.getLocation(this.id)); 309 } catch (Exception e) { 310 throw new MBeanException (e); 311 } 312 } 313 314 318 void createLeafMBean(Descriptor descriptor) throws MBeanException { 319 if (descriptor instanceof EjbDescriptor) { 320 EjbDescriptor ejbDescriptor = null; 321 try { 322 ejbDescriptor = (EjbDescriptor) descriptor; 323 } catch (Exception e) { 324 throw new MBeanException (e); 325 } 326 Switch.getSwitch().getManagementObjectManager().createEJBMBean(ejbDescriptor, 327 this.configManager.getInstanceEnvironment().getName()); 328 } else if (descriptor instanceof ConnectorDescriptor) { 329 ConnectorDescriptor cd = null; 330 try { 331 cd = (ConnectorDescriptor) descriptor; 332 } catch (Exception e) { 333 throw new MBeanException (e); 334 } 335 Switch.getSwitch().getManagementObjectManager().createRARMBean(cd, 336 this.configManager.getInstanceEnvironment().getName()); 337 } 338 } 339 340 344 void deleteLeafMBean(Descriptor descriptor) throws MBeanException { 345 if (descriptor instanceof EjbDescriptor) { 346 EjbDescriptor ejbDescriptor = null; 347 try { 348 ejbDescriptor = (EjbDescriptor) descriptor; 349 } catch (Exception e) { 350 throw new MBeanException (e); 351 } 352 Switch.getSwitch().getManagementObjectManager().deleteEJBMBean(ejbDescriptor, 353 this.configManager.getInstanceEnvironment().getName()); 354 } else if (descriptor instanceof ConnectorDescriptor) { 355 ConnectorDescriptor cd = null; 356 try { 357 cd = (ConnectorDescriptor) descriptor; 358 } catch (Exception e) { 359 throw new MBeanException (e); 360 } 361 Switch.getSwitch().getManagementObjectManager().deleteRARMBean(cd, 362 this.configManager.getInstanceEnvironment().getName()); 363 } 364 } 365 366 369 void deleteLeafMBeans() throws MBeanException { 370 Switch.getSwitch().getManagementObjectManager().deleteAppMBeans(this.application, 371 this.configManager.getInstanceEnvironment().getName()); 372 } 373 374 377 void deleteLeafAndRootMBeans() throws MBeanException { 378 deleteLeafMBeans(); 379 deleteRootMBean(); 380 } 381 382 383 386 void setState(int state) throws MBeanException { 387 if (application == null) { 388 _logger.log(Level.FINE, 394 "Application descriptor is NULL. setState skipped"); 395 } else { 396 Switch.getSwitch().getManagementObjectManager().setApplicationState( 397 state, application, 398 configManager.getInstanceEnvironment().getName()); 399 } 400 } 401 402 public boolean isForceDeploy(){ 403 return this.isForceDeploy; 404 } 405 406 public void setForceDeploy(boolean isForceDeploy) { 407 this.isForceDeploy = isForceDeploy; 408 } 409 } 410 | Popular Tags |