Last but not least Coherence 3.7 finally introduces the native integration with GlassFish Server by using the Coherence*Web SPI for GlassFish (ActiveCache for GlassFish), providing "no code change" installation and configuration of Coherence*Web, making it dramatically easier for GlassFish Server users to scale their applications. And that's exactly what we are going to do today.
Get the latest Oracle GlassFish Server 3.1. Unzip/install it to your favorite location. Download Oracle Coherence for Java Version 3.7. Same here: Unzip to your favorite location. Open the coherence_3.7\lib\webInstaller.jar and extract the webInstaller.jar\web-install\coherence-web.jar and the session-cache-config.xml. Now you have to create a domain if you haven't already (asadmin create-domain coherenceTest). Copy the coherence.jar from coherence_3.7\lib\ to your domain\lib folder.
If you are starting from scratch, you have to fire up your favorite IDE and create a new Web or Ear Project. If you are configuring a web project, copy the coherence-web.jar file to the /WEB-INF/lib/ directory of your Web application. If you are configuring an ear project, copy the coherence-web.jar file to the EAR file's /lib. The session-cache-config.xml needs to be in your /WEB-INF/classes folder.
For this simple example I refer to the good old clusterjsp (taken from Arun's Screencast #34). Extract it. Put coherence-web.jar into ear/lib folder and create a WEB-INF/classes folder in which you put the session-cache-config.xml file. Great. Delete the sun-web.xml from WEB-INF and create a new glassfish-web.xml containing:
<glassfish-web-app>Done. Package everything up again.
<session-manager persistence-type="coherence-web" />
Start a Cache Server
A Coherence data node (also known as a cache server) is responsible for storing and managing all cached data. It can be run either in a dedicated JVM (out-of-process) or within a GlassFish Server instance (in-process). The simplest setting is to run it in-process. To make this easy you have to edit the config/domain.xml and add a JVM Option:
Now fire up your GlassFish and deploy the sample. If you are looking at the server.log you see Oracle Coherence coming up and logging some fancy stuff:
Oracle Coherence Version 22.214.171.124 Build 23397 Grid Edition: Development mode ... Clustered Session Cache Name=session-storage Local Session Cache Name=local-session-storage Local Session Attribute Cache Name=local-attribute-storage Death Certificate Cache Name=session-death-certificates SessionDistributionController Class Name=com.tangosol.coherence.servlet.glassfish31.GlassFishHybridController AttributeScopeController Class Name=com.tangosol.coherence.servlet.AbstractHttpSessionCollection$ApplicationScopeController ...That's good. Now you know, that everything is working.
Start your GlassFish and deploy the application
Links and Further Readings
High performance JPA with GlassFish and Coherence
Oracle® Coherence User's Guide for Oracle Coherence*Web
Installing Oracle Coherence for Java
Using Coherence*Web with GlassFish Server
Installing and Configuring Eclipse and OEPE with Coherence
The GlassFish Product Manager Adam Leftik published two screencasts about the concepts behind Oracle Coherence and how Active Cache for GlassFish provides seamless integration with Coherence*Web. This is great additional information if you need to know more about the whole topic.
Active Cache For GlassFish Part 1 of 2
Active Cache For GlassFish Part 2 of 2