Jetty is a project at the Eclipse Foundation.
| Homepage: | http://www.eclipse.org/jetty |
| Downloads: | http://download.eclipse.org/jetty/ |
| Documentation: | http://www.eclipse.org/jetty/documentation/current/ |
| About: | http://www.eclipse.org/jetty/about.php |
| Jetty Powered: | http://www.eclipse.org/jetty/powered/ |
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
Session Clustering with Terracotta
Build Instructions
- Before you start, make sure you have installed release terracotta 2.4 or greater. We'll refer to the installation directory as
<TC-HOME>. - If you haven't already got a boot jar for terracotta for your jvm version, then make one now. On linux this is:
- Download and unzip a src bundle (6.1.4 onwards) or check out trunk or any tag from
jetty-6.1.4onwards. Here's how to do the checkout:We'll refer to the installation directory as<JETTY-HOME>. - Build it if it isn't already:
- Go to the
<JETTY_HOME>/contrib/terracottadirectory and build it: - Copy the target/terracotta-sessions.jar you just built into
<JETTY-HOME>/lib/ext:
Configuration
Configuring Jetty to use Terracotta consists of creating a single TerracottaSessionIdManager per jetty instance to generate unqiue session ids, and then setting up a special TerracottaSessionManager per webapp to be distributed.
We've provided sample config files to do both of these things, so if you don't want to read further, you can just use them. Here's how to start jetty with terracotta and deploy the sample webapps that come with the terracotta distribution:
- build, then copy the DepartmentTaskList.war, Cart.war and Townsend.war files from
<TC-HOME>/samples/sessionsto<JETTY-HOME>/webapps - copy these jetty context deployer config files which match the sample webapps into <JETTY-HOME>/contexts from
<JETTY-HOME>/contrib/terracotta/src/main/resources:- cart.xml
- departmentTaskList.xml
- townsend.xml
- skip down to the #Starting section to run jetty
Otherwise, let's continue with looking into the configuration files.
The TerracottaSessionIdManager
One TerracottaSessionIdManager is configured per jetty instance to generate unique session ids. These are the relevant lines from <JETTY-HOME>/contrib/terracotta/src/main/resources/jetty.xml:
The workerName is a unqiue name for the jetty instance. In the example it is "fred" but you can use any naming scheme you'd like. We set the tcIdMgr object as a Server attribute so that we can reference it in other config files.
The TerracottaSessionManager
Each webapp whose sessions we want clustered must use a TerracottaSessionManager instead of the default HashSessionManager.
The easiest way to do this is to create individual context deployer config files for each webapp, and include these lines:
These lines ensure that a TerracottaSessionManager is established for each webapp, and has access to the jetty instance's unique session id generator we configured above.
Starting
- Start a terracotta server with a jetty configuration file. On linux this is:
- Set up the webapps that you want to use terracotta by following the instructions in the #Configuration section above.
- Run the <TC_HOME>/bin/dso-env.sh command to determine the appropriate JVM arguments to start jetty with.
(The dso-env script will also create a Terracotta boot jar for you if you haven't already created one for your platform as described earlier.)
- Copy the output of the
dso-envscript and use it to start jetty:
You'll now have a jetty instance that is talking to terracotta to distribute sessions from your webapps. Rinse and repeat to create other jetty instances in the cluser. Don't forget to select a unique workerName for the other TerracottaSessionIdManagers. Also, if you just want to play around and run 2 jetty instances on the same machine, don't forget that you'll need to use port numbers for each!
A simple way to test if Terracotta session clustering is working is to restart the jetty server and verify that your session data is intact. You can also use the Terracotta console (<TC_HOME>/bin/admin.sh) to inspect the live session data.