1 23 24 29 30 package com.sun.enterprise.web; 31 32 import java.util.Hashtable ; 33 34 import java.util.logging.Logger ; 35 import java.util.logging.Level ; 36 import java.util.ResourceBundle ; 37 38 import com.sun.logging.LogDomains; 39 40 import com.sun.enterprise.admin.event.ApplicationDeployEvent; 41 import com.sun.enterprise.admin.event.ModuleDeployEvent; 42 43 47 public class EEWebContainerAdminEventProcessor implements WebContainerAdminEventProcessor { 48 49 52 protected static Logger _logger = null; 53 54 57 protected static ResourceBundle _rb = null; 58 59 62 protected EmbeddedWebContainer _embedded = null; 63 64 68 private static Hashtable _deployHistory = new Hashtable (); 69 70 71 public EEWebContainerAdminEventProcessor() { 72 if (_logger == null) { 73 _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER); 74 _rb = _logger.getResourceBundle(); 75 } 76 } 77 78 79 public EEWebContainerAdminEventProcessor(EmbeddedWebContainer embedded) { 80 _embedded = embedded; 81 if (_logger == null) { 82 _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER); 83 _rb = _logger.getResourceBundle(); 84 } 85 } 86 87 public void init(EmbeddedWebContainer embedded) { 88 _embedded = embedded; 89 } 90 91 public void applicationDeployed(ApplicationDeployEvent deployEvent) { 92 String deployedAppName = deployEvent.getApplicationName(); 93 _logger.finest("applicationDeployed:" + deployedAppName); 94 String key = "App_" + deployedAppName; 95 96 boolean deployedRecently = checkDeployHistoryEntry(key, "deployed"); 97 setDeployHistoryEntry(key, "deployed", System.currentTimeMillis()); 98 if (deployedRecently) { 99 _logger.finest("Returning from MIDDLE of applicationDeployed"); 100 return; 101 } 102 103 SessionPurgeUtil purgeUtil = new SessionPurgeUtil(_embedded); 104 _logger.finest("about to call SessionPurgeUtil for" + deployedAppName); 105 deployedAppName = "/" + deployedAppName; 106 112 System.gc(); 113 _logger.finest("Returning from END of applicationDeployed"); 116 } 117 118 public void applicationDisabled(ApplicationDeployEvent deployEvent) { 119 } 120 121 public void applicationEnabled(ApplicationDeployEvent deployEvent) { 122 } 123 124 public void applicationRedeployed(ApplicationDeployEvent deployEvent) { 125 String deployedAppName = deployEvent.getApplicationName(); 126 _logger.finest("applicationRedeployed:" + deployedAppName); 127 128 String key = "App_" + deployedAppName; 129 boolean redeployedRecently = checkDeployHistoryEntry(key, "redeployed"); 130 setDeployHistoryEntry(key, "redeployed", System.currentTimeMillis()); 131 if (redeployedRecently) { 132 _logger.finest("Returning from MIDDLE of applicationRedeployed"); 133 return; 134 } 135 136 SessionPurgeUtil purgeUtil = new SessionPurgeUtil(_embedded); 137 _logger.finest("about to call SessionPurgeUtil for" + deployedAppName); 138 deployedAppName = "/" + deployedAppName; 139 purgeUtil.purgeSessionsForApp(deployedAppName); 140 146 System.gc(); 147 _logger.finest("Returning from END of applicationRedeployed"); 150 } 151 152 public void applicationUndeployed(ApplicationDeployEvent deployEvent) { 153 String deployedAppName = deployEvent.getApplicationName(); 154 _logger.finest("applicationUndeployed:" + deployedAppName); 155 156 String key = "App_" + deployedAppName; 157 boolean undeployedRecently = checkDeployHistoryEntry(key, "undeployed"); 158 setDeployHistoryEntry(key, "undeployed", System.currentTimeMillis()); 159 if (undeployedRecently) { 160 _logger.finest("Returning from MIDDLE of applicationUndeployed"); 161 return; 162 } 163 164 SessionPurgeUtil purgeUtil = new SessionPurgeUtil(_embedded); 165 _logger.finest("about to call SessionPurgeUtil for" + deployedAppName); 166 deployedAppName = "/" + deployedAppName; 167 purgeUtil.purgeSessionsForApp(deployedAppName); 168 174 System.gc(); 175 } 178 179 public void moduleDeployed(ModuleDeployEvent deployEvent) { 180 String deployedModuleName = deployEvent.getModuleName(); 181 _logger.finest("moduleDeployed:" + deployedModuleName); 182 183 String key = "Mod_" + deployedModuleName; 184 boolean deployedRecently = checkDeployHistoryEntry(key, "deployed"); 185 setDeployHistoryEntry(key, "deployed", System.currentTimeMillis()); 186 if (deployedRecently) { 187 _logger.finest("Returning from MIDDLE of moduleDeployed"); 188 return; 189 } 190 191 ConnectionShutdownUtil shutdownUtil = new ConnectionShutdownUtil(_embedded); 192 shutdownUtil.runCloseAllConnections(); 193 System.gc(); 194 _logger.finest("Returning from END of moduleDeployed"); 197 } 198 199 public void moduleDisabled(ModuleDeployEvent deployEvent) { 200 } 201 202 public void moduleEnabled(ModuleDeployEvent deployEvent) { 203 } 204 205 public void moduleRedeployed(ModuleDeployEvent deployEvent) { 206 String deployedModuleName = deployEvent.getModuleName(); 207 _logger.finest("moduleRedeployed:" + deployedModuleName); 208 209 String key = "Mod_" + deployedModuleName; 210 boolean redeployedRecently = checkDeployHistoryEntry(key, "redeployed"); 211 setDeployHistoryEntry(key, "redeployed", System.currentTimeMillis()); 212 if (redeployedRecently) { 213 _logger.finest("Returning from MIDDLE of moduleRedeployed"); 214 return; 215 } 216 217 ConnectionShutdownUtil shutdownUtil = new ConnectionShutdownUtil(_embedded); 218 shutdownUtil.runCloseAllConnections(); 219 System.gc(); 220 _logger.finest("Returning from END of moduleRedeployed"); 223 } 224 225 public void moduleUndeployed(ModuleDeployEvent deployEvent) { 226 String deployedModuleName = deployEvent.getModuleName(); 227 _logger.finest("moduleUndeployed:" + deployedModuleName); 228 229 String key = "Mod_" + deployedModuleName; 230 boolean undeployedRecently = checkDeployHistoryEntry(key, "undeployed"); 231 setDeployHistoryEntry(key, "undeployed", System.currentTimeMillis()); 232 if (undeployedRecently) { 233 _logger.finest("Returning from MIDDLE of moduleUndeployed"); 234 return; 235 } 236 237 ConnectionShutdownUtil shutdownUtil = new ConnectionShutdownUtil(_embedded); 238 System.out.println("IN WebContainer>>moduleUndeployed: " 239 + deployedModuleName + "about to close all connections"); 240 shutdownUtil.runCloseAllConnections(); 241 System.gc(); 242 _logger.finest("Returning from END of moduleUndeployed"); 245 } 246 247 255 private void setDeployHistoryEntry(String key, String value, long lat) { 256 DeployHistoryEntry entry = (DeployHistoryEntry) _deployHistory.get(key); if (entry == null) 257 _deployHistory.put(key, new DeployHistoryEntry(value, lat)); 258 else { 259 entry.value = value; 260 entry.lat = lat; 261 } 262 } 263 264 273 private boolean checkDeployHistoryEntry(String key, String deployStatus) { 274 DeployHistoryEntry entry = (DeployHistoryEntry) _deployHistory.get(key); 275 if (entry == null) { 276 return false; 277 } 278 String val = entry.value; 279 if (val.equals(deployStatus)) { 280 283 if (( System.currentTimeMillis() - entry.lat ) < 60000) { 284 return true; 285 } 286 } 287 return false; 288 } 289 290 } 291 292 296 class DeployHistoryEntry { 297 String value; 298 long lat; 299 300 DeployHistoryEntry(String value, long lat) { 301 this.value = value; 302 this.lat = lat; 303 } 304 } 305 | Popular Tags |