FileDocCategorySizeDatePackage
AutoDeployControllerImpl.javaAPI DocGlassfish v2 API15904Fri May 04 22:34:30 BST 2007com.sun.enterprise.deployment.autodeploy

AutoDeployControllerImpl

public class AutoDeployControllerImpl extends Object implements com.sun.enterprise.config.ConfigContextEventListener, AutoDeployController
Main class for autodeploy service. It uses jdk timer class (java.util.Timer) as scheduler.
Presently its not implemented as MBean but later on, we can add the MBean behaviour easily.
Implements ConfigContextEventListener for handling config changes. Supports auto deployment, with
multiple source directories, using a single java.util.Timer and a single AutoDeployTask instance.
So there will be only one thread running for deployment, even when yoy have more than one input
source directory. It will complete deployment of all the modules/apps from one directory and then
moves on to next.
author
vikas

Fields Summary
private Vector
autodeployDirs
vector (of File objects) containing the list of source directories
private long
pollingInterval
private boolean
verify
private boolean
preJspCompilation
private Timer
timer
private AutoDeployTask
deployTask
public static final Logger
sLogger
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
public AutoDeployControllerImpl(String autodeployDir, long pollingInterval)

    
    
           
        try {
            addAutoDeployDir(autodeployDir);
            setPollingInterval(pollingInterval);
        } catch(AutoDeploymentException ae){
            sLogger.log(Level.SEVERE, "enterprise.deployment.backend.autoDeploymentStartFailure");
            throw ae;
        }
    
public AutoDeployControllerImpl(String[] autodeployDirs, long pollingInterval)

        try {
            for (int i=0;i<autodeployDirs.length;i++) {
                addAutoDeployDir(autodeployDirs[i]);
            }
            setPollingInterval(pollingInterval);
        } catch(AutoDeploymentException ae){
            sLogger.log(Level.SEVERE, "enterprise.deployment.backend.autoDeploymentStartFailure");
            throw ae;
        }
        
    
Methods Summary
public voidaddAutoDeployDir(java.lang.String autodeployDir)
add input source directory. to the list(Vector).

        if(!validateDir(autodeployDir)) {
           String msg = localStrings.getString("enterprise.deployment.autodeploy.invalid_source_dir",autodeployDir);
           sLogger.log(Level.INFO, msg);
        }        
        if((locateAlreadyExistingDir(autodeployDir)== -1)){ 
            autodeployDirs.add(new File(autodeployDir));
        } else {
        String msg = localStrings.getString("enterprise.deployment.autodeploy.duplicate_source_dir",autodeployDir);
        sLogger.log(Level.WARNING, msg);                
        //ignore, dir already exist
        }
        
    
public booleandisableAutoDeploy()
stop/disable autodeployment thread.

        if(deployTask!=null) {
            deployTask.cancel();
        }
        if(timer!=null) {
            timer.cancel();
        }
        String msg = localStrings.getString("enterprise.deployment.autodeploy.autoDeployment_service_disabled");
        sLogger.log(Level.INFO, msg);
        return true;
        
        
    
public booleanenableAutoDeploy()
start autodeployment.

        timer = new Timer();
        deployTask=new AutoDeployTask();
        timer.schedule(deployTask,0,pollingInterval*1000);
        String msg = localStrings.getString("enterprise.deployment.autodeploy.autoDeployment_service_enabled");
        sLogger.log(Level.FINE, msg+System.currentTimeMillis());
        return true;
        
    
public java.lang.String[]getAllAutoDeployDirs()
get all the input source directory.

        if(autodeployDirs != null && ! autodeployDirs.isEmpty()) {
            String[] dirs=new String[autodeployDirs.size()];
            int i=0;
            for (Enumeration list = autodeployDirs.elements() ; list.hasMoreElements() ;i++) {
                
                dirs[i]=((File)list.nextElement()).getAbsolutePath();
            }
            
            return dirs;
        }else {
            return null;
        }
        
    
public longgetPollingInterval()
get polling duration.

        return pollingInterval;
        
    
public booleanisPreJspCompilationEnabled()
is PreJspCompilation flag enabled or not. If enabled PreJspCompilation compilation ignored.

        return preJspCompilation;
    
public booleanisVerifyEnabled()
is verify flag enabled or not. If enabled verification happnes before
every deployment.

        return verify;
    
private intlocateAlreadyExistingDir(java.lang.String dir)

        //return -1 if the vector autoDeployDirs dont have this dir
        int location=-1;
        String extingDirs[]=getAllAutoDeployDirs();
        if(extingDirs!=null) {
            for (int i=0; i<extingDirs.length ; i++) {
                if(dir.equalsIgnoreCase(extingDirs[i])) {
                    location=i; //I got this dir in list
                    break;
                }
            }
            
        }
        return location;
    
public voidpostAccessNotification(com.sun.enterprise.config.ConfigContextEvent ccce)
Implement notification listner.
after config add, delete, set, update or flush. type is in ccce

        //not implemented
    
public voidpostChangeNotification(com.sun.enterprise.config.ConfigContextEvent ccce)
Implement notification listner.
after config add, delete, set, update or flush. type is in ccce

        //not implemented
    
public voidpreAccessNotification(com.sun.enterprise.config.ConfigContextEvent ccce)
Implement notification listner.
before config add, delete, set, update or flush. type is in ccce

        //not implemented
    
public voidpreChangeNotification(com.sun.enterprise.config.ConfigContextEvent ccce)
Implement notification listner.
before config add, delete, set, update or flush. type is in ccce

        //not implemented
    
public voidremoveAutoDeployDir(java.lang.String autodeployDir)
remove input source dir. from the list(Vector).

        int location=locateAlreadyExistingDir(autodeployDir);
        if(location>=0) {
            this.autodeployDirs.remove(location);
        }
    
public voidsetPollingInterval(long pollInterval)
set polling interval, polling interval can not be -ve. && more than

        
        if(validatePollingInterval(pollInterval)) {
            this.pollingInterval=pollInterval;
        } else{
            String sInterval= new String(""+pollInterval);
            String sMinInterval= new String(""+AutoDeployConstants.MIN_POOLING_INTERVAL);
            String msg = localStrings.getString("enterprise.deployment.autodeploy.invalid_pooling_interval", sInterval, sMinInterval);
            sLogger.log(Level.INFO, msg+pollInterval);
            throw new AutoDeploymentException(msg+pollInterval);
        }
    
public voidsetPreJspCompilation(boolean preJspCompilation)
set PreJspCompilation flag.

        this.preJspCompilation=preJspCompilation;
    
public voidsetVerify(boolean verify)
set verify flag.

        this.verify=verify;
    
private booleanvalidateDir(java.lang.String dir)

        boolean valid=false;
        File autodeployDir=new File(dir);
        if(autodeployDir != null && autodeployDir.exists()
                && autodeployDir.isDirectory()&& autodeployDir.canWrite() && 
                autodeployDir.canRead() /*&& (locateAlreadyExistingDir(dir)== -1)*/) {
            valid=true;
        }
        return valid;
        
    
private booleanvalidatePollingInterval(long time)

        boolean valid=false;
        
        if(time >= AutoDeployConstants.MIN_POOLING_INTERVAL) {
            valid= true;
        }
        return valid;