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);
}
}
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());
}
}
}
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);
}
}
}
}
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();
}
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);
}
}
Aggregations