1 5 package ve.luz.ica.jackass.daemon; 6 7 import java.io.File ; 8 import java.io.FilenameFilter ; 9 import java.util.Properties ; 10 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 import org.omg.CORBA.UserException ; 14 import org.omg.PortableServer.POA ; 15 16 import ve.luz.ica.jackass.deploy.Deployer; 17 import ve.luz.ica.jackass.util.ConfigurationManager; 18 import ve.luz.ica.remoteio.FileUtil; 19 import ve.luz.ica.remoteio.RemoteFile; 20 21 26 public class InitialDeployer implements Runnable 27 { 28 private static final Log LOG = LogFactory.getLog(InitialDeployer.class); 29 30 private static final String TEMP_EXTENSION = ".tmp"; 31 private static final int TIME_OUT = 5000; 32 33 private Deployer deployer; 34 private POA poa; 35 36 42 public InitialDeployer(Deployer deployerRef, POA aPoa) 43 { 44 this.deployer = deployerRef; 45 this.poa = aPoa; 46 } 47 48 51 public void deployExistingApplications() 52 { 53 this.waitForInstantiators(); 54 55 Properties cf = ConfigurationManager.getConfigFile(); 56 String deploymentPath = cf.getProperty(ConfigurationManager.DEPLOYMENT_PATH_PROPERTY); 57 58 File file = new File (deploymentPath); 59 ZipFileFilter filter = new ZipFileFilter(); 60 String [] zipFiles = file.list(filter); 61 62 if (zipFiles == null) return; 63 64 for (int i = 0; i<zipFiles.length; ++i) 65 { 66 try 67 { 68 if (LOG.isDebugEnabled()) LOG.debug("Deploying " + zipFiles[i]); 69 File zipFile = new File (deploymentPath, zipFiles[i]); 70 File newZipFile = new File (deploymentPath, zipFiles[i]+TEMP_EXTENSION); 71 if (zipFile.renameTo(newZipFile)) 72 { 73 if (LOG.isDebugEnabled()) LOG.debug("Zip file remaned to " + newZipFile.getName()); 74 RemoteFile remoteFile = FileUtil.createRemoteFile(newZipFile.getPath(), poa); 75 deployer.deploy(remoteFile); 76 newZipFile.delete(); 77 } 78 } 79 catch (Exception e) 80 { 81 LOG.error(e); 82 } 83 } 84 } 85 86 90 private synchronized void waitForInstantiators() 91 { 92 try 93 { 94 wait(TIME_OUT); 95 } 96 catch (InterruptedException e) 97 { 98 e.printStackTrace(); 99 } 100 } 101 102 106 public void run() 107 { 108 this.deployExistingApplications(); 109 } 110 111 112 115 private static class ZipFileFilter implements FilenameFilter 116 { 117 private static final String ZIP_EXTENSION = ".zip"; 118 119 122 public boolean accept(File dir, String name) 123 { 124 return name.endsWith(ZIP_EXTENSION); 125 } 126 127 } 128 } 129 130 131 | Popular Tags |