FileDocCategorySizeDatePackage
ConnectionShutdownUtil.javaAPI DocGlassfish v2 API11317Fri May 04 22:36:00 BST 2007com.sun.enterprise.web

ConnectionShutdownUtil

public class ConnectionShutdownUtil extends Object
author
lwhite

Fields Summary
protected final EmbeddedWebContainer
_embedded
The embedded Catalina object.
private static final Logger
_logger
private WebContainer
webContainer
Constructors Summary
public ConnectionShutdownUtil()
Creates a new instance of ConnectionShutdownUtil

    
    
            _logger=LogDomains.getLogger(LogDomains.WEB_LOGGER);
    
        _embedded= null;
    
public ConnectionShutdownUtil(EmbeddedWebContainer embedded)
Creates a new instance of ConnectionShutdownUtil

        _embedded = embedded;
    
Methods Summary
public voidclearoutJDBCPool()

        //this will clear out the HADB connection pool
        String hadbPoolname = this.getHadbJdbcConnectionPoolNameFromConfig();
        if(hadbPoolname == null) {
            return;
        }
        ResourceSpec resourceSpec = new ResourceSpec(hadbPoolname,
            ResourceSpec.JNDI_NAME);
        resourceSpec.setConnectionPoolName(hadbPoolname);
        if(resourceSpec == null) {
            return;
        }
        Switch.getSwitch().getPoolManager().emptyResourcePool(resourceSpec);
        resourceSpec = new ResourceSpec(hadbPoolname, ResourceSpec.JDBC_URL);
        resourceSpec.setConnectionPoolName(hadbPoolname);
        if(resourceSpec == null) {
            return;
        }        
        Switch.getSwitch().getPoolManager().emptyResourcePool(resourceSpec);
    
public java.lang.StringgetApplicationId(org.apache.catalina.Context ctx)

        com.sun.enterprise.web.WebModule wm = 
            (com.sun.enterprise.web.WebModule)ctx;
        return wm.getID();
    
public java.lang.StringgetApplicationName(org.apache.catalina.Context ctx)

        return ctx.getName();
    
private java.lang.StringgetHadbJdbcConnectionPoolNameFromConfig()

        ServerConfigLookup configLookup = new ServerConfigLookup();
        return configLookup.getHadbJdbcConnectionPoolNameFromConfig();
    
public voidrunCloseAllConnections()

        ArrayList list = this.runGetShutdownCapables();
        this.runShutdownCleanupFromShutdownCleanupCapableList(list);
    
public voidrunCloseCachedConnectionForApp(java.lang.String appName)

        ArrayList list = this.runGetShutdownCapablesForAppName(appName);
        this.runCloseCachedConnectionFromShutdownCleanupCapableList(list, appName);
    
public voidrunCloseCachedConnectionFromShutdownCleanupCapableList(java.util.ArrayList shutdownCapablesList, java.lang.String appName)

        for(int i=0; i<shutdownCapablesList.size(); i++) {
            ShutdownCleanupCapable nextOne = (ShutdownCleanupCapable)shutdownCapablesList.get(i);
            nextOne.doCloseCachedConnection();
        }
    
public java.util.ArrayListrunGetShutdownCapables()

        _logger.finest("IN ConnectionShutdownUtil:runGetShutdownCapables");
        //System.out.println("IN ConnectionShutdownUtil:runGetShutdownCapables");
        //each element of this list will contain
        //a list of connections
        ArrayList shutdownCapablesList = new ArrayList();

        try {
            Engine[] engines = _embedded.getEngines();
            
            for(int h=0; h<engines.length; h++) {
                Container engine = (Container) engines[h];            
                Container[] hosts = engine.findChildren();
                for(int i=0; i<hosts.length; i++) {
                    Container nextHost = hosts[i];
                    Container [] webModules = nextHost.findChildren();
                    for (int j=0; j<webModules.length; j++) {
                        Container nextWebModule = webModules[j];
                        Context ctx = (Context)nextWebModule;
                        //this code gets managers
                        String webAppName = this.getApplicationId(ctx);
                        Manager nextManager = nextWebModule.getManager();
                        if(nextManager instanceof ShutdownCleanupCapable) {
                            _logger.finest("found a shutdown capable manager:" + nextManager.getClass().getName());
                            //System.out.println("found a shutdown capable manager:" + nextManager.getClass().getName());
                            shutdownCapablesList.add(nextManager);
                        }
                    }
                    _logger.finest("1) shutdownCapablesList Size = " + shutdownCapablesList.size());
                    //System.out.println("1) shutdownCapablesList Size = " + shutdownCapablesList.size());                   
                    //now get any shutdown capable valves installed in virtual hosts
                    Valve[] valves = ((ContainerBase)nextHost).getValves();                    
                    for(int k=0; k<valves.length; k++) {
                        Valve nextValve = valves[k];
                        _logger.finest("VALVE = " + nextValve.getClass().getName());
                        //System.out.println("VALVE = " + nextValve.getClass().getName());                         
                        if(nextValve instanceof ShutdownCleanupCapable) {
                            _logger.finest("found a shutdown capable valve");
                            //System.out.println("found a shutdown capable valve");
                            shutdownCapablesList.add(nextValve);
                        }                       
                    }
                }                 
            }
        } catch (Throwable th) {
            _logger.log(Level.SEVERE, "Exception thrown", th);
        }
        _logger.finest("1) shutdownCapablesList Size = " + shutdownCapablesList.size());
        //System.out.println("1) shutdownCapablesList Size = " + shutdownCapablesList.size());         
        return shutdownCapablesList;
                
    
public java.util.ArrayListrunGetShutdownCapablesForAppName(java.lang.String appName)

        //FIXME this is not returning valves
        _logger.finest("IN ConnectionShutdownUtil:runGetShutdownCapablesForAppName");
        //System.out.println("IN ConnectionShutdownUtil:runGetShutdownCapablesForAppName");
        //each element of this list will contain
        //a list of connections
        ArrayList shutdownCapablesList = new ArrayList();
        try {
            Engine[] engines = _embedded.getEngines();
            
            for(int h=0; h<engines.length; h++) {
                Container engine = (Container) engines[h];             
                Container[] hosts = engine.findChildren();
                for(int i=0; i<hosts.length; i++) {
                    Container nextHost = hosts[i];
                    Container [] webModules = nextHost.findChildren();
                    for (int j=0; j<webModules.length; j++) {
                        Container nextWebModule = webModules[j];
                        Context ctx = (Context)nextWebModule;
                        String webAppName = this.getApplicationName(ctx);
                        //this code gets managers
                        //String webAppName = this.getApplicationId(ctx);
                        Manager nextManager = nextWebModule.getManager();
                        if(nextManager instanceof ShutdownCleanupCapable) {
                            if(webAppName.equals(appName)) {
                                _logger.finest("found a shutdown capable manager:" + nextManager.getClass().getName());
                                //System.out.println("found a shutdown capable manager:" + nextManager.getClass().getName());
                                shutdownCapablesList.add(nextManager);
                            }
                        }
                    }
                    //System.out.println("1) shutdownCapablesList Size = " + shutdownCapablesList.size());                   

                }                 
            }
        } catch (Throwable th) {
            _logger.log(Level.SEVERE, "Exception thrown", th);
        }
        _logger.finest("1) shutdownCapablesList Size = " + shutdownCapablesList.size());
        //System.out.println("1) shutdownCapablesList Size = " + shutdownCapablesList.size());         
        return shutdownCapablesList;
                
    
public voidrunShutdownCleanupFromShutdownCleanupCapableList(java.util.ArrayList shutdownCapablesList)

        for(int i=0; i<shutdownCapablesList.size(); i++) {
            ShutdownCleanupCapable nextOne = (ShutdownCleanupCapable)shutdownCapablesList.get(i);
            nextOne.doShutdownCleanup();
        }