Tuesday, November 03, 2009

Oracle Coherence*Web: easy in-memory session management in a clustered environment

Oracle Coherence contains the Oracle Coherence*Web session management module. Oracle Coherence*Web provides in-memory session data management that allows your website to benefit from the high-performance, reliable, high available and scalable data grid solution provided by Oracle Coherence to easily share and manage session data in an application server cluster

In this blog posting, I will use a simple JSF web application deployed on a Weblogic Server 11g instance to show you how easy it is to set-up Oracle Coherence*Web to store session data in a Oracle Coherence data grid.

Coherence and Weblogic 11g configuration
I have used Coherence 3.5.2 and Weblogic 11g (10.3.1) to set up this demo. Coherence 3.5.2 can be downloaded from here and Weblogic Server 11g (10.3.1) from here. Make sure you have patched your weblogic server with patch 6W2W if you use Weblogic Server 10.3

Deploy the coherence-web-spi.war as a shared library to your Weblogic server instance. To start a Oracle Coherence web-session cache server, create a cache-websession-server.sh in the root of your COHERENCE_HOME. Copy/paste the following contents to cache-websession-server.sh:


# This will start a cache server

# specify the Coherence installation directory

# specify the JVM heap size

if [ ! -f ${COHERENCE_HOME}/bin/cache-server.sh ]; then
echo "coherence.sh: must be run from the Coherence installation directory."

if [ -f $JAVA_HOME/bin/java ]; then


$JAVAEXEC -server -showversion $JAVA_OPTS -cp "$COHERENCE_HOME/lib/coherence.jar:$COHERENCE_HOME/lib/coherence-web-spi.war" -Dtangosol.coherence.management.remote=true -Dtangosol.coherence.cacheconfig=WEB-INF/classes/session-cache-config.xml -Dtangosol.coherence.session.localstorage=true com.tangosol.net.DefaultCacheServer

That's all what's needed to set up your test environment.

The web application is a JSF web application consisting of a simple JSF page that displays a button to increase a counter. The counter value is stored in a JSF managed bean (session-scoped) attribute. The managed bean is session scoped to ensure that the counter is saved in the Coherence data grid. Storing the complete managed bean is not a must-have requirement, but it is an easy way and suitable for this simple case. Oracle Coherence provides functionality to determine which objects have to be stored in the Oracle Coherence data grid and which not. This is explained later in this posting.

I assume you know how to make such a simple JSF application so I will skip that. The only thing you have to make sure is that you add the coherence.jar library to your project.

To enable Coherence*Web for in-memory session management, the only thing you have to add is a weblogic.xml file and add the following library reference to it:


(The JSF reference makes the JSF libraries available to web application)

Bundle the application in a war file and deploy it to the Weblogic Server Domain in the same server in which you have deployed the coherence-web-spi.war.

Note: The JSF application makes use of WAR-scoped Coherence session management. Other variants are EAR-scoped and application server scoped. The last two variant allows you to share session data between web applications...but be careful with this feature!

Start 1 or more Coherence web-session-cache instances to create a Oracle Coherence data-grid by executing the cache-websession-server.sh several times...(notice how easy it is to create a Oracle Coherence cluster and check the logging output to see the Coherence actions to manage the cluster) . Now we have a data grid to store the session data in, you can browse to your web application and hit the button several times to set the counter value. As a final test: shutdown the Weblogic server....wait a second...start the server again and open your web application...the previous counter value is still there!

Other features & benefits
- Session management models
Oracle Coherence*Web supports three different session management models to support different types of web applications:

  • The traditional model -> suitable for small applications with small session objects

  • The monolithic model -> same as traditional model but without object sharing issues

  • The split model -> suitable for web applications with large session object

- Distribution controller
The Coherence*Web distributed controller functionality allows you to manage which objects has to be stored locally in the server heap (only local accessible) or distributed (shared across multiple servers) in the Coherence data grid and at what moment in the life-cycle of a user session a object should be stored in a Coherence data grid. This feature has several useful use cases, for example to reduce the migration effort to migrate a non-distributed application to a distributed one.


Khad said...

Thanks for the post on Coherence. I am trying to test a simple Coherence example in OSB. Can you please let me know where to include this "cache-config.xml" so that it gets picked up by the OSB Proxy Service during runtime. I have inclueded in the jar file which I am using in the Java Callout but no luck. Also, I have add the file to Oracle Weblogic Domain libraries but no progress. If you know the steps, please kindly post the same. Thanks.

Sadia said...

Hi Tom,

I am doing a simple BPEL process with oracle coherence. I have tried with simple type variable to store those in cache and it worked for me.But I want to store XSD data in cache. Can you please give me some clue how to implement those. It will be really nice of if. Currently I am following the mentioned link:

Mike said...

I also tried the same test and it worked great for me. I got bit difficulty in finding jar file for it and essential xml file but after adding it worked brilliantly.
sap project management