JBoss Native SVN: r2238 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-28 12:05:27 -0500 (Wed, 28 Jan 2009)
New Revision: 2238
Modified:
trunk/build/unix/build.sh
Log:
Remove the buildfromtar.sh... It doesn't work and would take ages
Modified: trunk/build/unix/build.sh
===================================================================
--- trunk/build/unix/build.sh 2009-01-28 14:31:16 UTC (rev 2237)
+++ trunk/build/unix/build.sh 2009-01-28 17:05:27 UTC (rev 2238)
@@ -1197,11 +1197,12 @@
fi
# try to build from the source tarball
- override ${build_top}/util/buildfromtar ${TMPROOTBASE}/src ${build_output_dir} ${package_src_name} ${BUILD_WIN} ${has_ssl} ${build_version} ${PACKAGE}
- if [ $? -ne 0 ]; then
- echo "buildfromtar in ${TMPROOTBASE}/src failed"
- exit 1
- fi
+#JFC override ${build_top}/util/buildfromtar ${TMPROOTBASE}/src ${build_output_dir} ${package_src_name} ${BUILD_WIN} ${has_ssl} ${build_version} ${PACKAGE}
+#JFC if [ $? -ne 0 ]; then
+#JFC echo "buildfromtar in ${TMPROOTBASE}/src failed"
+#JFC exit 1
+#JFC fi
+
fi
echo ""
echo "SUCCESS : `basename $0` $LastChangedDate$"
15 years, 11 months
JBoss Native SVN: r2237 - trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2009-01-28 09:31:16 -0500 (Wed, 28 Jan 2009)
New Revision: 2237
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ReceiveTrafficLoadMetricTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SendTrafficLoadMetricTestCase.java
Log:
Improve reliability of test via more precise sleeping.
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ReceiveTrafficLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ReceiveTrafficLoadMetricTestCase.java 2009-01-28 14:25:11 UTC (rev 2236)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/ReceiveTrafficLoadMetricTestCase.java 2009-01-28 14:31:16 UTC (rev 2237)
@@ -49,18 +49,30 @@
EasyMock.replay(this.server);
+ long start = System.currentTimeMillis();
+
double load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
+
+ Assert.assertEquals(0, load, 0);
+
EasyMock.reset(this.server);
- Thread.sleep(500);
-
EasyMock.expect(this.server.getAttribute(this.name1, ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(1000L);
EasyMock.expect(this.server.getAttribute(this.name2, ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2000L);
EasyMock.replay(this.server);
+
+ long sleep = 500 - (System.currentTimeMillis() - start);
+ if (sleep > 0)
+ {
+ Thread.sleep(sleep);
+ }
+
+ start = System.currentTimeMillis();
+
load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
@@ -69,13 +81,18 @@
EasyMock.reset(this.server);
- Thread.sleep(500);
-
EasyMock.expect(this.server.getAttribute(this.name1, ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2000L);
EasyMock.expect(this.server.getAttribute(this.name2, ReceiveTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(3000L);
EasyMock.replay(this.server);
+ sleep = 500 - (System.currentTimeMillis() - start);
+
+ if (sleep > 0)
+ {
+ Thread.sleep(sleep);
+ }
+
load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java 2009-01-28 14:25:11 UTC (rev 2236)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java 2009-01-28 14:31:16 UTC (rev 2237)
@@ -58,6 +58,11 @@
Assert.assertEquals(0, load, 0);
EasyMock.reset(this.server);
+
+ EasyMock.expect(this.server.getAttribute(this.name1, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(1);
+ EasyMock.expect(this.server.getAttribute(this.name2, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2);
+
+ EasyMock.replay(this.server);
long sleep = 500 - (System.currentTimeMillis() - start);
@@ -65,11 +70,6 @@
{
Thread.sleep(sleep);
}
-
- EasyMock.expect(this.server.getAttribute(this.name1, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(1);
- EasyMock.expect(this.server.getAttribute(this.name2, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2);
-
- EasyMock.replay(this.server);
start = System.currentTimeMillis();
@@ -81,6 +81,12 @@
EasyMock.reset(this.server);
+ // Test incremental load
+ EasyMock.expect(this.server.getAttribute(this.name1, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2);
+ EasyMock.expect(this.server.getAttribute(this.name2, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(3);
+
+ EasyMock.replay(this.server);
+
sleep = 500 - (System.currentTimeMillis() - start);
if (sleep > 0)
@@ -88,12 +94,6 @@
Thread.sleep(sleep);
}
- // Test incremental load
- EasyMock.expect(this.server.getAttribute(this.name1, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2);
- EasyMock.expect(this.server.getAttribute(this.name2, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(3);
-
- EasyMock.replay(this.server);
-
load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SendTrafficLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SendTrafficLoadMetricTestCase.java 2009-01-28 14:25:11 UTC (rev 2236)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/SendTrafficLoadMetricTestCase.java 2009-01-28 14:31:16 UTC (rev 2237)
@@ -49,18 +49,30 @@
EasyMock.replay(this.server);
+ long start = System.currentTimeMillis();
+
double load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
+
+ Assert.assertEquals(0, load, 0);
+
EasyMock.reset(this.server);
- Thread.sleep(500);
-
EasyMock.expect(this.server.getAttribute(this.name1, SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(1000L);
EasyMock.expect(this.server.getAttribute(this.name2, SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2000L);
EasyMock.replay(this.server);
+ long sleep = 500 - (System.currentTimeMillis() - start);
+
+ if (sleep > 0)
+ {
+ Thread.sleep(sleep);
+ }
+
+ start = System.currentTimeMillis();
+
load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
@@ -69,13 +81,18 @@
EasyMock.reset(this.server);
- Thread.sleep(500);
-
EasyMock.expect(this.server.getAttribute(this.name1, SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2000L);
EasyMock.expect(this.server.getAttribute(this.name2, SendTrafficLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(3000L);
EasyMock.replay(this.server);
+ sleep = 500 - (System.currentTimeMillis() - start);
+
+ if (sleep > 0)
+ {
+ Thread.sleep(sleep);
+ }
+
load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
15 years, 11 months
JBoss Native SVN: r2236 - trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2009-01-28 09:25:11 -0500 (Wed, 28 Jan 2009)
New Revision: 2236
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java
Log:
Improve reliability of test via more precise sleeping.
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java 2009-01-28 10:54:00 UTC (rev 2235)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/metric/RequestCountLoadMetricTestCase.java 2009-01-28 14:25:11 UTC (rev 2236)
@@ -49,17 +49,29 @@
EasyMock.replay(this.server);
+ long start = System.currentTimeMillis();
+
double load = this.metric.getLoad(this.context);
EasyMock.verify(this.server);
+
+ Assert.assertEquals(0, load, 0);
+
EasyMock.reset(this.server);
+
+ long sleep = 500 - (System.currentTimeMillis() - start);
- Thread.sleep(500);
+ if (sleep > 0)
+ {
+ Thread.sleep(sleep);
+ }
EasyMock.expect(this.server.getAttribute(this.name1, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(1);
EasyMock.expect(this.server.getAttribute(this.name2, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2);
EasyMock.replay(this.server);
+
+ start = System.currentTimeMillis();
load = this.metric.getLoad(this.context);
@@ -69,8 +81,13 @@
EasyMock.reset(this.server);
- Thread.sleep(500);
+ sleep = 500 - (System.currentTimeMillis() - start);
+ if (sleep > 0)
+ {
+ Thread.sleep(sleep);
+ }
+
// Test incremental load
EasyMock.expect(this.server.getAttribute(this.name1, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(2);
EasyMock.expect(this.server.getAttribute(this.name2, RequestCountLoadMetric.DEFAULT_ATTRIBUTE)).andReturn(3);
15 years, 11 months
JBoss Native SVN: r2235 - trunk/mod_cluster/test/java.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-28 05:54:00 -0500 (Wed, 28 Jan 2009)
New Revision: 2235
Modified:
trunk/mod_cluster/test/java/build.xml
Log:
Oops the build always fails otherwise :-(
Modified: trunk/mod_cluster/test/java/build.xml
===================================================================
--- trunk/mod_cluster/test/java/build.xml 2009-01-28 08:53:54 UTC (rev 2234)
+++ trunk/mod_cluster/test/java/build.xml 2009-01-28 10:54:00 UTC (rev 2235)
@@ -126,15 +126,20 @@
<!-- Run the tests -->
<target name="tests" depends="compile">
<copy file="conf/web.xml" todir="${test.classes}/conf"/>
- <java dir="${test.classes}" classname="${test.runner}" fork="yes" resultproperty="test.failure">
+ <java dir="${test.classes}" classname="${test.runner}" fork="yes">
<arg value="org.jboss.mod_cluster.Maintest"/>
<jvmarg line="-Dcluster=${cluster}"/>
<classpath refid="tomcat.test.classpath"/>
</java>
</target>
<target name="all" depends="compile,httpd">
- <antcall target="tests">
- </antcall>
+ <!-- That is like test but it sets test.failure to make sure we stop httpd even in case of errors -->
+ <copy file="conf/web.xml" todir="${test.classes}/conf"/>
+ <java dir="${test.classes}" classname="${test.runner}" fork="yes" resultproperty="test.failure">
+ <arg value="org.jboss.mod_cluster.Maintest"/>
+ <jvmarg line="-Dcluster=${cluster}"/>
+ <classpath refid="tomcat.test.classpath"/>
+ </java>
<antcall target="stophttpd">
</antcall>
15 years, 11 months
JBoss Native SVN: r2234 - trunk/mod_cluster/test/java.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-28 03:53:54 -0500 (Wed, 28 Jan 2009)
New Revision: 2234
Modified:
trunk/mod_cluster/test/java/installhttpd.sh
Log:
The "postinstall" logic also need to be called when install from a directory.
Modified: trunk/mod_cluster/test/java/installhttpd.sh
===================================================================
--- trunk/mod_cluster/test/java/installhttpd.sh 2009-01-28 07:36:50 UTC (rev 2233)
+++ trunk/mod_cluster/test/java/installhttpd.sh 2009-01-28 08:53:54 UTC (rev 2234)
@@ -146,13 +146,30 @@
rm -rf "$BASELOC/$BASEHTTPD"
case ${EXT} in
file)
- rm -rf $BASELOC/opt
- cp -rp $root/opt $BASELOC
+ cp -rp $root/* $BASELOC
+ case $BUILD_TAG in
+ *windows*)
+ EXT=zip
+ ;;
+ *)
+ EXT=tar.gz
+ ;;
+ esac
;;
tar.gz)
(cd $BASELOC
gzip -dc ${TARBALL} | tar xvf -
)
+ ;;
+ *)
+ (cd "$BASELOC"
+ unzip ${TARBALL}
+ )
+ ;;
+esac
+
+case ${EXT} in
+ tar.gz)
# Arrange the installed files
files="${BASEHTTPDSBIN}/apachectl ${BASEHTTPDCONF}/httpd.conf ${BASEHTTPDSBIN}/envvars"
for FILE in `echo $files`
@@ -173,9 +190,6 @@
mv $file.new $file
;;
*)
- (cd "$BASELOC"
- unzip ${TARBALL}
- )
# Arrange the installed files
(cd "$BASELOC/httpd-2.2/bin"
./installconf.bat
15 years, 11 months
JBoss Native SVN: r2233 - trunk/mod_cluster/test/java.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-28 02:36:50 -0500 (Wed, 28 Jan 2009)
New Revision: 2233
Modified:
trunk/mod_cluster/test/java/installhttpd.sh
Log:
Arrange locations.
Modified: trunk/mod_cluster/test/java/installhttpd.sh
===================================================================
--- trunk/mod_cluster/test/java/installhttpd.sh 2009-01-27 22:42:39 UTC (rev 2232)
+++ trunk/mod_cluster/test/java/installhttpd.sh 2009-01-28 07:36:50 UTC (rev 2233)
@@ -133,8 +133,8 @@
rm -f ${PACKAGE}-${BUILD_SYS}-${BUILD_CPU}.${EXT}
ant downloadfile -Dsourcefile=${TARBALL} -Ddestfile=${PACKAGE}-${BUILD_SYS}-${BUILD_CPU}.${EXT} -Ddestdir=$BASELOC
else
- echo "Using $root/${PACKAGE}-${BUILD_SYS}-${BUILD_CPU}.${EXT}"
- cp -p $root/${PACKAGE}-${BUILD_SYS}-${BUILD_CPU}.${EXT} .
+ echo "Using $root"
+ EXT=file
fi
fi
TARBALL=`pwd`/${PACKAGE}-${BUILD_SYS}-${BUILD_CPU}.${EXT}
@@ -145,6 +145,10 @@
# Clean previous install
rm -rf "$BASELOC/$BASEHTTPD"
case ${EXT} in
+ file)
+ rm -rf $BASELOC/opt
+ cp -rp $root/opt $BASELOC
+ ;;
tar.gz)
(cd $BASELOC
gzip -dc ${TARBALL} | tar xvf -
15 years, 11 months
JBoss Native SVN: r2232 - trunk/mod_cluster/src/main/java/org/jboss/modcluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2009-01-27 17:42:39 -0500 (Tue, 27 Jan 2009)
New Revision: 2232
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandlerAdapter.java
Log:
javadoc fix
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandlerAdapter.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandlerAdapter.java 2009-01-27 22:10:03 UTC (rev 2231)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandlerAdapter.java 2009-01-27 22:42:39 UTC (rev 2232)
@@ -34,7 +34,7 @@
import org.apache.catalina.Service;
/**
- * Adapts lifecycle and container listener events to the {@link JBossWebEventHandler} interface.
+ * Adapts lifecycle and container listener events to the {@link ContainerEventHandler} interface.
*/
public class CatalinaEventHandlerAdapter implements LifecycleListener, ContainerListener
{
15 years, 11 months
JBoss Native SVN: r2231 - trunk/mod_cluster/test/java/org/jboss/mod_cluster.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-27 17:10:03 -0500 (Tue, 27 Jan 2009)
New Revision: 2231
Modified:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyForce.java
Log:
Change the ports to prevent "address in use problems".
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyForce.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyForce.java 2009-01-27 21:45:18 UTC (rev 2230)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestStickyForce.java 2009-01-27 22:10:03 UTC (rev 2231)
@@ -58,11 +58,11 @@
// server = (StandardServer) ServerFactory.getServer();
service = new JBossWeb("sticky3", "localhost");
- connector = service.addConnector(8009);
+ connector = service.addConnector(8012);
server.addService(service);
service2 = new JBossWeb("sticky4", "localhost");
- connector2 = service2.addConnector(8010);
+ connector2 = service2.addConnector(8011);
server.addService(service2);
cluster = Maintest.createClusterListener("232.0.0.2", 23364, false);
@@ -110,10 +110,10 @@
if ("sticky4".equals(node)) {
connector = connector2;
node = "sticky3";
- port = 8010;
+ port = 8011;
} else {
node = "sticky4";
- port = 8009;
+ port = 8012;
}
if (connector != null) {
try {
@@ -169,8 +169,8 @@
System.out.println("Can't stop...");
}
- Maintest.testPort(8009);
- Maintest.testPort(8010);
+ Maintest.testPort(8012);
+ Maintest.testPort(8011);
// Test client result.
if ( !clienterror && client.httpResponseCode != 503 )
15 years, 11 months
JBoss Native SVN: r2230 - trunk/mod_cluster/test/java.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-01-27 16:45:18 -0500 (Tue, 27 Jan 2009)
New Revision: 2230
Modified:
trunk/mod_cluster/test/java/build.xml
Log:
Allow a tests target just to run the tests.
Modified: trunk/mod_cluster/test/java/build.xml
===================================================================
--- trunk/mod_cluster/test/java/build.xml 2009-01-27 21:41:00 UTC (rev 2229)
+++ trunk/mod_cluster/test/java/build.xml 2009-01-27 21:45:18 UTC (rev 2230)
@@ -124,13 +124,18 @@
</target>
<!-- Run the tests -->
- <target name="all" depends="compile,httpd">
+ <target name="tests" depends="compile">
<copy file="conf/web.xml" todir="${test.classes}/conf"/>
<java dir="${test.classes}" classname="${test.runner}" fork="yes" resultproperty="test.failure">
<arg value="org.jboss.mod_cluster.Maintest"/>
<jvmarg line="-Dcluster=${cluster}"/>
<classpath refid="tomcat.test.classpath"/>
</java>
+ </target>
+ <target name="all" depends="compile,httpd">
+ <antcall target="tests">
+ </antcall>
+
<antcall target="stophttpd">
</antcall>
15 years, 11 months
JBoss Native SVN: r2229 - in trunk/mod_cluster/src: main/java/org/jboss/modcluster/ha and 5 other directories.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2009-01-27 16:41:00 -0500 (Tue, 27 Jan 2009)
New Revision: 2229
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandlerAdapter.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ContainerEventHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ServerProvider.java
Removed:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandlerAdapter.java
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/JBossWebEventHandlerAdapterTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterServiceTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java
Log:
Create ServerProvider<S> - eliminating problematic references to static org.apache.catalina.ServerFactory.getServer() method
This also makes it easier for objects like ResetRequestSource to reference the Server instance
Preliminary refactoring for supporting other containers:
JBossWebEventHandler -> ContainerEventHandler<Server, Engine, Context>
DefaultJBossWebJBossEventHandler -> CatalinaEventHandler
JBossWebEventHandlerAdapter -> CatalinaEventHandlerAdapter
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -21,10 +21,11 @@
*/
package org.jboss.modcluster;
+import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Server;
import org.apache.catalina.Service;
import org.jboss.modcluster.advertise.impl.AdvertiseListenerFactoryImpl;
import org.jboss.modcluster.config.ModClusterConfig;
@@ -42,34 +43,46 @@
* @author Paul Ferraro
*/
public abstract class AbstractModClusterService extends ModClusterConfig
- implements LifecycleListener, LoadBalanceFactorProviderFactory, ModClusterServiceMBean
+ implements LifecycleListener, LoadBalanceFactorProviderFactory, ModClusterServiceMBean, ServerProvider<Server>
{
private final MCMPHandler mcmpHandler;
private final LifecycleListener lifecycleListener;
private final MCMPRequestFactory requestFactory;
+ private final ServerProvider<Server> serverProvider;
public AbstractModClusterService()
{
this.requestFactory = new DefaultMCMPRequestFactory();
- ResetRequestSource source = new ResetRequestSourceImpl(this, this, this.requestFactory);
+ ResetRequestSource source = new ResetRequestSourceImpl(this, this, this, this.requestFactory);
this.mcmpHandler = new DefaultMCMPHandler(this, source, this.requestFactory);
- JBossWebEventHandler eventHandler = new DefaultJBossWebEventHandler(this, this, this, this.mcmpHandler, source, this.requestFactory, this, new AdvertiseListenerFactoryImpl());
+ ContainerEventHandler<Server, Engine, Context> eventHandler = new CatalinaEventHandler(this, this, this, this.mcmpHandler, source, this.requestFactory, this, new AdvertiseListenerFactoryImpl());
- this.lifecycleListener = new JBossWebEventHandlerAdapter(eventHandler);
+ this.serverProvider = eventHandler;
+ this.lifecycleListener = new CatalinaEventHandlerAdapter(eventHandler);
}
- protected AbstractModClusterService(MCMPHandler mcmpHandler, MCMPRequestFactory requestFactory, LifecycleListener lifecycleListener)
+ protected AbstractModClusterService(MCMPHandler mcmpHandler, MCMPRequestFactory requestFactory, ServerProvider<Server> serverProvider, LifecycleListener lifecycleListener)
{
this.mcmpHandler = mcmpHandler;
this.requestFactory = requestFactory;
+ this.serverProvider = serverProvider;
this.lifecycleListener = lifecycleListener;
}
/**
* @{inheritDoc}
+ * @see org.jboss.modcluster.ServerProvider#getServer()
+ */
+ public Server getServer()
+ {
+ return this.serverProvider.getServer();
+ }
+
+ /**
+ * @{inheritDoc}
* @see org.apache.catalina.LifecycleListener#lifecycleEvent(org.apache.catalina.LifecycleEvent)
*/
public void lifecycleEvent(LifecycleEvent event)
@@ -138,7 +151,7 @@
*/
public boolean disable()
{
- for (Service service: ServerFactory.getServer().findServices())
+ for (Service service: this.serverProvider.getServer().findServices())
{
Engine engine = (Engine) service.getContainer();
// Send DISABLE-APP * request
@@ -155,7 +168,7 @@
*/
public boolean enable()
{
- for (Service service: ServerFactory.getServer().findServices())
+ for (Service service: this.serverProvider.getServer().findServices())
{
Engine engine = (Engine) service.getContainer();
// Send ENABLE-APP * request
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandler.java (from rev 2225, trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandler.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandler.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -0,0 +1,360 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.modcluster;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Server;
+import org.apache.catalina.Service;
+import org.apache.catalina.util.StringManager;
+import org.jboss.logging.Logger;
+import org.jboss.modcluster.advertise.AdvertiseListener;
+import org.jboss.modcluster.advertise.AdvertiseListenerFactory;
+import org.jboss.modcluster.config.BalancerConfiguration;
+import org.jboss.modcluster.config.MCMPHandlerConfiguration;
+import org.jboss.modcluster.config.NodeConfiguration;
+import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+import org.jboss.modcluster.load.LoadBalanceFactorProviderFactory;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPRequestFactory;
+import org.jboss.modcluster.mcmp.ResetRequestSource;
+
+/**
+ * Default implementation of {@link JBossWebEventHandler}.
+ *
+ * @author Brian Stansberry
+ */
+public class CatalinaEventHandler implements ContainerEventHandler<Server, Engine, Context>
+{
+ static final Logger log = Logger.getLogger(CatalinaEventHandler.class);
+
+ // ----------------------------------------------------------------- Fields
+
+ /**
+ * The string manager for this package.
+ */
+ private final StringManager sm = StringManager.getManager(Constants.Package);
+ private final NodeConfiguration nodeConfig;
+ private final BalancerConfiguration balancerConfig;
+ private final MCMPHandlerConfiguration mcmpConfig;
+ private final MCMPHandler mcmpHandler;
+ private final ResetRequestSource source;
+ private final MCMPRequestFactory requestFactory;
+ private final AdvertiseListenerFactory listenerFactory;
+ private final LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory;
+
+ private volatile Server server = null;
+
+ private volatile LoadBalanceFactorProvider loadBalanceFactorProvider;
+ private volatile AdvertiseListener advertiseListener;
+ private volatile Map<String, Set<String>> excludedContextPaths;
+
+ public CatalinaEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
+ MCMPHandlerConfiguration mcmpConfig, MCMPHandler mcmpHandler, ResetRequestSource source,
+ MCMPRequestFactory requestFactory, LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory,
+ AdvertiseListenerFactory listenerFactory)
+ {
+ this.nodeConfig = nodeConfig;
+ this.balancerConfig = balancerConfig;
+ this.mcmpConfig = mcmpConfig;
+ this.mcmpHandler = mcmpHandler;
+ this.source = source;
+ this.requestFactory = requestFactory;
+ this.loadBalanceFactorProviderFactory = loadBalanceFactorProviderFactory;
+ this.listenerFactory = listenerFactory;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ServerProvider#getServer()
+ */
+ public Server getServer()
+ {
+ return this.server;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ContainerEventHandler#init(java.lang.Object)
+ */
+ public synchronized void init(Server server)
+ {
+ List<InetSocketAddress> initialProxies = Utils.parseProxies(this.mcmpConfig.getProxyList());
+
+ this.mcmpHandler.init(initialProxies);
+
+ this.excludedContextPaths = Utils.parseContexts(this.mcmpConfig.getExcludedContexts());
+
+ this.source.init(this.excludedContextPaths);
+
+ this.loadBalanceFactorProvider = this.loadBalanceFactorProviderFactory.createLoadBalanceFactorProvider();
+
+ Boolean advertise = this.mcmpConfig.getAdvertise();
+
+ if (Boolean.TRUE.equals(advertise) || (advertise == null && initialProxies.isEmpty()))
+ {
+ this.advertiseListener = this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig);
+
+ try
+ {
+ this.advertiseListener.start();
+ }
+ catch (IOException e)
+ {
+ // TODO What now?
+ log.error(e.getMessage(), e);
+ }
+ }
+
+ this.server = server;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ContainerEventHandler#shutdown()
+ */
+ public synchronized void shutdown()
+ {
+ this.server = null;
+
+ if (this.advertiseListener != null)
+ {
+ try
+ {
+ this.advertiseListener.destroy();
+ }
+ catch (IOException e)
+ {
+ log.error(this.sm.getString("modcluster.error.stopListener"), e);
+ }
+
+ this.advertiseListener = null;
+ }
+
+ this.mcmpHandler.shutdown();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ContainerEventHandler#startServer(java.lang.Object)
+ */
+ public void startServer(Server server)
+ {
+ this.checkInit();
+
+ for (Service service: server.findServices())
+ {
+ Engine engine = (Engine) service.getContainer();
+
+ this.config(engine);
+
+ for (Container host: engine.findChildren())
+ {
+ for (Container context: host.findChildren())
+ {
+ this.addContext((Context) context);
+ }
+ }
+ }
+ }
+
+ /**
+ * Send commands to the front end server associated with the shutdown of the
+ * node.
+ */
+ public void stopServer(Server server)
+ {
+ this.checkInit();
+
+ for (Service service: server.findServices())
+ {
+ Engine engine = (Engine) service.getContainer();
+
+ for (Container host: engine.findChildren())
+ {
+ for (Container context: host.findChildren())
+ {
+ this.removeContext((Context) context);
+ }
+ }
+
+ this.removeAll(engine);
+ }
+ }
+
+ protected void config(Engine engine)
+ {
+ this.config(engine, this.mcmpHandler);
+ }
+
+ protected void config(Engine engine, MCMPHandler mcmpHandler)
+ {
+ log.debug(this.sm.getString("modcluster.engine.config", engine.getName()));
+
+ // If needed, create automagical JVM route (address + port + engineName)
+ try
+ {
+ Utils.establishJvmRouteAndConnectorAddress(engine, mcmpHandler);
+
+ this.jvmRouteEstablished(engine);
+
+ MCMPRequest request = this.requestFactory.createConfigRequest(engine, this.nodeConfig, this.balancerConfig);
+
+ this.mcmpHandler.sendRequest(request);
+ }
+ catch (Exception e)
+ {
+ mcmpHandler.markProxiesInError();
+
+ log.info(this.sm.getString("modcluster.error.addressJvmRoute"), e);
+ }
+ }
+
+ protected void jvmRouteEstablished(Engine engine)
+ {
+ // Do nothing
+ }
+
+ public void addContext(Context context)
+ {
+ this.checkInit();
+
+ if (!this.exclude(context))
+ {
+ // Send ENABLE-APP if state is started
+ if (Utils.isContextStarted(context))
+ {
+ log.debug(this.sm.getString("modcluster.context.enable", context.getPath(), context.getParent().getName()));
+
+ MCMPRequest request = this.requestFactory.createEnableRequest(context);
+
+ this.mcmpHandler.sendRequest(request);
+ }
+ }
+ }
+
+ public void startContext(Context context)
+ {
+ this.checkInit();
+
+ if (!this.exclude(context))
+ {
+ log.debug(this.sm.getString("modcluster.context.start", context.getPath(), context.getParent().getName()));
+
+ // Send ENABLE-APP
+ MCMPRequest request = this.requestFactory.createEnableRequest(context);
+
+ this.mcmpHandler.sendRequest(request);
+ }
+ }
+
+ public void stopContext(Context context)
+ {
+ this.checkInit();
+
+ if (!this.exclude(context))
+ {
+ log.debug(this.sm.getString("modcluster.context.stop", context.getPath(), context.getParent().getName()));
+
+ // Send STOP-APP
+ MCMPRequest request = this.requestFactory.createStopRequest(context);
+
+ this.mcmpHandler.sendRequest(request);
+ }
+ }
+
+ public void removeContext(Context context)
+ {
+ this.checkInit();
+
+ if (!this.exclude(context))
+ {
+ // JVMRoute can be null here if nothing was ever initialized
+ if (Utils.getJvmRoute(context) != null)
+ {
+ log.debug(this.sm.getString("modcluster.context.disable", context.getPath(), context.getParent().getName()));
+
+ MCMPRequest request = this.requestFactory.createRemoveRequest(context);
+
+ this.mcmpHandler.sendRequest(request);
+ }
+ }
+ }
+
+ protected void removeAll(Engine engine)
+ {
+ // JVMRoute can be null here if nothing was ever initialized
+ if (engine.getJvmRoute() != null)
+ {
+ log.debug(this.sm.getString("modcluster.engine.stop", engine.getName()));
+
+ // Send REMOVE-APP * request
+ MCMPRequest request = this.requestFactory.createRemoveRequest(engine);
+
+ this.mcmpHandler.sendRequest(request);
+ }
+ }
+
+ public void status(Engine engine)
+ {
+ this.checkInit();
+
+ log.debug(this.sm.getString("modcluster.engine.status", engine.getName()));
+
+ this.mcmpHandler.status();
+
+ // Send STATUS request
+ int lbf = this.getLoadBalanceFactor();
+ MCMPRequest request = this.requestFactory.createStatusRequest(engine.getJvmRoute(), lbf);
+
+ this.mcmpHandler.sendRequest(request);
+ }
+
+ protected int getLoadBalanceFactor()
+ {
+ return this.loadBalanceFactorProvider.getLoadBalanceFactor();
+ }
+
+ protected void checkInit()
+ {
+ if (this.server == null)
+ {
+ throw new IllegalStateException(this.sm.getString("modcluster.error.uninitialized"));
+ }
+ }
+
+ private boolean exclude(Context context)
+ {
+ Set<String> excludedPaths = this.excludedContextPaths.get(context.getParent().getName());
+
+ return (excludedPaths != null) ? excludedPaths.contains(context.getPath()) : false;
+ }
+}
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandlerAdapter.java (from rev 2225, trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandlerAdapter.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandlerAdapter.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/CatalinaEventHandlerAdapter.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.modcluster;
+
+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;
+
+/**
+ * Adapts lifecycle and container listener events to the {@link JBossWebEventHandler} interface.
+ */
+public class CatalinaEventHandlerAdapter implements LifecycleListener, ContainerListener
+{
+ /** Initialization flag. */
+ private volatile boolean init = false;
+
+ private ContainerEventHandler<Server, Engine, Context> eventHandler;
+
+ // ----------------------------------------------------------- Constructors
+
+ public CatalinaEventHandlerAdapter(ContainerEventHandler<Server, Engine, Context> eventHandler)
+ {
+ this.eventHandler = eventHandler;
+ }
+
+ // ------------------------------------------------------------- Properties
+
+ // ---------------------------------------------- LifecycleListener Methods
+
+ /**
+ * 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
+ ((Lifecycle) child).addLifecycleListener(this);
+ this.eventHandler.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
+ ((Lifecycle) child).removeLifecycleListener(this);
+ this.eventHandler.removeContext((Context) child);
+ }
+ else if (container instanceof Engine)
+ {
+ // Undeploying a host
+ container.removeContainerListener(this);
+ }
+ }
+ }
+
+ /**
+ * Primary entry point for startup and shutdown events.
+ *
+ * @param event The event that has occurred
+ */
+ public void lifecycleEvent(LifecycleEvent event)
+ {
+ Lifecycle source = event.getLifecycle();
+ String type = event.getType();
+
+ if (type.equals(Lifecycle.START_EVENT))
+ {
+ if (source instanceof Context)
+ {
+ // Start a webapp
+ this.eventHandler.startContext((Context) source);
+ }
+ }
+ else if (type.equals(Lifecycle.AFTER_START_EVENT))
+ {
+ if (source instanceof Server)
+ {
+ Server server = (Server) source;
+
+ this.eventHandler.init(server);
+
+ this.addListeners(server);
+
+ this.eventHandler.startServer(server);
+
+ this.init = true;
+ }
+ }
+ else if (type.equals(Lifecycle.BEFORE_STOP_EVENT))
+ {
+ if (source instanceof Context)
+ {
+ // Stop a webapp
+ this.eventHandler.stopContext((Context) source);
+ }
+ else if (source instanceof Server)
+ {
+ this.init = false;
+
+ Server server = (Server) source;
+
+ this.removeListeners(server);
+
+ this.eventHandler.stopServer(server);
+
+ this.eventHandler.shutdown();
+ }
+ }
+ else if (type.equals(Lifecycle.PERIODIC_EVENT))
+ {
+ if (this.init && (source instanceof Engine))
+ {
+ this.eventHandler.status((Engine) source);
+ }
+ }
+ }
+
+ private void addListeners(Server server)
+ {
+ // Register ourself as a listener for child services
+ for (Service service: server.findServices())
+ {
+ Container engine = service.getContainer();
+ engine.addContainerListener(this);
+ ((Lifecycle) engine).addLifecycleListener(this);
+
+ for (Container host: engine.findChildren())
+ {
+ host.addContainerListener(this);
+
+ for (Container context: host.findChildren())
+ {
+ ((Lifecycle) context).addLifecycleListener(this);
+ }
+ }
+ }
+ }
+
+ private void removeListeners(Server server)
+ {
+ // Unregister ourself as a listener to child components
+ for (Service service: server.findServices())
+ {
+ Container engine = service.getContainer();
+ engine.removeContainerListener(this);
+ ((Lifecycle) engine).removeLifecycleListener(this);
+
+ for (Container host: engine.findChildren())
+ {
+ host.removeContainerListener(this);
+
+ for (Container context: host.findChildren())
+ {
+ ((Lifecycle) context).removeLifecycleListener(this);
+ }
+ }
+ }
+ }
+}
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ContainerEventHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ContainerEventHandler.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ContainerEventHandler.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.modcluster;
+
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface ContainerEventHandler<S, E, C> extends ServerProvider<S>
+{
+ void init(S server);
+
+ void shutdown();
+
+ void addContext(C context);
+
+ void startContext(C context);
+
+ void stopContext(C context);
+
+ void removeContext(C context);
+
+ void status(E engine);
+
+ void startServer(S server);
+
+ void stopServer(S server);
+}
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -1,345 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.modcluster;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.catalina.Container;
-import org.apache.catalina.Context;
-import org.apache.catalina.Engine;
-import org.apache.catalina.Server;
-import org.apache.catalina.Service;
-import org.apache.catalina.util.StringManager;
-import org.jboss.logging.Logger;
-import org.jboss.modcluster.advertise.AdvertiseListener;
-import org.jboss.modcluster.advertise.AdvertiseListenerFactory;
-import org.jboss.modcluster.config.BalancerConfiguration;
-import org.jboss.modcluster.config.MCMPHandlerConfiguration;
-import org.jboss.modcluster.config.NodeConfiguration;
-import org.jboss.modcluster.load.LoadBalanceFactorProvider;
-import org.jboss.modcluster.load.LoadBalanceFactorProviderFactory;
-import org.jboss.modcluster.mcmp.MCMPHandler;
-import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPRequestFactory;
-import org.jboss.modcluster.mcmp.ResetRequestSource;
-
-/**
- * Default implementation of {@link JBossWebEventHandler}.
- *
- * @author Brian Stansberry
- */
-public class DefaultJBossWebEventHandler implements JBossWebEventHandler
-{
- static final Logger log = Logger.getLogger(DefaultJBossWebEventHandler.class);
-
- // ----------------------------------------------------------------- Fields
-
- /**
- * The string manager for this package.
- */
- private final StringManager sm = StringManager.getManager(Constants.Package);
- private final NodeConfiguration nodeConfig;
- private final BalancerConfiguration balancerConfig;
- private final MCMPHandlerConfiguration mcmpConfig;
- private final MCMPHandler mcmpHandler;
- private final ResetRequestSource source;
- private final MCMPRequestFactory requestFactory;
- private final AdvertiseListenerFactory listenerFactory;
- private final LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory;
-
- private volatile boolean init;
-
- private volatile LoadBalanceFactorProvider loadBalanceFactorProvider;
- private volatile AdvertiseListener advertiseListener;
- private volatile Map<String, Set<String>> excludedContextPaths;
-
- public DefaultJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
- MCMPHandlerConfiguration mcmpConfig, MCMPHandler mcmpHandler, ResetRequestSource source,
- MCMPRequestFactory requestFactory, LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory,
- AdvertiseListenerFactory listenerFactory)
- {
- this.nodeConfig = nodeConfig;
- this.balancerConfig = balancerConfig;
- this.mcmpConfig = mcmpConfig;
- this.mcmpHandler = mcmpHandler;
- this.source = source;
- this.requestFactory = requestFactory;
- this.loadBalanceFactorProviderFactory = loadBalanceFactorProviderFactory;
- this.listenerFactory = listenerFactory;
- }
-
- // ---------------------------------------------------- JBossWebEventHandler
-
- public synchronized void init(Server server)
- {
- List<InetSocketAddress> initialProxies = Utils.parseProxies(this.mcmpConfig.getProxyList());
-
- this.mcmpHandler.init(initialProxies);
-
- this.excludedContextPaths = Utils.parseContexts(this.mcmpConfig.getExcludedContexts());
-
- this.source.init(server, this.excludedContextPaths);
-
- this.loadBalanceFactorProvider = this.loadBalanceFactorProviderFactory.createLoadBalanceFactorProvider();
-
- Boolean advertise = this.mcmpConfig.getAdvertise();
-
- if (Boolean.TRUE.equals(advertise) || (advertise == null && initialProxies.isEmpty()))
- {
- this.advertiseListener = this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig);
-
- try
- {
- this.advertiseListener.start();
- }
- catch (IOException e)
- {
- // TODO What now?
- log.error(e.getMessage(), e);
- }
- }
-
- this.init = true;
- }
-
- public synchronized void shutdown()
- {
- this.init = false;
-
- if (this.advertiseListener != null)
- {
- try
- {
- this.advertiseListener.destroy();
- }
- catch (IOException e)
- {
- log.error(this.sm.getString("modcluster.error.stopListener"), e);
- }
-
- this.advertiseListener = null;
- }
-
- this.mcmpHandler.shutdown();
- }
-
- /**
- * Send commands to the front end server associated with the startup of the
- * node.
- */
- public void startServer(Server server)
- {
- this.checkInit();
-
- for (Service service: server.findServices())
- {
- Engine engine = (Engine) service.getContainer();
-
- this.config(engine);
-
- for (Container host: engine.findChildren())
- {
- for (Container context: host.findChildren())
- {
- this.addContext((Context) context);
- }
- }
- }
- }
-
- /**
- * Send commands to the front end server associated with the shutdown of the
- * node.
- */
- public void stopServer(Server server)
- {
- this.checkInit();
-
- for (Service service: server.findServices())
- {
- Engine engine = (Engine) service.getContainer();
-
- for (Container host: engine.findChildren())
- {
- for (Container context: host.findChildren())
- {
- this.removeContext((Context) context);
- }
- }
-
- this.removeAll(engine);
- }
- }
-
- protected void config(Engine engine)
- {
- this.config(engine, this.mcmpHandler);
- }
-
- protected void config(Engine engine, MCMPHandler mcmpHandler)
- {
- log.debug(this.sm.getString("modcluster.engine.config", engine.getName()));
-
- // If needed, create automagical JVM route (address + port + engineName)
- try
- {
- Utils.establishJvmRouteAndConnectorAddress(engine, mcmpHandler);
-
- this.jvmRouteEstablished(engine);
-
- MCMPRequest request = this.requestFactory.createConfigRequest(engine, this.nodeConfig, this.balancerConfig);
-
- this.mcmpHandler.sendRequest(request);
- }
- catch (Exception e)
- {
- mcmpHandler.markProxiesInError();
-
- log.info(this.sm.getString("modcluster.error.addressJvmRoute"), e);
- }
- }
-
- protected void jvmRouteEstablished(Engine engine)
- {
- // Do nothing
- }
-
- public void addContext(Context context)
- {
- this.checkInit();
-
- if (!this.exclude(context))
- {
- // Send ENABLE-APP if state is started
- if (Utils.isContextStarted(context))
- {
- log.debug(this.sm.getString("modcluster.context.enable", context.getPath(), context.getParent().getName()));
-
- MCMPRequest request = this.requestFactory.createEnableRequest(context);
-
- this.mcmpHandler.sendRequest(request);
- }
- }
- }
-
- public void startContext(Context context)
- {
- this.checkInit();
-
- if (!this.exclude(context))
- {
- log.debug(this.sm.getString("modcluster.context.start", context.getPath(), context.getParent().getName()));
-
- // Send ENABLE-APP
- MCMPRequest request = this.requestFactory.createEnableRequest(context);
-
- this.mcmpHandler.sendRequest(request);
- }
- }
-
- public void stopContext(Context context)
- {
- this.checkInit();
-
- if (!this.exclude(context))
- {
- log.debug(this.sm.getString("modcluster.context.stop", context.getPath(), context.getParent().getName()));
-
- // Send STOP-APP
- MCMPRequest request = this.requestFactory.createStopRequest(context);
-
- this.mcmpHandler.sendRequest(request);
- }
- }
-
- public void removeContext(Context context)
- {
- this.checkInit();
-
- if (!this.exclude(context))
- {
- // JVMRoute can be null here if nothing was ever initialized
- if (Utils.getJvmRoute(context) != null)
- {
- log.debug(this.sm.getString("modcluster.context.disable", context.getPath(), context.getParent().getName()));
-
- MCMPRequest request = this.requestFactory.createRemoveRequest(context);
-
- this.mcmpHandler.sendRequest(request);
- }
- }
- }
-
- protected void removeAll(Engine engine)
- {
- // JVMRoute can be null here if nothing was ever initialized
- if (engine.getJvmRoute() != null)
- {
- log.debug(this.sm.getString("modcluster.engine.stop", engine.getName()));
-
- // Send REMOVE-APP * request
- MCMPRequest request = this.requestFactory.createRemoveRequest(engine);
-
- this.mcmpHandler.sendRequest(request);
- }
- }
-
- public void status(Engine engine)
- {
- this.checkInit();
-
- log.debug(this.sm.getString("modcluster.engine.status", engine.getName()));
-
- this.mcmpHandler.status();
-
- // Send STATUS request
- int lbf = this.getLoadBalanceFactor();
- MCMPRequest request = this.requestFactory.createStatusRequest(engine.getJvmRoute(), lbf);
-
- this.mcmpHandler.sendRequest(request);
- }
-
- protected int getLoadBalanceFactor()
- {
- return this.loadBalanceFactorProvider.getLoadBalanceFactor();
- }
-
- protected void checkInit()
- {
- if (!this.init)
- {
- throw new IllegalStateException(this.sm.getString("modcluster.error.uninitialized"));
- }
- }
-
- private boolean exclude(Context context)
- {
- Set<String> excludedPaths = this.excludedContextPaths.get(context.getParent().getName());
-
- return (excludedPaths != null) ? excludedPaths.contains(context.getPath()) : false;
- }
-}
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandler.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandler.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.modcluster;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.Engine;
-import org.apache.catalina.Server;
-
-/**
- * Handles events notifications coming from JBoss Web via a cluster listener.
- *
- * @author Brian Stansberry
- */
-public interface JBossWebEventHandler
-{
- void init(Server server);
-
- void shutdown();
-
- void addContext(Context context);
-
- void startContext(Context context);
-
- void stopContext(Context context);
-
- void removeContext(Context context);
-
- void status(Engine engine);
-
- void startServer(Server server);
-
- void stopServer(Server server);
-}
\ No newline at end of file
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandlerAdapter.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandlerAdapter.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandlerAdapter.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -1,203 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.modcluster;
-
-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;
-
-/**
- * Adapts lifecycle and container listener events to the {@link JBossWebEventHandler} interface.
- */
-public class JBossWebEventHandlerAdapter implements LifecycleListener, ContainerListener
-{
- /** Initialization flag. */
- private volatile boolean init = false;
-
- private JBossWebEventHandler eventHandler;
-
- // ----------------------------------------------------------- Constructors
-
- public JBossWebEventHandlerAdapter(JBossWebEventHandler eventHandler)
- {
- this.eventHandler = eventHandler;
- }
-
- // ------------------------------------------------------------- Properties
-
- // ---------------------------------------------- LifecycleListener Methods
-
- /**
- * 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
- ((Lifecycle) child).addLifecycleListener(this);
- this.eventHandler.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
- ((Lifecycle) child).removeLifecycleListener(this);
- this.eventHandler.removeContext((Context) child);
- }
- else if (container instanceof Engine)
- {
- // Undeploying a host
- container.removeContainerListener(this);
- }
- }
- }
-
- /**
- * Primary entry point for startup and shutdown events.
- *
- * @param event The event that has occurred
- */
- public void lifecycleEvent(LifecycleEvent event)
- {
- Lifecycle source = event.getLifecycle();
- String type = event.getType();
-
- if (type.equals(Lifecycle.START_EVENT))
- {
- if (source instanceof Context)
- {
- // Start a webapp
- this.eventHandler.startContext((Context) source);
- }
- }
- else if (type.equals(Lifecycle.AFTER_START_EVENT))
- {
- if (source instanceof Server)
- {
- Server server = (Server) source;
-
- this.eventHandler.init(server);
-
- this.addListeners(server);
-
- this.eventHandler.startServer(server);
-
- this.init = true;
- }
- }
- else if (type.equals(Lifecycle.BEFORE_STOP_EVENT))
- {
- if (source instanceof Context)
- {
- // Stop a webapp
- this.eventHandler.stopContext((Context) source);
- }
- else if (source instanceof Server)
- {
- this.init = false;
-
- Server server = (Server) source;
-
- this.removeListeners(server);
-
- this.eventHandler.stopServer(server);
-
- this.eventHandler.shutdown();
- }
- }
- else if (type.equals(Lifecycle.PERIODIC_EVENT))
- {
- if (this.init && (source instanceof Engine))
- {
- this.eventHandler.status((Engine) source);
- }
- }
- }
-
- private void addListeners(Server server)
- {
- // Register ourself as a listener for child services
- for (Service service: server.findServices())
- {
- Container engine = service.getContainer();
- engine.addContainerListener(this);
- ((Lifecycle) engine).addLifecycleListener(this);
-
- for (Container host: engine.findChildren())
- {
- host.addContainerListener(this);
-
- for (Container context: host.findChildren())
- {
- ((Lifecycle) context).addLifecycleListener(this);
- }
- }
- }
- }
-
- private void removeListeners(Server server)
- {
- // Unregister ourself as a listener to child components
- for (Service service: server.findServices())
- {
- Container engine = service.getContainer();
- engine.removeContainerListener(this);
- ((Lifecycle) engine).removeLifecycleListener(this);
-
- for (Container host: engine.findChildren())
- {
- host.removeContainerListener(this);
-
- for (Container context: host.findChildren())
- {
- ((Lifecycle) context).removeLifecycleListener(this);
- }
- }
- }
- }
-}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -87,9 +87,9 @@
super();
}
- protected ModClusterListener(MCMPHandler mcmpHandler, MCMPRequestFactory requestFactory, LifecycleListener lifecycleListener)
+ protected ModClusterListener(MCMPHandler mcmpHandler, MCMPRequestFactory requestFactory, ServerProvider<Server> serverProvider, LifecycleListener lifecycleListener)
{
- super(mcmpHandler, requestFactory, lifecycleListener);
+ super(mcmpHandler, requestFactory, serverProvider, lifecycleListener);
}
/**
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -22,6 +22,7 @@
package org.jboss.modcluster;
import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Server;
import org.jboss.modcluster.load.LoadBalanceFactorProvider;
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequestFactory;
@@ -41,9 +42,9 @@
this.lbfProvider = lbfProvider;
}
- protected ModClusterService(MCMPHandler mcmpHandler, MCMPRequestFactory requestFactory, LifecycleListener lifecycleListener, LoadBalanceFactorProvider lbfProvider)
+ protected ModClusterService(MCMPHandler mcmpHandler, MCMPRequestFactory requestFactory, ServerProvider<Server> serverProvider, LifecycleListener lifecycleListener, LoadBalanceFactorProvider lbfProvider)
{
- super(mcmpHandler, requestFactory, lifecycleListener);
+ super(mcmpHandler, requestFactory, serverProvider, lifecycleListener);
this.lbfProvider = lbfProvider;
}
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ServerProvider.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ServerProvider.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ServerProvider.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.modcluster;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface ServerProvider<S>
+{
+ S getServer();
+}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -33,10 +33,11 @@
import java.util.Map;
import java.util.Set;
+import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Server;
import org.apache.catalina.Service;
import org.apache.catalina.util.StringManager;
import org.jboss.beans.metadata.api.annotations.Inject;
@@ -50,9 +51,10 @@
import org.jboss.ha.framework.server.HAServiceRpcHandler;
import org.jboss.ha.framework.server.HASingletonImpl;
import org.jboss.modcluster.Constants;
-import org.jboss.modcluster.DefaultJBossWebEventHandler;
-import org.jboss.modcluster.JBossWebEventHandler;
-import org.jboss.modcluster.JBossWebEventHandlerAdapter;
+import org.jboss.modcluster.ContainerEventHandler;
+import org.jboss.modcluster.CatalinaEventHandler;
+import org.jboss.modcluster.CatalinaEventHandlerAdapter;
+import org.jboss.modcluster.ServerProvider;
import org.jboss.modcluster.Utils;
import org.jboss.modcluster.advertise.AdvertiseListenerFactory;
import org.jboss.modcluster.advertise.impl.AdvertiseListenerFactoryImpl;
@@ -90,7 +92,7 @@
* @version $Revision$
*/
public class HAModClusterService extends HASingletonImpl<HAServiceEvent>
- implements LifecycleListener, HAModClusterServiceMBean, ModClusterServiceRpcHandler<List<?>, MCMPServerState>, LoadBalanceFactorProviderFactory
+ implements LifecycleListener, HAModClusterServiceMBean, ModClusterServiceRpcHandler<List<?>, MCMPServerState>, LoadBalanceFactorProviderFactory, ServerProvider<Server>
{
private static final Class<?>[] CLUSTER_STATUS_COMPLETE_TYPES = new Class[] { Map.class };
private static final Class<?>[] GET_CLUSTER_COORDINATOR_STATE_TYPES = new Class[] { Set.class };
@@ -110,6 +112,7 @@
*/
final StringManager sm = StringManager.getManager(Constants.Package);
+ private final ServerProvider<Server> serverProvider;
private final LifecycleListener lifecycleListener;
private final LoadBalanceFactorProvider loadBalanceFactorProvider;
private final RpcHandler rpcHandler;
@@ -158,13 +161,14 @@
this.loadBalanceFactorProvider = loadFactorProvider;
this.requestFactory = new DefaultMCMPRequestFactory();
- this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config, config, this.requestFactory, this, this);
+ this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config, config, this, this.requestFactory, this, this);
this.localHandler = new DefaultMCMPHandler(config, this.resetRequestSource, this.requestFactory);
this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this, this);
- JBossWebEventHandler eventHandler = new ClusteredJBossWebEventHandler(config, config, config, this.clusteredHandler, this.resetRequestSource, this.requestFactory, this, new AdvertiseListenerFactoryImpl());
+ ContainerEventHandler<Server, Engine, Context> eventHandler = new ClusteredCatalinaEventHandler(config, config, config, this.clusteredHandler, this.resetRequestSource, this.requestFactory, this, new AdvertiseListenerFactoryImpl());
- this.lifecycleListener = new JBossWebEventHandlerAdapter(eventHandler);
+ this.serverProvider = eventHandler;
+ this.lifecycleListener = new CatalinaEventHandlerAdapter(eventHandler);
this.domain = config.getDomain();
this.masterPerDomain = config.isMasterPerDomain();
@@ -196,6 +200,7 @@
MCMPHandlerConfiguration mcmpConfig,
HAConfiguration haConfig,
MCMPHandler localHandler,
+ ServerProvider<Server> serverProvider,
MCMPRequestFactory requestFactory,
HASingletonAwareResetRequestSource resetRequestSource,
ClusteredMCMPHandler clusteredHandler,
@@ -205,20 +210,11 @@
{
super(new HAServiceEventFactory());
- assert partition != null : this.sm.getString("modcluster.error.iae.null", "partition");
- assert localHandler != null : this.sm.getString("modcluster.error.iae.null", "localHandler");
- assert requestFactory != null : this.sm.getString("modcluster.error.iae.null", "requestFactory");
- assert resetRequestSource != null : this.sm.getString("modcluster.error.iae.null", "resetRequestSource");
- assert nodeConfig != null : this.sm.getString("modcluster.error.iae.null", "nodeConfig");
- assert mcmpConfig != null : this.sm.getString("modcluster.error.iae.null", "mcmpConfig");
- assert haConfig != null : this.sm.getString("modcluster.error.iae.null", "haConfig");
- assert balancerConfig != null : this.sm.getString("modcluster.error.iae.null", "balancerConfig");
- assert clusteredHandler != null : this.sm.getString("modcluster.error.iae.null", "clusteredHandler");
-
this.setHAPartition(partition);
this.loadBalanceFactorProvider = loadFactorProvider;
this.localHandler = localHandler;
+ this.serverProvider = serverProvider;
this.requestFactory = requestFactory;
this.resetRequestSource = resetRequestSource;
this.clusteredHandler = clusteredHandler;
@@ -236,6 +232,16 @@
/**
* @{inheritDoc}
+ * @see org.jboss.modcluster.ServerProvider#getServer()
+ */
+ public Server getServer()
+ {
+ return this.serverProvider.getServer();
+ }
+
+
+ /**
+ * @{inheritDoc}
* @see org.apache.catalina.LifecycleListener#lifecycleEvent(org.apache.catalina.LifecycleEvent)
*/
public void lifecycleEvent(LifecycleEvent event)
@@ -314,7 +320,7 @@
*/
public boolean disable()
{
- for (Service service: ServerFactory.getServer().findServices())
+ for (Service service: this.serverProvider.getServer().findServices())
{
Engine engine = (Engine) service.getContainer();
// Send DISABLE-APP * request
@@ -331,7 +337,7 @@
*/
public boolean enable()
{
- for (Service service: ServerFactory.getServer().findServices())
+ for (Service service: this.serverProvider.getServer().findServices())
{
Engine engine = (Engine) service.getContainer();
// Send ENABLE-APP * request
@@ -716,7 +722,7 @@
}
}
- private class ClusteredJBossWebEventHandler extends DefaultJBossWebEventHandler
+ private class ClusteredCatalinaEventHandler extends CatalinaEventHandler
{
private final HAModClusterService coord = HAModClusterService.this;
@@ -726,7 +732,7 @@
* @param config
* @param loadFactorProvider
*/
- public ClusteredJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
+ public ClusteredCatalinaEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
MCMPHandlerConfiguration mcmpConfig, MCMPHandler clusteredHandler, ResetRequestSource source,
MCMPRequestFactory requestFactory, LoadBalanceFactorProviderFactory loadFactorProviderFactory,
AdvertiseListenerFactory listenerFactory)
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -27,11 +27,13 @@
import java.util.Map;
import java.util.Set;
+import org.apache.catalina.Server;
import org.apache.catalina.util.StringManager;
import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
import org.jboss.ha.framework.interfaces.HASingletonMBean;
import org.jboss.logging.Logger;
import org.jboss.modcluster.Constants;
+import org.jboss.modcluster.ServerProvider;
import org.jboss.modcluster.Utils;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
@@ -65,9 +67,9 @@
private final HASingletonMBean singleton;
private final ResetRequestSourceRpcHandler<List<?>> rpcStub;
- public HASingletonAwareResetRequestSourceImpl(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig, MCMPRequestFactory requestFactory, HASingletonMBean singleton, HAServiceKeyProvider serviceKeyProvider)
+ public HASingletonAwareResetRequestSourceImpl(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig, ServerProvider<Server> serverProvider, MCMPRequestFactory requestFactory, HASingletonMBean singleton, HAServiceKeyProvider serviceKeyProvider)
{
- super(nodeConfig, balancerConfig, requestFactory);
+ super(nodeConfig, balancerConfig, serverProvider, requestFactory);
this.singleton = singleton;
this.rpcStub = new RpcStub(serviceKeyProvider);
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -27,8 +27,6 @@
import java.util.Map;
import java.util.Set;
-import org.apache.catalina.Server;
-
/**
* Source for a list of requests that should be sent to an httpd-side
* mod_cluster instance when an {@link MCMPHandler} determines that
@@ -50,7 +48,7 @@
Map<String, Status> getContexts();
}
- void init(Server server, Map<String, Set<String>> excludedContexts);
+ void init(Map<String, Set<String>> excludedContexts);
/**
* Gets a list of requests that should be sent to an httpd-side
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -35,6 +35,7 @@
import org.apache.catalina.Host;
import org.apache.catalina.Server;
import org.apache.catalina.Service;
+import org.jboss.modcluster.ServerProvider;
import org.jboss.modcluster.Utils;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
@@ -51,15 +52,16 @@
{
private final NodeConfiguration nodeConfig;
private final BalancerConfiguration balancerConfig;
+ private final ServerProvider<Server> serverProvider;
private final MCMPRequestFactory requestFactory;
- private volatile Server server;
private volatile Map<String, Set<String>> excludedContexts;
- public ResetRequestSourceImpl(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig, MCMPRequestFactory requestFactory)
+ public ResetRequestSourceImpl(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig, ServerProvider<Server> serverProvider, MCMPRequestFactory requestFactory)
{
this.nodeConfig = nodeConfig;
this.balancerConfig = balancerConfig;
+ this.serverProvider = serverProvider;
this.requestFactory = requestFactory;
}
@@ -67,9 +69,8 @@
* @{inheritDoc}
* @see org.jboss.modcluster.mcmp.ResetRequestSource#init(java.util.Map)
*/
- public void init(Server server, Map<String, Set<String>> excludedContexts)
+ public void init(Map<String, Set<String>> excludedContexts)
{
- this.server = server;
this.excludedContexts = excludedContexts;
}
@@ -81,11 +82,13 @@
{
List<MCMPRequest> requests = new ArrayList<MCMPRequest>();
- if (this.server == null) return requests;
+ Server server = this.serverProvider.getServer();
+ if (server == null) return requests;
+
List<MCMPRequest> engineRequests = new LinkedList<MCMPRequest>();
- for (Service service: this.server.findServices())
+ for (Service service: server.findServices())
{
Engine engine = (Engine) service.getContainer();
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -72,12 +72,12 @@
private final AdvertiseListenerFactory listenerFactory = EasyMock.createStrictMock(AdvertiseListenerFactory.class);
private AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
- private JBossWebEventHandler handler;
+ private ContainerEventHandler<Server, Engine, Context> handler;
@Before
public void construct() throws Exception
{
- this.handler = new DefaultJBossWebEventHandler(this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.mcmpHandler, this.source, this.requestFactory, this.lbfProviderFactory, this.listenerFactory);
+ this.handler = new CatalinaEventHandler(this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.mcmpHandler, this.source, this.requestFactory, this.lbfProviderFactory, this.listenerFactory);
}
@Test
@@ -95,7 +95,7 @@
EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn(null);
- this.source.init(server, emptyContextMap);
+ this.source.init(emptyContextMap);
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
@@ -124,7 +124,7 @@
EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("");
- this.source.init(server, emptyContextMap);
+ this.source.init(emptyContextMap);
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
@@ -156,7 +156,7 @@
EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("ignored");
- this.source.init(server, Collections.singletonMap("localhost", Collections.singleton("/ignored")));
+ this.source.init(Collections.singletonMap("localhost", Collections.singleton("/ignored")));
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
@@ -184,7 +184,7 @@
EasyMock.expect(this.mcmpConfig.getExcludedContexts()).andReturn("host1:ignored,ROOT");
- this.source.init(EasyMock.same(server), EasyMock.capture(capturedMap));
+ this.source.init(EasyMock.capture(capturedMap));
EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/JBossWebEventHandlerAdapterTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/JBossWebEventHandlerAdapterTestCase.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/JBossWebEventHandlerAdapterTestCase.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -39,9 +39,10 @@
*/
public class JBossWebEventHandlerAdapterTestCase
{
- private JBossWebEventHandler eventHandler = EasyMock.createStrictMock(JBossWebEventHandler.class);
+ @SuppressWarnings("unchecked")
+ private ContainerEventHandler<Server, Engine, Context> eventHandler = EasyMock.createStrictMock(ContainerEventHandler.class);
- private JBossWebEventHandlerAdapter adapter = new JBossWebEventHandlerAdapter(this.eventHandler);
+ private CatalinaEventHandlerAdapter adapter = new CatalinaEventHandlerAdapter(this.eventHandler);
@Test
public void deployWebApp()
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -27,6 +27,7 @@
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.easymock.EasyMock;
import org.jboss.modcluster.load.LoadBalanceFactorProvider;
@@ -45,13 +46,13 @@
*/
public class ModClusterListenerTestCase
{
- private static final ModClusterServiceTestCase.LifecycleServer server = ModClusterServiceTestCase.server;
-
private final MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
private final MCMPRequestFactory requestFactory = EasyMock.createStrictMock(MCMPRequestFactory.class);
private final LifecycleListener lifecycleListener = EasyMock.createStrictMock(LifecycleListener.class);
+ @SuppressWarnings("unchecked")
+ private final ServerProvider<Server> serverProvider = EasyMock.createStrictMock(ServerProvider.class);
- private final ModClusterListener listener = new ModClusterListener(this.mcmpHandler, this.requestFactory, this.lifecycleListener);
+ private final ModClusterListener listener = new ModClusterListener(this.mcmpHandler, this.requestFactory, this.serverProvider, this.lifecycleListener);
@Test
public void createLoadBalanceFactorProvider()
@@ -181,10 +182,12 @@
@Test
public void enable()
{
+ Server server = EasyMock.createStrictMock(Server.class);
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
MCMPRequest request = EasyMock.createStrictMock(MCMPRequest.class);
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(server);
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
@@ -194,25 +197,25 @@
EasyMock.expect(this.mcmpHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.mcmpHandler, this.requestFactory, server, service, engine);
+ EasyMock.replay(this.serverProvider, this.mcmpHandler, this.requestFactory, server, service, engine);
boolean result = this.listener.enable();
- EasyMock.verify(this.mcmpHandler, this.requestFactory, server, service, engine);
+ EasyMock.verify(this.serverProvider, this.mcmpHandler, this.requestFactory, server, service, engine);
Assert.assertTrue(result);
-
- EasyMock.reset(this.mcmpHandler, this.requestFactory, server);
}
@SuppressWarnings("boxing")
@Test
public void disable()
{
+ Server server = EasyMock.createStrictMock(Server.class);
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
MCMPRequest request = EasyMock.createStrictMock(MCMPRequest.class);
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(server);
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
@@ -222,14 +225,12 @@
EasyMock.expect(this.mcmpHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.mcmpHandler, this.requestFactory, server, service, engine);
+ EasyMock.replay(this.serverProvider, this.mcmpHandler, this.requestFactory, server, service, engine);
boolean result = this.listener.disable();
- EasyMock.verify(this.mcmpHandler, this.requestFactory, server, service, engine);
+ EasyMock.verify(this.serverProvider, this.mcmpHandler, this.requestFactory, server, service, engine);
Assert.assertTrue(result);
-
- EasyMock.reset(this.mcmpHandler, this.requestFactory, server);
}
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -26,7 +26,6 @@
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Server;
-import org.apache.catalina.ServerFactory;
import org.apache.catalina.Service;
import org.easymock.EasyMock;
import org.jboss.modcluster.load.LoadBalanceFactorProvider;
@@ -42,18 +41,14 @@
*/
public class ModClusterServiceTestCase
{
- public static final LifecycleServer server = EasyMock.createStrictMock(LifecycleServer.class);
- static
- {
- ServerFactory.setServer(server);
- }
-
private final MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
private final LifecycleListener lifecycleListener = EasyMock.createStrictMock(LifecycleListener.class);
private final LoadBalanceFactorProvider lbfProvider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
private final MCMPRequestFactory requestFactory = EasyMock.createStrictMock(MCMPRequestFactory.class);
+ @SuppressWarnings("unchecked")
+ private final ServerProvider<Server> serverProvider = EasyMock.createStrictMock(ServerProvider.class);
- private final ModClusterService listener = new ModClusterService(this.mcmpHandler, this.requestFactory, this.lifecycleListener, this.lbfProvider);
+ private final ModClusterService listener = new ModClusterService(this.mcmpHandler, this.requestFactory, this.serverProvider, this.lifecycleListener, this.lbfProvider);
@Test
public void createLoadBalanceFactorProvider()
@@ -166,12 +161,12 @@
@Test
public void enable()
{
+ Server server = EasyMock.createStrictMock(Server.class);
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
MCMPRequest request = EasyMock.createMock(MCMPRequest.class);
- Assert.assertSame(server, ServerFactory.getServer());
-
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(server);
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
@@ -181,27 +176,25 @@
EasyMock.expect(this.mcmpHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.requestFactory, this.mcmpHandler, server, service, engine);
+ EasyMock.replay(this.serverProvider, this.requestFactory, this.mcmpHandler, server, service, engine);
boolean result = this.listener.enable();
- EasyMock.verify(this.requestFactory, this.mcmpHandler, server, service, engine);
+ EasyMock.verify(this.serverProvider, this.requestFactory, this.mcmpHandler, server, service, engine);
Assert.assertTrue(result);
-
- EasyMock.reset(this.requestFactory, this.mcmpHandler, server);
}
@SuppressWarnings("boxing")
@Test
public void disable()
{
+ Server server = EasyMock.createStrictMock(Server.class);
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
MCMPRequest request = EasyMock.createMock(MCMPRequest.class);
- Assert.assertSame(server, ServerFactory.getServer());
-
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(server);
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
@@ -211,19 +204,12 @@
EasyMock.expect(this.mcmpHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.requestFactory, this.mcmpHandler, server, service, engine);
+ EasyMock.replay(this.serverProvider, this.requestFactory, this.mcmpHandler, server, service, engine);
boolean result = this.listener.disable();
- EasyMock.verify(this.requestFactory, this.mcmpHandler, server, service, engine);
+ EasyMock.verify(this.serverProvider, this.requestFactory, this.mcmpHandler, server, service, engine);
Assert.assertTrue(result);
-
- EasyMock.reset(this.requestFactory, this.mcmpHandler, server);
}
-
- public interface LifecycleServer extends Server, Lifecycle
- {
- String getDomain();
- }
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterServiceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterServiceTestCase.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterServiceTestCase.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -25,13 +25,13 @@
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Server;
import org.apache.catalina.Service;
import org.easymock.EasyMock;
import org.jboss.ha.framework.interfaces.ClusterNode;
import org.jboss.ha.framework.interfaces.HAPartition;
import org.jboss.ha.framework.interfaces.HASingletonElectionPolicy;
-import org.jboss.modcluster.ModClusterServiceTestCase;
+import org.jboss.modcluster.ServerProvider;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
@@ -51,8 +51,6 @@
@SuppressWarnings("boxing")
public class HAModClusterServiceTestCase
{
- private static final ModClusterServiceTestCase.LifecycleServer server = ModClusterServiceTestCase.server;
-
private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
private NodeConfiguration nodeConfig = EasyMock.createMock(NodeConfiguration.class);
private BalancerConfiguration balancerConfig = EasyMock.createMock(BalancerConfiguration.class);
@@ -66,6 +64,8 @@
private ClusterNode node = EasyMock.createStrictMock(ClusterNode.class);
private LifecycleListener lifecycleListener = EasyMock.createStrictMock(LifecycleListener.class);
private MCMPRequestFactory requestFactory = EasyMock.createStrictMock(MCMPRequestFactory.class);
+ @SuppressWarnings("unchecked")
+ private ServerProvider<Server> serverProvider = EasyMock.createStrictMock(ServerProvider.class);
private static final boolean MASTER_PER_DOMAIN = true;
private static final String SERVICE_HA_NAME = "myservice";
@@ -83,7 +83,7 @@
EasyMock.replay(this.mcmpConfig, this.nodeConfig, this.haConfig, this.partition);
- this.service = new HAModClusterService(this.partition, this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.haConfig, this.mcmpHandler, this.requestFactory, this.resetRequestSource, this.clusteredMCMPHandler, this.lifecycleListener, this.lbfProvider, this.electionPolicy);
+ this.service = new HAModClusterService(this.partition, this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.haConfig, this.mcmpHandler, this.serverProvider, this.requestFactory, this.resetRequestSource, this.clusteredMCMPHandler, this.lifecycleListener, this.lbfProvider, this.electionPolicy);
this.service.setServiceHAName(SERVICE_HA_NAME);
EasyMock.verify(this.mcmpConfig, this.nodeConfig, this.haConfig, this.partition);
@@ -91,6 +91,22 @@
}
@Test
+ public void getServer()
+ {
+ Server server = EasyMock.createMock(Server.class);
+
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(server);
+
+ EasyMock.replay(this.serverProvider);
+
+ Server result = this.service.getServer();
+
+ EasyMock.verify(this.serverProvider);
+
+ Assert.assertSame(server, result);
+ }
+
+ @Test
public void addProxy()
{
String host = "127.0.0.1";
@@ -183,12 +199,12 @@
@Test
public void enable()
{
+ Server server = EasyMock.createStrictMock(Server.class);
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
MCMPRequest request = EasyMock.createMock(MCMPRequest.class);
- Assert.assertSame(server, ServerFactory.getServer());
-
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(server);
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
@@ -198,27 +214,25 @@
EasyMock.expect(this.clusteredMCMPHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
+ EasyMock.replay(this.serverProvider, this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
boolean result = this.service.enable();
- EasyMock.verify(this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
+ EasyMock.verify(this.serverProvider, this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
Assert.assertTrue(result);
-
- EasyMock.reset(this.requestFactory, this.clusteredMCMPHandler, server);
}
@Test
public void disable()
{
+ Server server = EasyMock.createStrictMock(Server.class);
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
MCMPRequest request = EasyMock.createMock(MCMPRequest.class);
- Assert.assertSame(server, ServerFactory.getServer());
-
- EasyMock.expect(ModClusterServiceTestCase.server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(server);
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
EasyMock.expect(this.requestFactory.createDisableRequest(engine)).andReturn(request);
@@ -227,15 +241,13 @@
EasyMock.expect(this.clusteredMCMPHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
+ EasyMock.replay(this.serverProvider, this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
boolean result = this.service.disable();
- EasyMock.verify(this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
+ EasyMock.verify(this.serverProvider, this.requestFactory, this.clusteredMCMPHandler, server, service, engine);
Assert.assertTrue(result);
-
- EasyMock.reset(this.requestFactory, this.clusteredMCMPHandler, server);
}
@Test
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -39,6 +39,7 @@
import org.jboss.ha.framework.interfaces.HAPartition;
import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
import org.jboss.ha.framework.interfaces.HASingletonMBean;
+import org.jboss.modcluster.ServerProvider;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
import org.jboss.modcluster.ha.rpc.ResetRequestGroupRpcResponse;
@@ -61,11 +62,13 @@
private HASingletonMBean singleton = EasyMock.createStrictMock(HASingletonMBean.class);
private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
private MCMPRequestFactory requestFactory = EasyMock.createStrictMock(MCMPRequestFactory.class);
+ @SuppressWarnings("unchecked")
+ private ServerProvider<Server> serverProvider = EasyMock.createStrictMock(ServerProvider.class);
@Test
public void getResetRequestsNonMaster()
{
- HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory, this.singleton, this.key);
+ HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.serverProvider, this.requestFactory, this.singleton, this.key);
EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
@@ -85,7 +88,7 @@
@Test
public void getResetRequestsNoInit() throws Exception
{
- HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory, this.singleton, this.key);
+ HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.serverProvider, this.requestFactory, this.singleton, this.key);
Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
@@ -116,7 +119,7 @@
@Test
public void getResetRequests() throws Exception
{
- HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory, this.singleton, this.key);
+ HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.serverProvider, this.requestFactory, this.singleton, this.key);
Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
Map<String, Set<String>> emptyContextMap = Collections.emptyMap();
@@ -134,10 +137,12 @@
MCMPRequest configRequest = EasyMock.createStrictMock(MCMPRequest.class);
MCMPRequest contextRequest = EasyMock.createStrictMock(MCMPRequest.class);
- source.init(server, emptyContextMap);
+ source.init(emptyContextMap);
EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(server);
+
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
@@ -158,11 +163,11 @@
EasyMock.expect(this.key.getHAServiceKey()).andReturn("service:domain");
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq("service:domain"), EasyMock.eq("getResetRequests"), EasyMock.aryEq(new Object[] { emptyResponseMap }), EasyMock.aryEq(new Class[] { Map.class }), EasyMock.eq(true))).andReturn(new ArrayList<ResetRequestGroupRpcResponse>(Arrays.asList(response1, response2)));
- EasyMock.replay(this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
+ EasyMock.replay(this.serverProvider, this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
List<MCMPRequest> requests = source.getResetRequests(emptyResponseMap);
- EasyMock.verify(this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
+ EasyMock.verify(this.serverProvider, this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
Assert.assertEquals(4, requests.size());
@@ -170,32 +175,30 @@
Assert.assertSame(contextRequest, requests.get(1));
Assert.assertSame(request1, requests.get(2));
Assert.assertSame(request2, requests.get(3));
-
- EasyMock.reset(this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
}
@Test
- public void getLocalResetRequestsNoInit() throws Exception
+ public void getLocalResetRequestsNoServer() throws Exception
{
- HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory, this.singleton, this.key);
+ HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.serverProvider, this.requestFactory, this.singleton, this.key);
Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
- EasyMock.replay(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory);
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(null);
+ EasyMock.replay(this.serverProvider, this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory);
+
List<MCMPRequest> requests = source.getLocalResetRequests(emptyResponseMap);
- EasyMock.verify(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory);
+ EasyMock.verify(this.serverProvider, this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory);
Assert.assertTrue(requests.isEmpty());
-
- EasyMock.reset(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory);
}
@Test
public void getLocalResetRequests() throws Exception
{
- HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory, this.singleton, this.key);
+ HASingletonAwareResetRequestSource source = new HASingletonAwareResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.serverProvider, this.requestFactory, this.singleton, this.key);
Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
Map<String, Set<String>> emptyContextMap = Collections.emptyMap();
@@ -209,8 +212,10 @@
MCMPRequest configRequest = EasyMock.createStrictMock(MCMPRequest.class);
MCMPRequest contextRequest = EasyMock.createStrictMock(MCMPRequest.class);
- source.init(server, emptyContextMap);
+ source.init(emptyContextMap);
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(server);
+
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
@@ -227,17 +232,15 @@
EasyMock.expect(this.requestFactory.createEnableRequest(context)).andReturn(contextRequest);
- EasyMock.replay(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
+ EasyMock.replay(this.serverProvider, this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
List<MCMPRequest> requests = source.getLocalResetRequests(emptyResponseMap);
- EasyMock.verify(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
+ EasyMock.verify(this.serverProvider, this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory, server, service, engine, host, context);
Assert.assertEquals(2, requests.size());
Assert.assertSame(configRequest, requests.get(0));
Assert.assertSame(contextRequest, requests.get(1));
-
- EasyMock.reset(this.nodeConfig, this.balancerConfig, this.key, this.singleton, this.partition, this.requestFactory);
}
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java 2009-01-27 21:32:36 UTC (rev 2228)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java 2009-01-27 21:41:00 UTC (rev 2229)
@@ -33,6 +33,7 @@
import org.apache.catalina.Server;
import org.apache.catalina.Service;
import org.easymock.EasyMock;
+import org.jboss.modcluster.ServerProvider;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
import org.jboss.modcluster.mcmp.impl.ResetRequestSourceImpl;
@@ -48,15 +49,23 @@
private final NodeConfiguration nodeConfig = EasyMock.createStrictMock(NodeConfiguration.class);
private final BalancerConfiguration balancerConfig = EasyMock.createStrictMock(BalancerConfiguration.class);
private final MCMPRequestFactory requestFactory = EasyMock.createStrictMock(MCMPRequestFactory.class);
+ @SuppressWarnings("unchecked")
+ private final ServerProvider<Server> serverProvider = EasyMock.createStrictMock(ServerProvider.class);
@Test
- public void testGetResetRequestsNoInit()
+ public void testGetResetRequestsNoServer()
{
- ResetRequestSource source = new ResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory);
+ ResetRequestSource source = new ResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.serverProvider, this.requestFactory);
+
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(null);
+ EasyMock.replay(this.serverProvider);
+
Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
List<MCMPRequest> requests = source.getResetRequests(emptyResponseMap);
+
+ EasyMock.verify(this.serverProvider);
Assert.assertTrue(requests.isEmpty());
}
@@ -64,7 +73,7 @@
@Test
public void testGetResetRequests() throws Exception
{
- ResetRequestSource source = new ResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.requestFactory);
+ ResetRequestSource source = new ResetRequestSourceImpl(this.nodeConfig, this.balancerConfig, this.serverProvider, this.requestFactory);
Server server = EasyMock.createStrictMock(Server.class);
Service service = EasyMock.createStrictMock(Service.class);
@@ -75,7 +84,9 @@
MCMPRequest contextRequest = EasyMock.createStrictMock(MCMPRequest.class);
Map<String, Set<String>> emptyContextMap = Collections.emptyMap();
- source.init(server, emptyContextMap);
+ source.init(emptyContextMap);
+
+ EasyMock.expect(this.serverProvider.getServer()).andReturn(server);
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
@@ -93,19 +104,17 @@
EasyMock.expect(this.requestFactory.createEnableRequest(context)).andReturn(contextRequest);
- EasyMock.replay(server, this.requestFactory, service, engine, host, context, this.nodeConfig, this.balancerConfig);
+ EasyMock.replay(this.serverProvider, server, this.requestFactory, service, engine, host, context, this.nodeConfig, this.balancerConfig);
Map<String, Set<ResetRequestSource.VirtualHost>> emptyResponseMap = Collections.emptyMap();
List<MCMPRequest> requests = source.getResetRequests(emptyResponseMap);
- EasyMock.verify(server, this.requestFactory, service, engine, host, context, this.nodeConfig, this.balancerConfig);
+ EasyMock.verify(this.serverProvider, server, this.requestFactory, service, engine, host, context, this.nodeConfig, this.balancerConfig);
Assert.assertEquals(2, requests.size());
Assert.assertSame(configRequest, requests.get(0));
Assert.assertSame(contextRequest, requests.get(1));
-
- EasyMock.reset(server);
}
}
15 years, 11 months