FileDocCategorySizeDatePackage
ReplicatedContext.javaAPI DocApache Tomcat 6.0.147549Fri Jul 20 04:20:34 BST 2007org.apache.catalina.ha.context

ReplicatedContext

public class ReplicatedContext extends org.apache.catalina.core.StandardContext implements org.apache.catalina.LifecycleListener
author
Filip Hanik
version
1.0

Fields Summary
private int
mapSendOptions
public static org.apache.juli.logging.Log
log
protected boolean
startComplete
protected static long
DEFAULT_REPL_TIMEOUT
Constructors Summary
Methods Summary
public java.lang.ClassLoader[]getClassLoaders()

        Loader loader = null;
        ClassLoader classLoader = null;
        loader = this.getLoader();
        if (loader != null) classLoader = loader.getClassLoader();
        if ( classLoader == null ) classLoader = Thread.currentThread().getContextClassLoader();
        if ( classLoader == Thread.currentThread().getContextClassLoader() ) {
            return new ClassLoader[] {classLoader};
        } else {
            return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()};
        }
    
public intgetMapSendOptions()

        return mapSendOptions;
    
public javax.servlet.ServletContextgetServletContext()

        if (context == null) {
            context = new ReplApplContext(getBasePath(), this);
            if (getAltDDName() != null)
                context.setAttribute(Globals.ALT_DD_ATTR,getAltDDName());
        }

        return ((ReplApplContext)context).getFacade();

    
public voidlifecycleEvent(org.apache.catalina.LifecycleEvent event)

//15 seconds
    
        
        if ( event.getType() == AFTER_START_EVENT ) 
            startComplete = true;
    
public voidsetMapSendOptions(int mapSendOptions)

        this.mapSendOptions = mapSendOptions;
    
public synchronized voidstart()

        if ( this.started ) return;
        super.addLifecycleListener(this);            
        try {
            CatalinaCluster catclust = (CatalinaCluster)this.getCluster();
            if (this.context == null) this.context = new ReplApplContext(this.getBasePath(), this);
            if ( catclust != null ) {
                ReplicatedMap map = new ReplicatedMap(this,catclust.getChannel(),DEFAULT_REPL_TIMEOUT,
                                                      getName(),getClassLoaders());
                map.setChannelSendOptions(mapSendOptions);
                ((ReplApplContext)this.context).setAttributeMap(map);
                if (getAltDDName() != null) context.setAttribute(Globals.ALT_DD_ATTR, getAltDDName());
            }
            super.start();
        }  catch ( Exception x ) {
            log.error("Unable to start ReplicatedContext",x);
            throw new LifecycleException("Failed to start ReplicatedContext",x);
        }
    
public synchronized voidstop()

        ReplicatedMap map = (ReplicatedMap)((ReplApplContext)this.context).getAttributeMap();
        if ( map!=null ) {
            map.breakdown();
        }
        if ( !this.started ) return;
        try {
            super.lifecycle.removeLifecycleListener(this);
        } catch ( Exception x ){
            log.error("Unable to stop ReplicatedContext",x);
            throw new LifecycleException("Failed to stop ReplicatedContext",x);
        } finally {
            this.startComplete = false;
            super.stop();
        }