FileDocCategorySizeDatePackage
ReconfigListener.javaAPI DocGlassfish v2 API24804Fri May 04 22:36:06 BST 2007com.sun.enterprise.web.reconfig

ReconfigListener

public class ReconfigListener extends Object implements com.sun.enterprise.admin.event.http.HSRequestProcessingEventListener, com.sun.enterprise.admin.event.http.HSAccessLogEventListener, com.sun.enterprise.admin.event.http.HSKeepAliveEventListener, com.sun.enterprise.admin.event.http.HSHttpListenerEventListener, com.sun.enterprise.admin.event.http.HSServiceEventListener, com.sun.enterprise.admin.event.http.HSHttpProtocolEventListener, com.sun.enterprise.admin.event.http.HSConnectionPoolEventListener, com.sun.enterprise.admin.event.http.HSVirtualServerEventListener, com.sun.enterprise.admin.event.http.HSHttpFileCacheEventListener
Class responsible for handling dynamic reconfiguration events for various elements in domain.xml.
author
Jean-Francois Arcand
author
Jan Luehe

Fields Summary
private com.sun.enterprise.web.PEWebContainer
webContainer
Constructors Summary
public ReconfigListener(com.sun.enterprise.web.PEWebContainer webContainer)

        this.webContainer = webContainer;
    
Methods Summary
public voidhandleCreate(com.sun.enterprise.admin.event.http.HSServiceEvent event)

        // Ignore
    
public voidhandleCreate(com.sun.enterprise.admin.event.http.HSVirtualServerEvent event)
Create a new virtual-server.

        
        if (webContainer == null || event == null) {
            return;
        }
           
        try {                                                          
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
                                    
            if ( config == null) return;
            
            ConfigAdd configAdd = null;
            ArrayList configChangeList = event.getConfigChangeList();
            VirtualServer vsBean = null;
            String xpath = null;
            Server serverBean = ServerBeansFactory.getServerBean(configContext);
            ElementProperty elementProperty = null;
            Object object;
            Object configObject;
            
            for (int i=0; i < configChangeList.size(); i++){
                configObject = configChangeList.get(i);

                if ( configObject instanceof ConfigAdd) {
                    configAdd = (ConfigAdd)configObject;
                    xpath = configAdd.getXPath();
                    if( xpath != null){
                        object = configContext.exactLookup(xpath);

                        if ( object instanceof VirtualServer){
                            vsBean = (VirtualServer)object;
                            webContainer.createHost(vsBean,configContext,true);
                        } else if (object instanceof ElementProperty) {
                            xpath = xpath.substring(0,xpath.lastIndexOf("/"));
                            vsBean = (VirtualServer)configContext.exactLookup(xpath);                       
                            elementProperty = (ElementProperty)object;
                            webContainer.updateHostProperties(
                                       vsBean, 
                                       elementProperty.getName(),
                                       elementProperty.getValue(),
                                       config.getHttpService(),
                                       config.getSecurityService());
                        }
                    }
                }
            }
        } catch (Exception ex) {
           throw new AdminEventListenerException(ex);
        } 
    
public voidhandleCreate(com.sun.enterprise.admin.event.http.HSHttpProtocolEvent event)

        // Ignore
    
public voidhandleCreate(com.sun.enterprise.admin.event.http.HSHttpFileCacheEvent event)

        // Ignore
    
public voidhandleCreate(com.sun.enterprise.admin.event.http.HSConnectionPoolEvent event)

        // Ignore
    
public voidhandleCreate(com.sun.enterprise.admin.event.http.HSKeepAliveEvent event)

        // Ignore
    
public voidhandleCreate(com.sun.enterprise.admin.event.http.HSRequestProcessingEvent event)

        // Ignore
    
public voidhandleCreate(com.sun.enterprise.admin.event.http.HSAccessLogEvent event)

        // Ignore
    
public voidhandleCreate(com.sun.enterprise.admin.event.http.HSHttpListenerEvent event)
Create a new http-listener.

        
        if (webContainer == null || event == null) {
            return;       
        }

        try {             
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            
            if ( config == null) return;
            
            ConfigAdd configAdd = null;
            ArrayList configChangeList = event.getConfigChangeList();
            HttpListener httpBean = null;
            String xpath = null;
            Object object;
            Object configObject;
            
            for (int i=0; i < configChangeList.size(); i++){
                configObject = configChangeList.get(i);

                if ( configObject instanceof ConfigAdd) {
                    configAdd = (ConfigAdd)configObject;
                    xpath = configAdd.getXPath();
                    if( xpath != null){
                        object = configContext.exactLookup(xpath);
                        if ( object instanceof HttpListener){
                            httpBean = (HttpListener)object;
                            webContainer.createConnector(httpBean, 
                                                         config.getHttpService());
                        }
                    }
                }
            }
        } catch (Exception ex) {
           throw new AdminEventListenerException(ex);
        }  
    
public voidhandleDelete(com.sun.enterprise.admin.event.http.HSVirtualServerEvent event)
Delete an existing virtual-server. Implementation note: we cannot use the same approach used when handling create/update event since the element is deleted before this method is invoked (strange behaviour). Instead we need to find by ourself which virtual-server has been deleted.


        if (webContainer == null || event == null) {
            return;       
        }

        try {
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            if (config != null) {
                webContainer.deleteHost(config.getHttpService());    
            }
        } catch( Exception ex){
           throw new AdminEventListenerException(ex);
        }    
    
public voidhandleDelete(com.sun.enterprise.admin.event.http.HSHttpProtocolEvent event)

        // Ignore
    
public voidhandleDelete(com.sun.enterprise.admin.event.http.HSHttpFileCacheEvent event)

        // Ignore
    
public voidhandleDelete(com.sun.enterprise.admin.event.http.HSAccessLogEvent event)

        // Ignore
    
public voidhandleDelete(com.sun.enterprise.admin.event.http.HSConnectionPoolEvent event)

        // Ignore
    
public voidhandleDelete(com.sun.enterprise.admin.event.http.HSKeepAliveEvent event)

        // Ignore
    
public voidhandleDelete(com.sun.enterprise.admin.event.http.HSRequestProcessingEvent event)

        // Ignore
    
public voidhandleDelete(com.sun.enterprise.admin.event.http.HSHttpListenerEvent event)
Delete an existing http-listener. Implementation note: we cannot use the same approach used when handling create/update event since the element is deleted before this method is invoked (strange behaviour). Instead we need to find by ourself which http-listener has been deleted.

         
        if (webContainer == null || event == null) {
            return;       
        }

        try {
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
                
            if ( config == null) return;
                
            webContainer.deleteConnector(config.getHttpService());

        }  catch( Exception ex){
           throw new AdminEventListenerException(ex);
        }      
    
public voidhandleDelete(com.sun.enterprise.admin.event.http.HSServiceEvent event)

        // Ignore
    
public voidhandleUpdate(com.sun.enterprise.admin.event.http.HSVirtualServerEvent event)
Update an existing virtual-server.

  
        
        if (webContainer == null || event == null) {
            return;
        }
           
        try {                                            
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            
            if ( config == null) return;
            
            ConfigChange configChange = null;
            ArrayList<ConfigChange> configChangeList = 
                event.getConfigChangeList();
            VirtualServer vsBean = null;
            String xpath = null;
            String parentXpath = null;
            Server serverBean = ServerBeansFactory.getServerBean(configContext);
            ElementProperty elementProperty = null;
            Object object;           

            for (int i=0; i < configChangeList.size(); i++){
                configChange = configChangeList.get(i);
                
                xpath = configChange.getXPath();
                if (xpath != null) {
                    object = configContext.exactLookup(xpath);
                    if (object != null) {
                        if ( object instanceof VirtualServer){
                            webContainer.updateHost((VirtualServer)object, 
                                                    config.getHttpService(), 
                                                    serverBean);
                        } else if (object instanceof ElementProperty) {
                            // Property has been added or updated
                            parentXpath = configChange.getParentXPath();
                            if (parentXpath == null) {
                                parentXpath =
                                    xpath.substring(0, xpath.lastIndexOf("/"));
                            }
                            vsBean = (VirtualServer)
                                configContext.exactLookup(parentXpath);
                            elementProperty = (ElementProperty)object;
                            webContainer.updateHostProperties(
                                       vsBean, 
                                       elementProperty.getName(),
                                       elementProperty.getValue(),
                                       config.getHttpService(),
                                       config.getSecurityService());
                        }

                    } else {
                        // Property has been deleted.
                        // Determine the property's name
                        int lastSlash = xpath.lastIndexOf("/");
                        parentXpath = xpath.substring(0, lastSlash);
                        String propName = xpath.substring(lastSlash);
                        if (propName != null) {
                            // e.g., /element-property[@name='sso-enabled']
                            int beginQuote = propName.indexOf("'");
                            int endQuote = propName.lastIndexOf("'");
                            if (endQuote > beginQuote) {
                                propName = propName.substring(beginQuote+1,
                                                              endQuote);
                                vsBean = (VirtualServer)
                                    configContext.exactLookup(parentXpath);
                                webContainer.updateHostProperties(
                                       vsBean,
                                       propName,
                                       null,
                                       config.getHttpService(),
                                       config.getSecurityService());
                            }
                        }
                    }
                }
            }
        } catch (Exception ex) {
           throw new AdminEventListenerException(ex);
        } 
    
public voidhandleUpdate(com.sun.enterprise.admin.event.http.HSHttpProtocolEvent event)


        if (webContainer == null) {
            return;
        }

        try {
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            if (config == null) {
                return;
            }
            webContainer.updateHttpService(config.getHttpService());
        } catch (Exception e) {
           throw new AdminEventListenerException(e);
        } 
    
public voidhandleUpdate(com.sun.enterprise.admin.event.http.HSHttpFileCacheEvent event)


        if (webContainer == null) {
            return;
        }

        try {
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            if (config == null) {
                return;
            }
            webContainer.updateHttpService(config.getHttpService());
        } catch (Exception e) {
           throw new AdminEventListenerException(e);
        } 
    
public voidhandleUpdate(com.sun.enterprise.admin.event.http.HSConnectionPoolEvent event)


        if (webContainer == null) {
            return;
        }

        try {
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            if (config == null) {
                return;
            }
            webContainer.updateHttpService(config.getHttpService());
        } catch (Exception e) {
           throw new AdminEventListenerException(e);
        } 
    
public voidhandleUpdate(com.sun.enterprise.admin.event.http.HSKeepAliveEvent event)


        if (webContainer == null) {
            return;
        }

        try {
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            if (config == null) {
                return;
            }
            webContainer.updateHttpService(config.getHttpService());
        } catch (Exception e) {
           throw new AdminEventListenerException(e);
        } 
    
public voidhandleUpdate(com.sun.enterprise.admin.event.http.HSRequestProcessingEvent event)


        if (webContainer == null) {
            return;
        }

        try {
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            if (config == null) {
                return;
            }
            webContainer.updateHttpService(config.getHttpService());
        } catch (Exception e) {
           throw new AdminEventListenerException(e);
        } 
    
public voidhandleUpdate(com.sun.enterprise.admin.event.http.HSAccessLogEvent event)


        if (webContainer == null || event == null) {
            return;
        }
           
        try {
                   
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            if (config == null) {
                return;
            }
            
            webContainer.updateAccessLog(config.getHttpService());

        } catch (Exception e) {
           throw new AdminEventListenerException(e);
        } 
    
public voidhandleUpdate(com.sun.enterprise.admin.event.http.HSHttpListenerEvent event)
Update an existing http-listener.

   
        
        if (webContainer == null || event == null) {
            return;
        }
                                     
        try {                        
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            
            if ( config == null) return;
            
            ConfigChange configChange = null;
            ArrayList<ConfigChange> configChangeList =
                event.getConfigChangeList();
            HttpListener httpBean = null;
            String xpath = null;
            String parentXpath = null;
            Object object;
            ElementProperty elementProperty = null;

            for (int i=0; i < configChangeList.size(); i++){
                configChange = configChangeList.get(i);
                xpath = configChange.getXPath();
                if (xpath != null) {
                    object = configContext.exactLookup(xpath);
                    if (object != null) {
                        if (object instanceof HttpListener) {
                            
                            if ( ((HttpListener)object).getDefaultVirtualServer()
                                    .equals(com.sun.enterprise.web.VirtualServer.ADMIN_VS)){
                                
                                if (configChangeList.size() == 1){
                                    throw new AdminEventListenerException("Restart required");
                                } else {
                                    continue;
                                }                                
                            }
                            
                            webContainer.updateConnector(
                                (HttpListener)object, 
                                config.getHttpService());
                        } else if (object instanceof ElementProperty) {
                            // Property has been added or updated
                            parentXpath = configChange.getParentXPath();
                            if (parentXpath == null) {
                                parentXpath =
                                    xpath.substring(0, xpath.lastIndexOf("/"));
                            }
                            httpBean = (HttpListener)
                                configContext.exactLookup(parentXpath);
                            webContainer.updateConnector(
                                httpBean, 
                                config.getHttpService());
                        }
                    } else {
                        // Property has been deleted
                        parentXpath =
                            xpath.substring(0, xpath.lastIndexOf("/"));
                        httpBean = (HttpListener)
                            configContext.exactLookup(parentXpath);
                        webContainer.updateConnector(
                            httpBean, 
                            config.getHttpService());
                    }
                }
            }
        } catch (Exception ex) {
           throw new AdminEventListenerException(ex);
        }
    
public voidhandleUpdate(com.sun.enterprise.admin.event.http.HSServiceEvent event)


        if (webContainer == null || event == null) {
            return;
        }

        try {
                   
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            if (config == null) {
                return;
            }
            
            webContainer.updateHttpService(config.getHttpService());

        } catch (Exception e) {
           throw new AdminEventListenerException(e);
        }