use of org.apache.tomee.catalina.cluster.TomEEClusterListener 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.tomee.catalina.cluster.TomEEClusterListener in project tomee by apache.
the class GlobalListenerSupport method lifecycleEvent.
/**
* {@inheritDoc}
*/
public void lifecycleEvent(final LifecycleEvent event) {
final Object source = event.getSource();
if (source instanceof StandardContext) {
final StandardContext standardContext = (StandardContext) source;
if (standardContext instanceof IgnoredStandardContext) {
return;
}
final String type = event.getType();
switch(// better than if cause it prevent duplicates
type) {
case INIT_EVENT:
case Lifecycle.BEFORE_INIT_EVENT:
contextListener.init(standardContext);
break;
case Lifecycle.BEFORE_START_EVENT:
contextListener.beforeStart(standardContext);
break;
case Lifecycle.START_EVENT:
standardContext.addParameter("openejb.start.late", "true");
contextListener.start(standardContext);
break;
case Lifecycle.AFTER_START_EVENT:
contextListener.afterStart(standardContext);
standardContext.removeParameter("openejb.start.late");
break;
case Lifecycle.BEFORE_STOP_EVENT:
contextListener.beforeStop(standardContext);
break;
case Lifecycle.STOP_EVENT:
contextListener.stop(standardContext);
break;
case Lifecycle.AFTER_STOP_EVENT:
contextListener.afterStop(standardContext);
break;
case DESTROY_EVENT:
case Lifecycle.AFTER_DESTROY_EVENT:
contextListener.destroy(standardContext);
break;
case Lifecycle.CONFIGURE_START_EVENT:
contextListener.configureStart(event, standardContext);
break;
default:
}
} else if (StandardHost.class.isInstance(source)) {
final StandardHost standardHost = (StandardHost) source;
final String type = event.getType();
if (Lifecycle.PERIODIC_EVENT.equals(type)) {
contextListener.checkHost(standardHost);
} else if (Lifecycle.AFTER_START_EVENT.equals(type) && REMOTE_SUPPORT) {
final TomEERemoteWebapp child = new TomEERemoteWebapp();
if (!hasChild(standardHost, child.getName())) {
standardHost.addChild(child);
}
// else old tomee webapp surely
}
} else if (StandardServer.class.isInstance(source)) {
final StandardServer standardServer = (StandardServer) source;
final String type = event.getType();
if (Lifecycle.START_EVENT.equals(type)) {
contextListener.start(standardServer);
}
if (Lifecycle.BEFORE_STOP_EVENT.equals(type)) {
TomcatHelper.setStopping(true);
final TomEEClusterListener tomEEClusterListener = SystemInstance.get().getComponent(TomEEClusterListener.class);
if (tomEEClusterListener != null) {
TomEEClusterListener.stop();
}
}
if (Lifecycle.AFTER_STOP_EVENT.equals(type)) {
contextListener.afterStop(standardServer);
}
}
// Notify
// here this way we are sure we get it even in embedded mode. TODO: we miss then few boot events, is it an issue.
SystemInstance.get().fireEvent(event);
}
use of org.apache.tomee.catalina.cluster.TomEEClusterListener in project tomee by apache.
the class SimpleTomEETcpCluster method checkDefaults.
@Override
protected void checkDefaults() {
final List<ClusterListener> currentListeners = clusterListeners;
final TomEEClusterListener tomEEClusterListener = SystemInstance.get().getComponent(TomEEClusterListener.class);
if (currentListeners.size() == 1 && currentListeners.iterator().next() == tomEEClusterListener) {
currentListeners.clear();
}
// else force the new cluster listener
for (final ClusterListener clusterListener : currentListeners) {
// we don't care about TomEEClusterListener since it is stateless
clusterListener.setCluster(this);
}
if (getClusterDeployer() != null) {
getClusterDeployer().setCluster(this);
}
super.checkDefaults();
// since that's a singleton and all listeners have to be unique (contains()) we can always add it
addClusterListener(tomEEClusterListener);
}
Aggregations