Is there an object that is shared across clustered tomcats that can take attributes and paramaters?
Like an 'application' object. I can add an object to it on one node and pick up that object on another node?
Basically I am looking for a simple solution to sharing data across nodes rather than implementing oscache and jgroups. I am sure I read about something like this years ago but cannot find it now, it may have been depricated.
I'm not an expert in clustering Tomcat but I'm pretty sure Tomcat doesn't replicate objects across a cluster automatically. This isn't even guaranteed for the said session attributes as far as I know. They are replicated to another Tomcat node in your cluster if a client connects to this other node and there is an established session already available (of course Tomcat has to be configured then to actually do session replicating). But I think this mechanism is not meant to make some objects visible to all nodes in a cluster at once.
Why don't you choose the typical solution and use some kind of centralized data store like a database system? I guess you will already have some kind of database in a clustered environment. Isn't this an option for managing shared data?
Another more or less easy to use solution I can think of without using a distributed cache or something like this would be to use Terracotta. Terracotta is able to cluster JVMs across multiple servers and simply make them available to applications as if it was only one JVM. The current version explicitly supports running Tomcat 6 on such a Terracotta cluster. Because for Tomcat and your web application this would seem like running on only one physical server node, attributes you put into the application context would be globally available in your application. Unfortunately I've never used Terracotta for clustering Tomcat myself, so I can't promise you that this approach definitely works but from the documentation and other things I read about this it should be possible.
Joined: Apr 24, 2001
Thanks for the reply Marco,
I am going to look at running tomcat under Terracotta, never though about that approach, thanks.
The app is going to be running under the amazon cloud and it is designed to change the amount of servers automatically as the demand rises and falls. I have tested the sessions and they seem to be able to deal with that quite happily.
One server is going to be running a batch job and I wanted to store it's results in the ServletContext to be shared with the other servers and although the docs say Context Attribute Replication is possible it just won't work.
If Terracotta can deal with servers coming on and off and will truly act like the one node then that could solve a few problems in one go.