1 23 24 29 30 package com.sun.enterprise.web; 31 32 import java.util.logging.*; 33 import com.sun.logging.*; 34 import java.util.Hashtable ; 35 import java.util.Enumeration ; 36 import java.util.ArrayList ; 37 import org.apache.catalina.Context; 38 import org.apache.catalina.Container; 39 import org.apache.catalina.Engine; 40 import org.apache.catalina.Manager; 41 import org.apache.catalina.core.StandardContext; 42 import org.apache.catalina.session.SessionPurgeCapable; 43 import java.sql.Connection ; 44 45 46 50 public class SessionPurgeUtil { 51 52 55 protected EmbeddedWebContainer _embedded = null; 56 private WebContainer webContainer = null; 57 private static Logger _logger; 58 static 59 { 60 _logger=LogDomains.getLogger(LogDomains.WEB_LOGGER); 61 } 62 63 64 public SessionPurgeUtil() { 65 } 66 67 68 69 74 75 76 public SessionPurgeUtil(EmbeddedWebContainer embedded) { 77 _embedded = embedded; 78 } 79 80 public String getApplicationId(Context ctx) { 81 com.sun.enterprise.web.WebModule wm = 82 (com.sun.enterprise.web.WebModule)ctx; 83 return wm.getID(); 84 } 85 86 public String getApplicationName(Context ctx) { 87 return ctx.getName(); 88 } 89 90 public String getJ2EEApplicationName(Context ctx) { 91 return ((StandardContext)ctx).getJ2EEApplication(); 92 } 93 94 public void purgeSessionsForContext(Context ctx) { 95 Manager mgr = ctx.getManager(); 96 _logger.finest("SessionPurgeUtil: mgr = " + mgr); 97 _logger.finest("SessionPurgeUtil: mgr SessionPurgeCapable: " + (mgr instanceof SessionPurgeCapable)); 98 if(mgr instanceof SessionPurgeCapable) { 99 ((SessionPurgeCapable)mgr).clearSessions(); 100 ((SessionPurgeCapable)mgr).clearStore(); 101 } 102 } 103 104 public void purgeSessionsForApp(String appName) { 105 _logger.finest("IN SessionPurgeUtil:purgeSessionsForApp" + appName); 106 try { 107 Engine[] engines = _embedded.getEngines(); 108 109 for(int h=0; h<engines.length; h++) { 110 Container engine = (Container) engines[h]; 111 Container[] hosts = engine.findChildren(); 112 for(int i=0; i<hosts.length; i++) { 113 Container nextHost = hosts[i]; 114 Container [] webModules = nextHost.findChildren(); 115 for (int j=0; j<webModules.length; j++) { 116 Container nextWebModule = webModules[j]; 117 Context ctx = (Context)nextWebModule; 118 String webAppName = this.getApplicationName(ctx); 121 Manager nextManager = nextWebModule.getManager(); 122 _logger.finest("webAppName = " + webAppName + ", appName = " + appName); 123 if(webAppName.equals(appName)) { 124 _logger.finest("found our manager:" + nextManager.getClass().getName()); 125 132 if(nextManager instanceof SessionPurgeCapable) { 133 ((SessionPurgeCapable)nextManager).clearSessions(); 134 ((SessionPurgeCapable)nextManager).clearStore(); 135 } 136 } 137 } 138 } 139 } 140 } catch (Throwable th) { 141 _logger.log(Level.SEVERE, "Exception thrown", th); 142 } 143 144 } 145 146 public void closeCachedConnectionForApp(String appName) { 147 _logger.finest("IN SessionPurgeUtil:closeCachedConnectionForApp" + appName); 148 149 try { 150 Engine[] engines = _embedded.getEngines(); 151 152 for(int h=0; h<engines.length; h++) { 153 Container engine = (Container) engines[h]; 154 Container[] hosts = engine.findChildren(); 155 for(int i=0; i<hosts.length; i++) { 156 Container nextHost = hosts[i]; 157 Container [] webModules = nextHost.findChildren(); 158 for (int j=0; j<webModules.length; j++) { 159 Container nextWebModule = webModules[j]; 160 Context ctx = (Context)nextWebModule; 161 String webAppName = this.getApplicationName(ctx); 164 Manager nextManager = nextWebModule.getManager(); 165 _logger.finest("webAppName = " + webAppName + ", appName = " + appName); 166 if(webAppName.equals(appName)) { 167 _logger.finest("found our manager:" + nextManager.getClass().getName()); 168 if(nextManager instanceof ShutdownCleanupCapable) { 170 ShutdownCleanupCapable nextOne = (ShutdownCleanupCapable) nextManager; 171 nextOne.doCloseCachedConnection(); 172 } 173 } 174 } 175 } 176 } 177 } catch (Throwable th) { 178 _logger.log(Level.SEVERE, "Exception thrown", th); 179 } 180 181 } 182 183 } 184 | Popular Tags |