Author: remy.maucherat(a)jboss.com
Date: 2008-04-09 20:06:14 -0400 (Wed, 09 Apr 2008)
New Revision: 581
Modified:
trunk/build.xml
trunk/java/org/jboss/web/cluster/ClusterListener.java
Log:
- Add skeleton listener for cluster. Normally, this should be per engine configuration
(since engine holds
the jvmRoute), but ...
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2008-04-07 11:48:48 UTC (rev 580)
+++ trunk/build.xml 2008-04-10 00:06:14 UTC (rev 581)
@@ -48,7 +48,7 @@
<property name="el-api.jar"
value="${tomcat.build}/lib/el-api.jar"/>
<property name="catalina.jar"
value="${tomcat.build}/lib/catalina.jar"/>
<property name="catalina-ant.jar"
value="${tomcat.build}/lib/catalina-ant.jar"/>
- <property name="catalina-ant-jmx.jar"
value="${tomcat.build}/lib/catalina-ant-jmx.jar"/>
+ <property name="catalina-optional.jar"
value="${tomcat.build}/lib/catalina-optional.jar"/>
<property name="tomcat-coyote.jar"
value="${tomcat.build}/lib/tomcat-coyote.jar"/>
<property name="jasper.jar"
value="${tomcat.build}/lib/jasper.jar"/>
Modified: trunk/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-04-07 11:48:48 UTC (rev
580)
+++ trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-04-10 00:06:14 UTC (rev
581)
@@ -24,31 +24,30 @@
package org.jboss.web.cluster;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
+import org.apache.catalina.Container;
+import org.apache.catalina.ContainerEvent;
+import org.apache.catalina.ContainerListener;
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Server;
+import org.apache.catalina.Service;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardContext;
import org.apache.catalina.util.StringManager;
-import org.apache.tomcat.jni.Library;
import org.jboss.logging.Logger;
-import org.jboss.logging.Logger;
/**
- * Implementation of <code>LifecycleListener</code> that will init and
- * and destroy APR.
- *
- * @author Remy Maucherat
- * @author Filip Hanik
- * @version $Revision: 515 $ $Date: 2008-03-17 22:02:23 +0100 (Mon, 17 Mar 2008) $
- * @since 4.1
+ *
*/
public class ClusterListener
- implements LifecycleListener {
+ implements LifecycleListener, ContainerListener {
private static Logger log = Logger.getLogger(ClusterListener.class);
@@ -65,6 +64,39 @@
// ---------------------------------------------- Properties
+ /**
+ * Acknowledge the occurrence of the specified event.
+ * Note: Will never be called when the listener is associated to a Server,
+ * since it is not a Container.
+ *
+ * @param event ContainerEvent that has occurred
+ */
+ public void containerEvent(ContainerEvent event) {
+
+ Container container = event.getContainer();
+ Object child = event.getData();
+ String type = event.getType();
+
+ if (type.equals(Container.ADD_CHILD_EVENT)) {
+ if (container instanceof Host) {
+ // Deploying a webapp
+ addContext((Context) child);
+ } else if (container instanceof Engine) {
+ // Deploying a host
+ container.addContainerListener(this);
+ }
+ } else if (type.equals(Container.REMOVE_CHILD_EVENT)) {
+ if (container instanceof Host) {
+ // Undeploying a webapp
+ removeContext((Context) child);
+ } else if (container instanceof Engine) {
+ // Undeploying a host
+ container.removeContainerListener(this);
+ }
+ }
+
+ }
+
// ---------------------------------------------- LifecycleListener Methods
/**
@@ -74,12 +106,101 @@
*/
public void lifecycleEvent(LifecycleEvent event) {
+ Object source = event.getLifecycle();
+
if (Lifecycle.START_EVENT.equals(event.getType())) {
-
+ if (source instanceof Context) {
+ // Start a webapp
+ startContext((Context) source);
+ } else if (source instanceof Server) {
+ Service[] services = ((Server) source).findServices();
+ for (int i = 0; i < services.length; i++) {
+ services[i].getContainer().addContainerListener(this);
+ ((Lifecycle) services[i].getContainer()).addLifecycleListener(this);
+ config((Engine) services[i].getContainer());
+ Container[] children = services[i].getContainer().findChildren();
+ for (int j = 0; j < children.length; j++) {
+ children[j].addContainerListener(this);
+ Container[] children2 = children[j].findChildren();
+ for (int k = 0; k < children2.length; k++) {
+ addContext((Context) children2[k]);
+ }
+ }
+ }
+ } else {
+ return;
+ }
} else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
-
+ if (source instanceof Context) {
+ // Stop a webapp
+ stopContext((Context) source);
+ } else if (source instanceof Server) {
+ Service[] services = ((Server) source).findServices();
+ for (int i = 0; i < services.length; i++) {
+ services[i].getContainer().removeContainerListener(this);
+ Container[] children = services[i].getContainer().findChildren();
+ for (int j = 0; j < children.length; j++) {
+ children[j].removeContainerListener(this);
+ Container[] children2 = children[j].findChildren();
+ for (int k = 0; k < children2.length; k++) {
+ removeContext((Context) children2[k]);
+ }
+ }
+ }
+ } else {
+ return;
+ }
+ } else if (Lifecycle.PERIODIC_EVENT.equals(event.getType())) {
+ if (source instanceof Engine) {
+ status((Engine) source);
+ }
}
}
+
+
+ protected void config(Engine engine) {
+ System.out.println("Config: " + engine.getName());
+ // FIXME: collect configuration from the connectors and service and call CONFIG
+ Service service = engine.getService();
+ Connector[] connectors = service.findConnectors();
+ }
+
+ protected void status(Engine engine) {
+ System.out.println("Status: " + engine.getName());
+ // FIXME: send STATUS
+ Service service = engine.getService();
+ Connector[] connectors = service.findConnectors();
+ }
+
+
+ protected void addContext(Context context) {
+ System.out.println("Deploy context: " + context.getPath() + " to
Host: " + context.getParent().getName() + " State: " + ((StandardContext)
context).getState());
+ ((Lifecycle) context).addLifecycleListener(this);
+ // FIXME: send ENABLE-APP if state is started
+ }
+
+
+ protected void removeContext(Context context) {
+ System.out.println("Undeploy context: " + context.getPath() + " to
Host: " + context.getParent().getName() + " State: " + ((StandardContext)
context).getState());
+ ((Lifecycle) context).removeLifecycleListener(this);
+ // FIXME: send REMOVE-APP
+ }
+
+
+ protected void startContext(Context context) {
+ Container parent = context.getParent();
+ System.out.println("Start context: " + context.getPath() + " to
Host: " + parent.getName());
+ // FIXME: send ENABLE-APP
+ }
+
+
+ protected void stopContext(Context context) {
+ Container parent = context.getParent();
+ System.out.println("Stop context: " + context.getPath() + " to
Host: " + parent.getName());
+ // FIXME: send STOP-APP
+ }
+
+
}
Show replies by date