Search in sources :

Example 1 with CatalinaCluster

use of org.apache.catalina.ha.CatalinaCluster in project tomee by apache.

the class TomcatWebAppBuilder method manageCluster.

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);
        }
        // better to be a singleton
        haCluster.addClusterListener(listener);
        clusters.add(haCluster);
    }
}
Also used : Container(org.apache.catalina.Container) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster) TomEEClusterListener(org.apache.tomee.catalina.cluster.TomEEClusterListener) Cluster(org.apache.catalina.Cluster) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster)

Example 2 with CatalinaCluster

use of org.apache.catalina.ha.CatalinaCluster in project tomcat by apache.

the class CatalinaClusterSF method storeChildren.

/**
 * Store the specified Cluster children.
 *
 * @param aWriter
 *            PrintWriter to which we are storing
 * @param indent
 *            Number of spaces to indent this element
 * @param aCluster
 *            Cluster whose properties are being stored
 *
 * @exception Exception
 *                if an exception occurs while storing
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aCluster, StoreDescription parentDesc) throws Exception {
    if (aCluster instanceof CatalinaCluster) {
        CatalinaCluster cluster = (CatalinaCluster) aCluster;
        if (cluster instanceof SimpleTcpCluster) {
            SimpleTcpCluster tcpCluster = (SimpleTcpCluster) cluster;
            // Store nested <Manager> element
            ClusterManager manager = tcpCluster.getManagerTemplate();
            if (manager != null) {
                storeElement(aWriter, indent, manager);
            }
        }
        // Store nested <Channel> element
        Channel channel = cluster.getChannel();
        if (channel != null) {
            storeElement(aWriter, indent, channel);
        }
        // Store nested <Deployer> element
        ClusterDeployer deployer = cluster.getClusterDeployer();
        if (deployer != null) {
            storeElement(aWriter, indent, deployer);
        }
        // Store nested <Valve> element
        // ClusterValve are not store at Hosts element, see
        Valve[] valves = cluster.getValves();
        storeElementArray(aWriter, indent, valves);
        if (aCluster instanceof SimpleTcpCluster) {
            // Store nested <Listener> elements
            LifecycleListener[] listeners = ((SimpleTcpCluster) cluster).findLifecycleListeners();
            storeElementArray(aWriter, indent, listeners);
            // Store nested <ClusterListener> elements
            ClusterListener[] mlisteners = ((SimpleTcpCluster) cluster).findClusterListeners();
            List<ClusterListener> clusterListeners = new ArrayList<>();
            for (ClusterListener clusterListener : mlisteners) {
                if (clusterListener != deployer) {
                    clusterListeners.add(clusterListener);
                }
            }
            storeElementArray(aWriter, indent, clusterListeners.toArray());
        }
    }
}
Also used : ClusterDeployer(org.apache.catalina.ha.ClusterDeployer) Channel(org.apache.catalina.tribes.Channel) ArrayList(java.util.ArrayList) LifecycleListener(org.apache.catalina.LifecycleListener) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster) ClusterListener(org.apache.catalina.ha.ClusterListener) Valve(org.apache.catalina.Valve) ClusterManager(org.apache.catalina.ha.ClusterManager)

Example 3 with CatalinaCluster

use of org.apache.catalina.ha.CatalinaCluster in project tomcat by apache.

the class DeltaSession method expire.

public void expire(boolean notify, boolean notifyCluster) {
    // isValid is false
    if (!isValid) {
        return;
    }
    synchronized (this) {
        // Double check locking - isValid needs to be volatile
        if (!isValid) {
            return;
        }
        if (manager == null) {
            return;
        }
        String expiredId = getIdInternal();
        if (notifyCluster && expiredId != null && manager instanceof DeltaManager) {
            DeltaManager dmanager = (DeltaManager) manager;
            CatalinaCluster cluster = dmanager.getCluster();
            ClusterMessage msg = dmanager.requestCompleted(expiredId, true);
            if (msg != null) {
                cluster.send(msg);
            }
        }
        super.expire(notify);
        if (notifyCluster) {
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("deltaSession.notifying", ((ClusterManager) manager).getName(), Boolean.valueOf(isPrimarySession()), expiredId));
            }
            if (manager instanceof DeltaManager) {
                ((DeltaManager) manager).sessionExpired(expiredId);
            }
        }
    }
}
Also used : CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) ClusterMessage(org.apache.catalina.ha.ClusterMessage) ClusterManager(org.apache.catalina.ha.ClusterManager)

Example 4 with CatalinaCluster

use of org.apache.catalina.ha.CatalinaCluster in project tomcat by apache.

the class ClusterSingleSignOn method startInternal.

// ------------------------------------------------------- Lifecycle Methods
/**
 * 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 {
    // Load the cluster component, if any
    try {
        if (cluster == null) {
            Container host = getContainer();
            if (host instanceof Host) {
                if (host.getCluster() instanceof CatalinaCluster) {
                    setCluster((CatalinaCluster) host.getCluster());
                }
            }
        }
        if (cluster == null) {
            throw new LifecycleException(sm.getString("clusterSingleSignOn.nocluster"));
        }
        ClassLoader[] cls = new ClassLoader[] { this.getClass().getClassLoader() };
        ReplicatedMap<String, SingleSignOnEntry> cache = new ReplicatedMap<>(this, cluster.getChannel(), rpcTimeout, cluster.getClusterName() + "-SSO-cache", cls, terminateOnStartFailure);
        cache.setChannelSendOptions(mapSendOptions);
        cache.setAccessTimeout(accessTimeout);
        this.cache = cache;
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        throw new LifecycleException(sm.getString("clusterSingleSignOn.clusterLoad.fail"), t);
    }
    super.startInternal();
}
Also used : Container(org.apache.catalina.Container) LifecycleException(org.apache.catalina.LifecycleException) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) SingleSignOnEntry(org.apache.catalina.authenticator.SingleSignOnEntry) Host(org.apache.catalina.Host) ReplicatedMap(org.apache.catalina.tribes.tipis.ReplicatedMap)

Example 5 with CatalinaCluster

use of org.apache.catalina.ha.CatalinaCluster in project tomcat by apache.

the class ReplicatedContext method startInternal.

/**
 * 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 {
    super.startInternal();
    try {
        CatalinaCluster catclust = (CatalinaCluster) this.getCluster();
        if (catclust != null) {
            ReplicatedMap<String, Object> map = new ReplicatedMap<>(this, catclust.getChannel(), DEFAULT_REPL_TIMEOUT, getName(), getClassLoaders());
            map.setChannelSendOptions(mapSendOptions);
            ((ReplApplContext) this.context).setAttributeMap(map);
        }
    } catch (Exception x) {
        log.error(sm.getString("replicatedContext.startUnable", getName()), x);
        throw new LifecycleException(sm.getString("replicatedContext.startFailed", getName()), x);
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) ReplicatedMap(org.apache.catalina.tribes.tipis.ReplicatedMap) LifecycleException(org.apache.catalina.LifecycleException)

Aggregations

CatalinaCluster (org.apache.catalina.ha.CatalinaCluster)9 LifecycleException (org.apache.catalina.LifecycleException)4 ReplicatedMap (org.apache.catalina.tribes.tipis.ReplicatedMap)4 Container (org.apache.catalina.Container)3 Host (org.apache.catalina.Host)2 SingleSignOnEntry (org.apache.catalina.authenticator.SingleSignOnEntry)2 ClusterManager (org.apache.catalina.ha.ClusterManager)2 ClusterMessage (org.apache.catalina.ha.ClusterMessage)2 SimpleTcpCluster (org.apache.catalina.ha.tcp.SimpleTcpCluster)2 ArrayList (java.util.ArrayList)1 Cluster (org.apache.catalina.Cluster)1 Context (org.apache.catalina.Context)1 LifecycleListener (org.apache.catalina.LifecycleListener)1 Valve (org.apache.catalina.Valve)1 ClusterDeployer (org.apache.catalina.ha.ClusterDeployer)1 ClusterListener (org.apache.catalina.ha.ClusterListener)1 Channel (org.apache.catalina.tribes.Channel)1 TomEEClusterListener (org.apache.tomee.catalina.cluster.TomEEClusterListener)1