Java源码示例:org.apache.catalina.Cluster

示例1
/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {

    if (cluster == null) {
        Cluster containerCluster = getContainer().getCluster();
        if (containerCluster instanceof CatalinaCluster) {
            setCluster((CatalinaCluster)containerCluster);
        }
    }

    if (log.isInfoEnabled()) {
        log.info(sm.getString("jvmRoute.valve.started"));
        if (cluster == null) {
            log.info(sm.getString("jvmRoute.noCluster"));
        }
    }

    super.startInternal();
}
 
示例2
/**
 * Return the Cluster with which this Container is associated.  If there is
 * no associated Cluster, return the Cluster associated with our parent
 * Container (if any); otherwise return <code>null</code>.
 */
@Override
public Cluster getCluster() {
    Lock readLock = clusterLock.readLock();
    readLock.lock();
    try {
        if (cluster != null)
            return cluster;

        if (parent != null)
            return parent.getCluster();

        return null;
    } finally {
        readLock.unlock();
    }
}
 
示例3
private void manageCluster(final Cluster cluster) {
    if (cluster == null || cluster instanceof SimpleTomEETcpCluster) {
        return;
    }

    Cluster current = cluster;
    if (cluster instanceof SimpleTcpCluster) {
        final Container container = cluster.getContainer();
        current = new SimpleTomEETcpCluster((SimpleTcpCluster) cluster);
        container.setCluster(current);
    }

    if (current instanceof CatalinaCluster) {
        final CatalinaCluster haCluster = (CatalinaCluster) current;
        TomEEClusterListener listener = SystemInstance.get().getComponent(TomEEClusterListener.class);
        if (listener == null) {
            listener = new TomEEClusterListener();
            SystemInstance.get().setComponent(TomEEClusterListener.class, listener);
        }
        haCluster.addClusterListener(listener); // better to be a singleton
        clusters.add(haCluster);
    }
}
 
示例4
@Override
protected void startInternal() throws LifecycleException {
    super.startInternal();
    if (getCluster() == null) {
        Cluster cluster = getContext().getCluster();
        if (cluster instanceof CatalinaCluster) {
            setCluster((CatalinaCluster)cluster);
        }
    }
    if (cluster != null) cluster.registerManager(this);
}
 
示例5
/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {
    if (cluster == null) {
        Cluster containerCluster = getContainer().getCluster();
        if (containerCluster instanceof CatalinaCluster) {
            setCluster((CatalinaCluster)containerCluster);
        } else {
            if (log.isWarnEnabled()) {
                log.warn(sm.getString("ReplicationValve.nocluster"));
            }
        }
    }
    super.startInternal();
}
 
示例6
protected Cluster getClusterInternal() {
    Lock readLock = clusterLock.readLock();
    readLock.lock();
    try {
        return cluster;
    } finally {
        readLock.unlock();
    }
}
 
示例7
@Override
protected void destroyInternal() throws LifecycleException {

    Realm realm = getRealmInternal();
    if (realm instanceof Lifecycle) {
        ((Lifecycle) realm).destroy();
    }
    Cluster cluster = getClusterInternal();
    if (cluster instanceof Lifecycle) {
        ((Lifecycle) cluster).destroy();
    }

    // Stop the Valves in our pipeline (including the basic), if any
    if (pipeline instanceof Lifecycle) {
        ((Lifecycle) pipeline).destroy();
    }

    // Remove children now this container is being destroyed
    for (Container child : findChildren()) {
        removeChild(child);
    }

    // Required if the child is destroyed directly.
    if (parent != null) {
        parent.removeChild(this);
    }

    // If init fails, this may be null
    if (startStopExecutor != null) {
        startStopExecutor.shutdownNow();
    }

    super.destroyInternal();
}
 
示例8
@Override
protected void startInternal() throws LifecycleException {
    super.startInternal();
    if (getCluster() == null) {
        Cluster cluster = getContainer().getCluster();
        if (cluster instanceof CatalinaCluster) {
            setCluster((CatalinaCluster)cluster);
        }
    }
    if (cluster != null) cluster.registerManager(this);
}
 
示例9
/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {
    if (cluster == null) {
        Cluster containerCluster = getContainer().getCluster();
        if (containerCluster instanceof CatalinaCluster) {
            setCluster((CatalinaCluster)containerCluster);
        } else {
            if (log.isWarnEnabled()) {
                log.warn(sm.getString("ReplicationValve.nocluster"));
            }
        }
    }
    super.startInternal();
}
 
示例10
/**
 * Return the Cluster with which this Container is associated.  If there is
 * no associated Cluster, return the Cluster associated with our parent
 * Container (if any); otherwise return <code>null</code>.
 */
@Override
public Cluster getCluster() {
    if (cluster != null)
        return (cluster);

    if (parent != null)
        return (parent.getCluster());

    return (null);
}
 
示例11
@Override
protected void startInternal() throws LifecycleException {
    super.startInternal();
    if (getCluster() == null) {
        Cluster cluster = getContainer().getCluster();
        if (cluster instanceof CatalinaCluster) {
            setCluster((CatalinaCluster)cluster);
        }
    }
    if (cluster != null) cluster.registerManager(this);
}
 
示例12
/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {
    if (cluster == null) {
        Cluster containerCluster = getContainer().getCluster();
        if (containerCluster instanceof CatalinaCluster) {
            setCluster((CatalinaCluster)containerCluster);
        } else {
            if (log.isWarnEnabled()) {
                log.warn(sm.getString("ReplicationValve.nocluster"));
            }
        }
    }
    super.startInternal();
}
 
示例13
@Override
public Cluster getCluster() { return null; }
 
示例14
@Override
public void setCluster(Cluster cluster) { /* NO-OP */ }
 
示例15
/**
 * Store the specified Host properties and children
 * (Listener,Alias,Realm,Valve,Cluster, Context)
 *
 * @param aWriter
 *            PrintWriter to which we are storing
 * @param indent
 *            Number of spaces to indent this element
 * @param aHost
 *            Host whose properties are being stored
 *
 * @exception Exception
 *                if an exception occurs while storing
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aHost,
        StoreDescription parentDesc) throws Exception {
    if (aHost instanceof StandardHost) {
        StandardHost host = (StandardHost) aHost;
        // Store nested <Listener> elements
        LifecycleListener listeners[] = ((Lifecycle) host)
                .findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);

        // Store nested <Alias> elements
        String aliases[] = host.findAliases();
        getStoreAppender().printTagArray(aWriter, "Alias", indent + 2,
                aliases);

        // Store nested <Realm> element
        Realm realm = host.getRealm();
        if (realm != null) {
            Realm parentRealm = null;
            if (host.getParent() != null) {
                parentRealm = host.getParent().getRealm();
            }
            if (realm != parentRealm) {
                storeElement(aWriter, indent, realm);
            }
        }

        // Store nested <Valve> elements
        Valve valves[] = host.getPipeline().getValves();
        if(valves != null && valves.length > 0 ) {
            List<Valve> hostValves = new ArrayList<>() ;
            for(int i = 0 ; i < valves.length ; i++ ) {
                if(!( valves[i] instanceof ClusterValve))
                    hostValves.add(valves[i]);
            }
            storeElementArray(aWriter, indent, hostValves.toArray());
        }

        // store all <Cluster> elements
        Cluster cluster = host.getCluster();
        if (cluster != null) {
            Cluster parentCluster = null;
            if (host.getParent() != null) {
                parentCluster = host.getParent().getCluster();
            }
            if (cluster != parentCluster) {
                storeElement(aWriter, indent, cluster);
            }
        }

        // store all <Context> elements
        Container children[] = host.findChildren();
        storeElementArray(aWriter, indent, children);
    }
}
 
示例16
/**
 * Store the specified Engine properties.
 *
 * @param aWriter
 *            PrintWriter to which we are storing
 * @param indent
 *            Number of spaces to indent this element
 * @param aEngine
 *            Object whose properties are being stored
 *
 * @exception Exception
 *                if an exception occurs while storing
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aEngine,
        StoreDescription parentDesc) throws Exception {
    if (aEngine instanceof StandardEngine) {
        StandardEngine engine = (StandardEngine) aEngine;
        // Store nested <Listener> elements
        LifecycleListener listeners[] = ((Lifecycle) engine)
                .findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);

        // Store nested <Realm> element
        Realm realm = engine.getRealm();
        Realm parentRealm = null;
        // TODO is this case possible? (see it a old Server 5.0 impl)
        if (engine.getParent() != null) {
            parentRealm = engine.getParent().getRealm();
        }
        if (realm != parentRealm) {
            storeElement(aWriter, indent, realm);

        }

        // Store nested <Valve> elements
        Valve valves[] = engine.getPipeline().getValves();
        if(valves != null && valves.length > 0 ) {
            List<Valve> engineValves = new ArrayList<>() ;
            for(int i = 0 ; i < valves.length ; i++ ) {
                if(!( valves[i] instanceof ClusterValve))
                    engineValves.add(valves[i]);
            }
            storeElementArray(aWriter, indent, engineValves.toArray());
        }

        // store all <Cluster> elements
        Cluster cluster = engine.getCluster();
        if (cluster != null) {
            storeElement(aWriter, indent, cluster);
        }
        // store all <Host> elements
        Container children[] = engine.findChildren();
        storeElementArray(aWriter, indent, children);

   }
}
 
示例17
/**
 1.BootStrap反射调用Catalina的start。
 * 2.Catalina去调用了StandardServer的start方法。
 * 3.StandardServer调用StandardService的start方法。
 * 4.StandardService调用StandarEngine的start方法。
 * 5.StandarEngine调用ContainerBase的start方法。(重点)
 * 6.ContainerBase的start方法:
 *          6.1 日志。
 *          6.2 安全。
 *          6.3 启动所有子容器(ChildList Future框架启动线程池去启动子结点)。启动子结点重点。
 *                  (Engin -> Host -> Context-> Wrapper 层级调用。
 *                      共享父类的方法,针对不同的容器处理不同。)
 *                      HostConfig类添加所有的Context结点。
 *                      然后在此类中进行启动。包括StandardContext结点。
 *                      StandardContext结点通过Web.xml文件,用ContextConfig添加了
 *                      所有的子节点。
 *                      然后在StandardContext去启动了StandardWrapper。
 *                      StandardWrapper load and start。
 *          6.4 Pipeline的启动。
 *          6.5 激发HostConfig监听器。
 *          (HostConfig ->t添加Host。) {@link HostConfig#start()}
 *          6.6 启动后台线程。
 *
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {

    // Start our subordinate components, if any
    logger = null;
    getLogger();
    //tomcat集群相关。
    Cluster cluster = getClusterInternal();
    if (cluster instanceof Lifecycle) {
        ((Lifecycle) cluster).start();
    }
    Realm realm = getRealmInternal();
    if (realm instanceof Lifecycle) {
        ((Lifecycle) realm).start();
    }

    // Start our child containers, if any
    Container children[] = findChildren();
    List<Future<Void>> results = new ArrayList<>();
    for (int i = 0; i < children.length; i++) {
        results.add(startStopExecutor.submit(new StartChild(children[i])));
    }

    MultiThrowable multiThrowable = null;

    for (Future<Void> result : results) {
        try {
            result.get();
        } catch (Throwable e) {
            log.error(sm.getString("containerBase.threadedStartFailed"), e);
            if (multiThrowable == null) {
                multiThrowable = new MultiThrowable();
            }
            multiThrowable.add(e);
        }

    }
    if (multiThrowable != null) {
        throw new LifecycleException(sm.getString("containerBase.threadedStartFailed"),
                multiThrowable.getThrowable());
    }

    // Start the Valves in our pipeline (including the basic), if any
    if (pipeline instanceof Lifecycle) {
        ((Lifecycle) pipeline).start();
    }


    setState(LifecycleState.STARTING);

    // Start our thread
    threadStart();
}
 
示例18
/**
 * Stop this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void stopInternal() throws LifecycleException {

    // Stop our thread
    threadStop();

    setState(LifecycleState.STOPPING);

    // Stop the Valves in our pipeline (including the basic), if any
    if (pipeline instanceof Lifecycle &&
            ((Lifecycle) pipeline).getState().isAvailable()) {
        ((Lifecycle) pipeline).stop();
    }

    // Stop our child containers, if any
    Container children[] = findChildren();
    List<Future<Void>> results = new ArrayList<>();
    for (int i = 0; i < children.length; i++) {
        results.add(startStopExecutor.submit(new StopChild(children[i])));
    }

    boolean fail = false;
    for (Future<Void> result : results) {
        try {
            result.get();
        } catch (Exception e) {
            log.error(sm.getString("containerBase.threadedStopFailed"), e);
            fail = true;
        }
    }
    if (fail) {
        throw new LifecycleException(
                sm.getString("containerBase.threadedStopFailed"));
    }

    // Stop our subordinate components, if any
    Realm realm = getRealmInternal();
    if (realm instanceof Lifecycle) {
        ((Lifecycle) realm).stop();
    }
    Cluster cluster = getClusterInternal();
    if (cluster instanceof Lifecycle) {
        ((Lifecycle) cluster).stop();
    }
}
 
示例19
@Override
public Cluster getCluster() {
    return null;
}
 
示例20
@Override
public void setCluster(Cluster cluster) {
    // NO-OP
}
 
示例21
@Override
public Cluster getCluster() {
    return null;
}
 
示例22
@Override
public void setCluster(Cluster cluster) {
    // NO-OP
}
 
示例23
@Override
public Cluster getCluster() { return null; }
 
示例24
@Override
public void setCluster(Cluster cluster) { /* NO-OP */ }
 
示例25
@Override
public Cluster getCluster() {
    return null;
}
 
示例26
@Override
public void setCluster(Cluster cluster) {
    // NO-OP
}
 
示例27
@Override
public Cluster getCluster() { return null; }
 
示例28
@Override
public void setCluster(Cluster cluster) { /* NO-OP */ }
 
示例29
@Override
public Cluster getCluster() {
    return null;
}
 
示例30
@Override
public void setCluster(Cluster cluster) {
    // NO-OP
}