This site hosts historical documentation. Visit www.terracotta.org for recent product information.

Terracotta Web Sessions Tutorial

Web Sessions version 4.x

Web Sessions works with the Terracotta Server Array, which backs your sessions with BigMemory resource management, nonstop, rejoin, and many other features. For more information, refer to the Terracotta Server Array page.

Follow these steps to get a sample clustered web sessions application running with Terracotta on your machine.

Step 1: Download Terracotta Web Sessions

Download the BigMemory Max kit, which includes Terracotta Web Sessions.

Unpack the Kit

Unpack the distribution into a directory on your system. In the following instructions, we will refer to the directory as <terracotta>/. Where forward slashes ("/") are given in directory paths, substitute back slashes ("\") for Microsoft Windows installations.

Copy the License Key

Copy the license key to the terracotta distribution directory. This file, called terracotta-license.key, was attached to an email you received after registering for the download.

%> cp terracotta-license.key <terracotta>/

Step 2: Start the Shopping Cart Tutorial

We'll use the "Cart" sample in the sessions samples directory of the Terracotta distribution to demonstrate clustered Web Sessions.

Start the Terracotta Server

%> cd <terracotta>/sessions/code-samples/cart

%> bin/start-sample-server.sh

Start the Sample

%> bin/start-sample.sh

Step 3: View the Sample

The Shopping Cart sample starts up two instances of Jetty, each connected to the Terracotta server for access to shared session data. The sample application uses Terracotta to store session data for scalable high availability. Any session can be read from any application server.

View the Cart

Once the Jetty instances have started, you can view the sample application by visiting the following links:

http://localhost:9081/Cart ›
http://localhost:9082/Cart ›

Note: These links will not work unless you have the sample running.

Create Session Data

After Jetty loads the sample application, select an item to place in the cart. It should look something like this in your browser:

Notice that your item is stored in the session and displayed on the page.

Step 4: View the Session in Other JVMs

To see the session data automatically made consistent and available in the other application server, click the Server link in the colored box.

Notice that your product browsing history is intact, even on the other application server. Web Sessions is automatically and transparently clustering your session data and sharing it between the two server instances on demand. Make another change to your cart and then click the other server link. You will observe that the session data is shared across the two server instances at a fine-grained, field-change level, independent of the application code.

Step 5: Install Web Sessions with Your Application

Go to the Web Sessions Installation Guide to learn how to install Web Sessions with your application, configure Terracotta clustering, and view runtime statistics.