FileDocCategorySizeDatePackage
SystemAppLifecycle.javaAPI DocGlassfish v2 API10286Fri May 04 22:35:42 BST 2007com.sun.enterprise.server

SystemAppLifecycle

public final class SystemAppLifecycle extends ApplicationLifecycle
This class implements the lifecycle methods used by the System Apps.
author
Sandhya E

Fields Summary
Constructors Summary
Methods Summary
private voiddeploySystemApps()
Deploys all system apps under system directory to all server instances under in domain.xml. There are three categories in system apps, applicable to admin instance only, applicable to instances only, applicable to all.

        //FIXME: deploying system apps shoudl be done using J2EEC when it is available.
        try{
            String[] targets = getTargets();
            if(targets == null) return;
            int size = targets.length;
            for(int i = 0; i < size; i++) {
                deployToTarget(targets[i]);
            }
        }catch(Exception ex){
            _logger.log(Level.SEVERE,
                "core.exception_while_deploying_system_apps", ex);
        }
    
private voiddeployToTarget(java.lang.String target)
Deploys the system apps under system_app_dir to a specific target. Target here is a single server

param
target targetserver to which application should be deployed

        String sysAppDirPath = getSystemAppDirPath();
        _logger.log(Level.FINE,"core.deploying_system_apps", new Object[]{target, sysAppDirPath});
        com.sun.enterprise.deployment.autodeploy.AutoDeployer deployer =
           new com.sun.enterprise.deployment.autodeploy.AutoDeployer();
        deployer.setTarget(target);
        deployer.setDirectoryScanner(new SystemAppScanner(getTargetType(target)));
        deployer.disableRenameOnSuccess();
		
        File sysAppDir = new File(sysAppDirPath);
        try{
            if(sysAppDir.exists() && sysAppDir.canRead()) {
                deployer.deployAll(sysAppDir);
                _logger.log(Level.FINE,"core.deployed_system_apps",target);
            } else {
                _logger.log(Level.WARNING, "core.system_app_dir_not_found", new Object[] {sysAppDirPath});
            }
        }catch(AutoDeploymentException ade) {
            _logger.log(Level.SEVERE,
                "core.exception_while_deploying_system_apps", ade);
        }
    
private java.lang.StringgetSystemAppDirPath()

        String sysAppDirPath = System.getProperty(Constants.INSTALL_ROOT) + File.separator 
            + Constants.LIB + File.separator + Constants.LIB_INSTALL + File.separator + Constants.LIB_INSTALL_APPLICATIONS;
        return sysAppDirPath;
    
private java.lang.StringgetTargetType(java.lang.String targetName)


	/*
        if(targetName.equalsIgnoreCase(ServerManager.ADMINSERVER_ID))
            return Constants.TARGET_TYPE_ADMIN;
        else
            return Constants.TARGET_TYPE_INSTANCE;
	*/

	/**
	 * commented the above code since it doesn't return the 
	 * target type properly. In case of DAS since the instance name is
	 * server it returns the type as instance
	 *
	 * Following code uses the isDAS of ServerHelper to determine
	 * if the target type is admin or not
	 */

        try{
	    if (ServerHelper.isDAS(_context.getConfigContext(), targetName)) {
            	return Constants.TARGET_TYPE_ADMIN;
	    } else {
            	return Constants.TARGET_TYPE_INSTANCE;
	    }
        }catch(Exception ex){
            _logger.log(Level.SEVERE, "core.exception_while_getting_targetType", ex);
        }

	return null;
    
private java.lang.String[]getTargets()

        try{
            ConfigContext confContext = _context.getConfigContext();
            Domain domain = (Domain)confContext.getRootConfigBean();
            Servers svrs = domain.getServers();
            Server[] svrArr = svrs.getServer();
            int size = svrArr.length;
            String[] targetNames = new String[size];
            for(int i = 0 ; i< size; i++) {
               targetNames[i] = svrArr[i].getName(); 
            }
            return targetNames;
        }catch(Exception ex){
            _logger.log(Level.SEVERE,
                "core.exception_while_getting_targets", ex);
            return null;
        }
    
private voidloadSystemApps()
Loads all the deployed system applications.

        _logger.log(Level.FINE, "core.loading_system_apps");
        // loads all deployed connector modules
        this._connMgr.loadSystem();

        // loads all deployed stand alone ejb modules
        this._ejbMgr.loadSystem();

        // loads all deployed j2ee applications
        this._applicationMgr.loadSystem();
    
public voidonReady(com.sun.enterprise.server.ServerContext sc)
Server has complted loading the system applications

param
sc ServerContext the server runtime context.
exception
ServerLifecycleException if this subsystem detects a fatal error that prevents this subsystem from being used

        // not required to notify listeners(ejb containers) as this will be done by ALC    
    
public voidonShutdown()
Server is shutting down applications

exception
ServerLifecycleException if this subsystem detects a fatal error that prevents this subsystem from being used

        //not required
    
public voidonStartup(com.sun.enterprise.server.ServerContext sc)
Server is starting up applications

param
sc ServerContext the server runtime context.
exception
ServerLifecycleException if this subsystem detects a fatal error that prevents this subsystem from being used


        try {
            //deploys any new system apps
            deploySystemApps();

            loadSystemApps();
        } catch (Throwable th) {
            _logger.log(Level.SEVERE, 
                "core.unexpected_error_occured_while_app_loading", th);
        }
    
public voidonTermination()
Server is terminating the subsystems and the runtime environment. Gracefully terminate the active use of the public methods of this subsystem. This method should be the last one called on a given instance of this subsystem.

exception
ServerLifecycleException if this subsystem detects a fatal error that prevents this subsystem from being used

        //not required
    
public voidstartup(com.sun.enterprise.server.ServerContext sc)
Right now this lifecycle is not registered as a lifecycle. This method will be explicitly called from J2EE Server. This method will call two lifecycle methods: onInit and onStartup. OnShutdown and onTermination need not be called as the required task will be done ALC for now. This is a mockup startup method which will take care of lifecycle methods till onStartup

        onInitialization(sc);        
        onStartup(sc);