Clustering with Jetty and WADI
What is WADI?
WADI is an acronym of 'WADI Application Distribution Infrastructure'. WADI started life as a solution to the problems surrounding the distribution of state in clustered web tiers, but is becoming a more generalised distributed space service.
How to cluster your web application with Jetty and WADI
First, svn checkout the wadi-session-manager and then buid it by calling mvn install.
There are two ways to cluster with WADI and Jetty: programatically and by using Jetty's xml configuration.
If you want to do it programatically, you need to put the following in your classpath first: backport-util-concurrent-2.2.jar, cglib-nodep-2.1_3.jar, commons-codec-1.2.jar, commons-httpclient-3.0.jar, concurrent-1.3.4.jar, concurrent-1.3.4.jar, regexp-1.3.jar, slf4j-simple-1.0.1.jar, jcl104-over-slf4j-1.0.1.jar, tribes-0.9.5.2.jar, wadi-core-2.0M3-SNAPSHOT.jar, wadi-group-2.0M3-SNAPSHOT.jar, wadi-tribes-2.0M3-SNAPSHOT.jar, jetty-wadi-session-manager-6.1-SNAPSHOT.jar, jetty-util-6.1-SNAPSHOT.jar, jetty-6.1-SNAPSHOT.jar, and servlet-api-2.5-6.1-SNAPSHOT.jar.
This looks like how one will usually setup an embedded a jetty server. The main difference is that here, the webapp is declared explicitly and configured to use the WadiSessionHandler. You'll also need to include the WadiSessionManager as a parameter when you instantiate the WadiSessionHandler.
The paramaters of WadiSessionManager's constructor are: cluster name, service space name, node name, nbreplica (int), endpoint url, number of partitions(int), and sweep interval(int). Its a good idea to obtain the port and node name from System properties so It can easily be set when you run the embedded jetty server (just indicate -Djetty.port and -Dnode.name)
This example clusters Jetty's test webapp. To test if it really works run multiple instances of the server using different ports and different node names. You can use any node name as long as it is distinct from the other nodes.
Clustering a webapp using jetty xml uses the same idea as when you do it programatically. The same dependencies mentioned above should first be placed inside the lib/ext directory of Jetty. Here's an example of the xml config:
This jetty xml is readily usable. To cluster the test webapp run three instances of the server:
java -Djetty.port=7070 -Dnode.name=orange -jar start.jar etc/jetty-wadi-cluster.xml
java -Djetty.port=8080 -Dnode.name=red -jar start.jar etc/jetty-wadi-cluster.xml
java -Djetty.port=9090 -Dnode.name=blue -jar start.jar etc/jetty-wadi-cluster.xml
Now, you can test clustering using the test webapp's Session Dump Servlet.