Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 4
Finally, Listing 4 shows the Web deployment descriptor for this application.
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
TeracottaSessionClusteringExample</display-name>
<servlet>
<description>
</description>
<display-name>SessionServlet</display-name>
<servlet-name>SessionServlet</servlet-name>
<servlet-class>com.geekcap.terracottaexample.SessionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SessionServlet</servlet-name>
<url-pattern>/SessionServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
The web.xml file defines the SessionServlet and maps requests for /SessionServlet to the SessionServlet.
Package these files into a WAR file named TerracottaExample.war with the following structure:
enterYourName.jsp
hello.jsp
WEB-INF/web.xml
WEB-INF/classes/com/geekcap/terracottaexample/SessionServlet.class
To test the sample application and build a Terracotta configuration file, you'll use the Sessions Configurator. Launch the
welcome application (by executing either welcome.bat or welcome.sh), select the Sessions tab (shown in Figure 1), and choose Terracotta Sessions Configurator.
When the Sessions Configurator starts, click the Import button. Or, if you close the initial dialog box, you can choose File ->Import webapp. Navigate to your WAR file and click OK, as shown in Figure 2.
The Control tab, shown in Figure 3, shows your application configured to run in two Tomcat instances.
The Terracotta Sessions enabled checkbox configures Tomcat to cluster Tomcat sessions. A simple way to see the effects of the clustering is to launch the application with this checkbox disabled and hit both servers, then launch the application with the checkbox enabled and hit both servers. Give it a try:
What you should notice is that when you hit the individual servers with Terracotta Sessions disabled, the servers know nothing about each other. As a matter of fact they clobber each other's session cookie, and the results are rather random. When you enable Terracotta Sessions and then enter your name into one server, the other server is immediately aware of your name. And when you change your name on one server, the change is immediately reflected on the other server.
Figure 4 shows screen shots from both of my Tomcat servers showing the same data.