FileDocCategorySizeDatePackage
AutoDeployedFilesManager.javaAPI DocGlassfish v2 API11306Sun May 13 15:19:38 BST 2007com.sun.enterprise.deployment.autodeploy

AutoDeployedFilesManager

public class AutoDeployedFilesManager extends Object
Contains the status of list of files that have been autodeployed.
author
Mahesh Rangamani

Fields Summary
private static final Logger
sLogger
static final String
STATUS_DIR_NAME
protected String
statDir
Constructors Summary
public AutoDeployedFilesManager()



      
    
protected AutoDeployedFilesManager(String s)

        statDir = s;
    
Methods Summary
protected static java.io.FileappToUndeployRequestFile(java.io.File f)

        File undeployRequest = new File(f.getPath() + AutoDeployConstants.UNDEPLOY_REQUESTED);
        return undeployRequest;
    
public voiddeleteDeployedFileInfo(java.io.File f)

      try {
        File statusFile = getStatusFile(f);
        statusFile.delete();
        deleteJbiDeployedFileInfo(f);
      } catch (Exception e) { throw e;}
    
private voiddeleteJbiDeployedFileInfo(java.io.File f)
Delete the JBI status file.

      try {
        JBIAutoDeployer jad = JBIAutoDeployer.getInstance();
        File statusFile = jad.getStatusFile(f, new File(statDir));
        if (statusFile != null)
            statusFile.delete();
      } catch (Exception e) { throw e;}
    
public java.io.File[]getFilesForDeployment(java.io.File[] latestFiles)
Compare the list of files with the current status info and determine the files that need to be deployed


        if (latestFiles == null) return new File[0];

        ArrayList<File> arrList = new ArrayList<File>();
        for (File deployDirFile : latestFiles) {
            File statusFile = getStatusFile(deployDirFile);
            if (!statusFile.exists() || deployDirFile.lastModified() != statusFile.lastModified()) {            
                arrList.add(deployDirFile);
            }
        }
        return arrList.toArray(new File[0]);
        
    
public java.io.File[]getFilesForUndeployment(java.io.File[] latestFiles)
Compare the list of files with the current status info and determine the apps that need to be undeployed.

        
        File statusDir = new File(statDir);  
        Set<File> statusFiles = 
                AutoDeployDirectoryScanner.getListOfFilesAsSet(statusDir, true);
        
        // The file might have been deleted. In that case, return null.
        if (statusFiles == null || statusFiles.isEmpty()){
            return null;
        }
        
        // now let's get the latestFiles status files names to remove them 
        // from the list of status files, any remaining ones will need to 
        // be undeployed
        for (File deployDirFile : latestFiles) {
            statusFiles.remove(getStatusFile(deployDirFile));
        }
        ArrayList<File> appNames = new ArrayList<File>();
        File autodeployDir = statusDir.getParentFile();        
        for(File statusDirFile : statusFiles) {
            
            // calculate the original file as it was copied in the autodeploy
            // directory
            File filePath = statusDir.getParentFile();
            File f = statusDirFile.getParentFile();
            while (!f.equals(statusDir)) {
                filePath = new File(filePath, f.getName());
                f = f.getParentFile();
            }
            filePath  = new File(filePath,  statusDirFile.getName());
            appNames.add(filePath);
        }
        
        // Add to the app names files any entries for which auto-undeployment
        // has been requested by the user's creation of xxx_undeploy_requested.
        appNames.addAll(getFilesToUndeployByRequest(latestFiles));
        return appNames.toArray(new File[0]);
    
private java.util.CollectiongetFilesToUndeployByRequest(java.io.File[] latestFiles)

        ArrayList<File> appsRequested = new ArrayList<File>();
        
        for (File f : latestFiles) {
            /*
             * See if there is a corresponding _undeployRequested file for this
             * file.
             */
            if (isUndeployRequested(f)) {
                appsRequested.add(new UndeployRequestedFile(f));
            }
        }
        if (sLogger.isLoggable(Level.FINE) && ! appsRequested.isEmpty()) {
            StringBuilder sb = new StringBuilder("Undeployment requested using *_undeployRequested for ");
            for (File app : appsRequested) {
                sb.append("  " + app.getName() + System.getProperty("line.separator"));
            }
            sLogger.fine(sb.toString());
        }
        return appsRequested;
    
private java.io.FilegetStatusFile(java.io.File f)

        File outDir = new File(this.statDir);
        outDir = obtainFileStatusDir(f, outDir, outDir.getParentFile());
        return new File(outDir, f.getName());
    
private static booleanisUndeployRequested(java.io.File f)

        return appToUndeployRequestFile(f).exists();
    
public static com.sun.enterprise.deployment.autodeploy.AutoDeployedFilesManagerloadStatus(java.io.File statusDir)
Create an instance from the persisted file in the specified directory.

param
statusDir Directory in which the status file is to read.

        return loadStatus(statusDir.getAbsolutePath());
    
public static com.sun.enterprise.deployment.autodeploy.AutoDeployedFilesManagerloadStatus(java.lang.String autoDeploymentDir)


        String statusDir = autoDeploymentDir + File.separator + STATUS_DIR_NAME;
        String sysAppDirPath = System.getProperty(Constants.INSTALL_ROOT) +
            File.separator + Constants.LIB + File.separator + 
            Constants.LIB_INSTALL + File.separator + 
            Constants.LIB_INSTALL_APPLICATIONS;

        File fileObj = new File(statusDir);
   
        // if the .autodeploystatus directory does not exist 
        // and this is not for auto deploying system applications
        // create the .autodeploystatus directory
        if (!fileObj.exists() && !autoDeploymentDir.equals(sysAppDirPath)) {
        	sLogger.log(Level.INFO, "autoDeployment status dir missing, creating a new one");
        	fileObj.mkdirs();
        }
        AutoDeployedFilesManager adfm = new AutoDeployedFilesManager(statusDir);
        return adfm;
        
    
static java.io.FileobtainFileStatusDir(java.io.File f, java.io.File statDir, java.io.File autoDeployDir)

        File dir = f.getParentFile();
        while (!dir.getAbsolutePath().equals(autoDeployDir.getAbsolutePath())) {
            statDir = new File(statDir, dir.getName()); 
            dir = dir.getParentFile();
        }
        statDir.mkdirs();
        return statDir;
    
public voidsetDeployedFileInfo(java.io.File f)
Update the status of the file as deployed.

      try {
        File statusFile = getStatusFile(f);
        statusFile.createNewFile();
        statusFile.setLastModified(f.lastModified());
        setJbiDeployedFileInfo(f);
      } catch (Exception e) { throw e; }
    
private voidsetJbiDeployedFileInfo(java.io.File f)
Create the JBI status file.

      try {
        JBIAutoDeployer jad = JBIAutoDeployer.getInstance();
        File statusFile = jad.getStatusFile(f, new File(statDir));
        if (statusFile != null)
            statusFile.createNewFile();
      } catch (Exception e) { throw e; }
    
public voidwriteStatus()

           // Nothing to do