1 23 24 37 package com.sun.enterprise.server; 38 39 import java.io.File ; 40 import java.util.Iterator ; 41 import com.sun.enterprise.util.io.FileUtils; 42 43 import java.util.logging.Level ; 44 import java.util.logging.Logger ; 45 import com.sun.logging.LogDomains; 46 47 53 class AutoDeployMonitor extends AbstractMonitor { 54 55 56 static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER); 57 58 59 private static AutoDeployMonitor _instance = null; 60 61 62 private static ArchiveFilter _archiveFilter = null; 63 64 65 private static final String SUCCESS_EXT = ".deployed"; 66 67 68 private static final String ERROR_EXT = ".notdeployed"; 69 70 75 private AutoDeployMonitor(long pollInterval) { 76 super(pollInterval); 77 } 78 79 85 static AutoDeployMonitor getInstance(long pollInterval) { 86 if (_instance == null) { 87 _instance = new AutoDeployMonitor(pollInterval); 88 _archiveFilter = new ArchiveFilter(); 89 } 90 return _instance; 91 } 92 93 106 public void run() { 107 108 try { 109 synchronized (_monitoredEntries) { 110 Iterator iter = _monitoredEntries.iterator(); 111 MonitorableEntry entry = null; 112 113 while (iter.hasNext()) { 115 entry = (MonitorableEntry) iter.next(); 116 File autoDeployDir = entry.getMonitoredFile(); 117 118 File [] archives = autoDeployDir.listFiles(_archiveFilter); 119 120 if ( (archives == null) || (archives.length == 0) ) { 121 return; 123 } 124 125 MonitorListener l = entry.getListener(); 126 127 for (int i=0; i<archives.length; i++) { 128 129 _logger.log(Level.FINE, 130 "[AutoDeployMonitor] Found " + archives[i]); 131 132 boolean success = l.deploy(entry, archives[i]); 133 if (success) { 134 File successExt = 135 new File (archives[i].getParentFile(), 136 archives[i].getName()+SUCCESS_EXT); 137 archives[i].renameTo(successExt); 138 } else { 139 File errorExt = 140 new File (archives[i].getParentFile(), 141 archives[i].getName()+ERROR_EXT); 142 archives[i].renameTo(errorExt); 143 } 144 } 145 } 146 } 147 } catch (Throwable t) { 148 _logger.log(Level.WARNING, "core.exception", t); 150 } 151 } 152 153 156 private static class ArchiveFilter implements java.io.FileFilter { 157 158 164 public boolean accept(File pathname) { 165 166 if ( FileUtils.isEar(pathname) 167 || FileUtils.isJar(pathname) 168 || FileUtils.isWar(pathname) 169 || FileUtils.isRar(pathname) ) { 170 return true; 171 } else { 172 return false; 173 } 174 } 175 } 176 } 177 | Popular Tags |