1 23 24 37 package com.sun.enterprise.server; 38 39 import java.io.File ; 40 41 import com.sun.enterprise.Switch; 42 43 import com.sun.enterprise.config.serverbeans.Domain; 44 import com.sun.enterprise.config.serverbeans.Servers; 45 import com.sun.enterprise.config.serverbeans.Server; 46 import com.sun.enterprise.config.serverbeans.ServerHelper; 47 import com.sun.enterprise.config.ConfigContext; 48 49 import com.sun.enterprise.deployment.autodeploy.AutoDeployer; 50 import com.sun.enterprise.deployment.autodeploy.AutoDeploymentException; 51 52 import java.util.logging.Level ; 53 import java.util.logging.Logger ; 54 import com.sun.logging.LogDomains; 55 56 import com.sun.enterprise.server.ondemand.OnDemandServer; 57 import com.sun.enterprise.server.ServerContext; 58 import com.sun.appserv.server.ServerLifecycleException; 59 import com.sun.enterprise.instance.ServerManager; 60 61 66 public final class SystemAppLifecycle extends ApplicationLifecycle { 67 68 76 public void startup(ServerContext sc) throws ServerLifecycleException { 77 onInitialization(sc); 78 onStartup(sc); 79 } 80 81 89 public void onStartup(ServerContext sc) throws ServerLifecycleException { 90 91 try { 92 deploySystemApps(); 94 95 if (OnDemandServer.isOnDemandOff()) { 98 loadSystemApps(); 99 } 100 } catch (Throwable th) { 101 _logger.log(Level.SEVERE, 102 "core.unexpected_error_occured_while_app_loading", th); 103 } 104 } 105 106 114 public void onReady(ServerContext sc) throws ServerLifecycleException { 115 } 117 118 124 public void onShutdown() throws ServerLifecycleException { 125 } 127 128 137 public void onTermination() throws ServerLifecycleException { 138 } 140 141 144 private void loadSystemApps() { 145 _logger.log(Level.FINE, "core.loading_system_apps"); 146 this._connMgr.loadSystem(); 148 149 this._ejbMgr.loadSystem(); 151 152 this._applicationMgr.loadSystem(); 154 } 155 private String getSystemAppDirPath(){ 156 String sysAppDirPath = System.getProperty(Constants.INSTALL_ROOT) + File.separator 157 + Constants.LIB + File.separator + Constants.LIB_INSTALL + File.separator + Constants.LIB_INSTALL_APPLICATIONS; 158 return sysAppDirPath; 159 } 160 161 168 private void deploySystemApps(){ 169 try{ 171 String [] targets = getTargets(); 172 if(targets == null) return; 173 int size = targets.length; 174 for(int i = 0; i < size; i++) { 175 deployToTarget(targets[i]); 176 } 177 }catch(Exception ex){ 178 _logger.log(Level.SEVERE, 179 "core.exception_while_deploying_system_apps", ex); 180 } 181 } 182 183 188 private void deployToTarget(String target) { 189 String sysAppDirPath = getSystemAppDirPath(); 190 _logger.log(Level.FINE,"core.deploying_system_apps", new Object []{target, sysAppDirPath}); 191 com.sun.enterprise.deployment.autodeploy.AutoDeployer deployer = 192 new com.sun.enterprise.deployment.autodeploy.AutoDeployer(); 193 deployer.setTarget(target); 194 deployer.setDirectoryScanner(new SystemAppScanner(getTargetType(target))); 195 deployer.disableRenameOnSuccess(); 196 197 File sysAppDir = new File (sysAppDirPath); 198 try{ 199 if(sysAppDir.exists() && sysAppDir.canRead()) { 200 deployer.deployAll(sysAppDir); 201 _logger.log(Level.FINE,"core.deployed_system_apps",target); 202 } else { 203 _logger.log(Level.WARNING, "core.system_app_dir_not_found", new Object [] {sysAppDirPath}); 204 } 205 }catch(AutoDeploymentException ade) { 206 _logger.log(Level.SEVERE, 207 "core.exception_while_deploying_system_apps", ade); 208 } 209 } 210 211 private String [] getTargets(){ 212 try{ 213 ConfigContext confContext = _context.getConfigContext(); 214 Domain domain = (Domain)confContext.getRootConfigBean(); 215 Servers svrs = domain.getServers(); 216 Server[] svrArr = svrs.getServer(); 217 int size = svrArr.length; 218 String [] targetNames = new String [size]; 219 for(int i = 0 ; i< size; i++) { 220 targetNames[i] = svrArr[i].getName(); 221 } 222 return targetNames; 223 }catch(Exception ex){ 224 _logger.log(Level.SEVERE, 225 "core.exception_while_getting_targets", ex); 226 return null; 227 } 228 } 229 230 private String getTargetType(String targetName){ 231 232 238 239 247 248 try{ 249 if (ServerHelper.isDAS(_context.getConfigContext(), targetName)) { 250 return Constants.TARGET_TYPE_ADMIN; 251 } else { 252 return Constants.TARGET_TYPE_INSTANCE; 253 } 254 }catch(Exception ex){ 255 _logger.log(Level.SEVERE, "core.exception_while_getting_targetType", ex); 256 } 257 258 return null; 259 } 260 261 } 262 | Popular Tags |