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.Valve; 42 import org.apache.catalina.core.ContainerBase; 43 import java.sql.Connection ; 44 45 import com.sun.enterprise.resource.ResourceSpec; 46 import com.sun.enterprise.Switch; 47 48 52 public class ConnectionShutdownUtil { 53 54 57 protected EmbeddedWebContainer _embedded = null; 58 private static Logger _logger; 59 private WebContainer webContainer = null; 60 static 61 { 62 _logger=LogDomains.getLogger(LogDomains.WEB_LOGGER); 63 } 64 65 66 public ConnectionShutdownUtil() { 67 } 68 69 70 75 76 77 public ConnectionShutdownUtil(EmbeddedWebContainer embedded) { 78 _embedded = embedded; 79 } 80 81 public String getApplicationId(Context ctx) { 82 com.sun.enterprise.web.WebModule wm = 83 (com.sun.enterprise.web.WebModule)ctx; 84 return wm.getID(); 85 } 86 87 public String getApplicationName(Context ctx) { 88 return ctx.getName(); 89 } 90 91 public ArrayList runGetShutdownCapables() { 92 _logger.finest("IN ConnectionShutdownUtil:runGetShutdownCapables"); 93 ArrayList shutdownCapablesList = new ArrayList (); 97 98 try { 99 Engine[] engines = _embedded.getEngines(); 100 101 for(int h=0; h<engines.length; h++) { 102 Container engine = (Container) engines[h]; 103 Container[] hosts = engine.findChildren(); 104 for(int i=0; i<hosts.length; i++) { 105 Container nextHost = hosts[i]; 106 Container [] webModules = nextHost.findChildren(); 107 for (int j=0; j<webModules.length; j++) { 108 Container nextWebModule = webModules[j]; 109 Context ctx = (Context)nextWebModule; 110 String webAppName = this.getApplicationId(ctx); 112 Manager nextManager = nextWebModule.getManager(); 113 if(nextManager instanceof ShutdownCleanupCapable) { 114 _logger.finest("found a shutdown capable manager:" + nextManager.getClass().getName()); 115 shutdownCapablesList.add(nextManager); 117 } 118 } 119 _logger.finest("1) shutdownCapablesList Size = " + shutdownCapablesList.size()); 120 Valve[] valves = ((ContainerBase)nextHost).getValves(); 123 for(int k=0; k<valves.length; k++) { 124 Valve nextValve = valves[k]; 125 _logger.finest("VALVE = " + nextValve.getClass().getName()); 126 if(nextValve instanceof ShutdownCleanupCapable) { 128 _logger.finest("found a shutdown capable valve"); 129 shutdownCapablesList.add(nextValve); 131 } 132 } 133 } 134 } 135 } catch (Throwable th) { 136 _logger.log(Level.SEVERE, "Exception thrown", th); 137 } 138 _logger.finest("1) shutdownCapablesList Size = " + shutdownCapablesList.size()); 139 return shutdownCapablesList; 141 142 } 143 144 public ArrayList runGetShutdownCapablesForAppName(String appName) { 145 _logger.finest("IN ConnectionShutdownUtil:runGetShutdownCapablesForAppName"); 147 ArrayList shutdownCapablesList = new ArrayList (); 151 try { 152 Engine[] engines = _embedded.getEngines(); 153 154 for(int h=0; h<engines.length; h++) { 155 Container engine = (Container) engines[h]; 156 Container[] hosts = engine.findChildren(); 157 for(int i=0; i<hosts.length; i++) { 158 Container nextHost = hosts[i]; 159 Container [] webModules = nextHost.findChildren(); 160 for (int j=0; j<webModules.length; j++) { 161 Container nextWebModule = webModules[j]; 162 Context ctx = (Context)nextWebModule; 163 String webAppName = this.getApplicationName(ctx); 164 Manager nextManager = nextWebModule.getManager(); 167 if(nextManager instanceof ShutdownCleanupCapable) { 168 if(webAppName.equals(appName)) { 169 _logger.finest("found a shutdown capable manager:" + nextManager.getClass().getName()); 170 shutdownCapablesList.add(nextManager); 172 } 173 } 174 } 175 177 } 178 } 179 } catch (Throwable th) { 180 _logger.log(Level.SEVERE, "Exception thrown", th); 181 } 182 _logger.finest("1) shutdownCapablesList Size = " + shutdownCapablesList.size()); 183 return shutdownCapablesList; 185 186 } 187 188 public void runShutdownCleanupFromShutdownCleanupCapableList(ArrayList shutdownCapablesList) { 189 for(int i=0; i<shutdownCapablesList.size(); i++) { 190 ShutdownCleanupCapable nextOne = (ShutdownCleanupCapable)shutdownCapablesList.get(i); 191 nextOne.doShutdownCleanup(); 192 } 193 } 194 195 public void runCloseAllConnections() { 196 ArrayList list = this.runGetShutdownCapables(); 197 this.runShutdownCleanupFromShutdownCleanupCapableList(list); 198 } 199 200 public void runCloseCachedConnectionForApp(String appName) { 201 ArrayList list = this.runGetShutdownCapablesForAppName(appName); 202 this.runCloseCachedConnectionFromShutdownCleanupCapableList(list, appName); 203 } 204 205 public void runCloseCachedConnectionFromShutdownCleanupCapableList(ArrayList shutdownCapablesList, String appName) { 206 for(int i=0; i<shutdownCapablesList.size(); i++) { 207 ShutdownCleanupCapable nextOne = (ShutdownCleanupCapable)shutdownCapablesList.get(i); 208 nextOne.doCloseCachedConnection(); 209 } 210 } 211 212 public void clearoutJDBCPool() { 213 String hadbPoolname = this.getHadbJdbcConnectionPoolNameFromConfig(); 215 if(hadbPoolname == null) { 216 return; 217 } 218 ResourceSpec resourceSpec = new ResourceSpec(hadbPoolname, 219 ResourceSpec.JNDI_NAME); 220 resourceSpec.setConnectionPoolName(hadbPoolname); 221 if(resourceSpec == null) { 222 return; 223 } 224 Switch.getSwitch().getPoolManager().emptyResourcePool(resourceSpec); 225 resourceSpec = new ResourceSpec(hadbPoolname, ResourceSpec.JDBC_URL); 226 resourceSpec.setConnectionPoolName(hadbPoolname); 227 if(resourceSpec == null) { 228 return; 229 } 230 Switch.getSwitch().getPoolManager().emptyResourcePool(resourceSpec); 231 } 232 233 private String getHadbJdbcConnectionPoolNameFromConfig() { 234 ServerConfigLookup configLookup = new ServerConfigLookup(); 235 return configLookup.getHadbJdbcConnectionPoolNameFromConfig(); 236 } 237 238 } 239 240 241 | Popular Tags |