tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Tomcat clustering
Date Mon, 21 Apr 2008 13:32:03 GMT
Hash: SHA1

Ken, wrote:
| In tomcat, you can eaily config all session data to be replicated among
| nodes. How about only replicate particular object(s)? e.g. Only the login
| session to be replicated so that I can kick out multiple login users,
| I don't want other session data (order form / credit card form) to be
| replicated?

Any Serializable object in the session will be replicated to other nodes
in the cluster (using standard clustering techniques).

One way to prevent certain objects from migrating it simply to make them
non-serializable. I think this is a brute-force hack, but it will work.

A better solution would be to create a pair of wrapper classes and an
interface like this:

public interface Wrapable {
~    public Object getObject();

public class ReplicableWrapper
~    implements Wrapable, Serializable
~    private Object _o;

~    public ReplicableWrapper() { }
~    public ReplicableWrapper(Object o)
~    {
~        _o = o;
~    }

~    public Object getObject()
~    {
~        return _o;
~    }

public class NonReplicableWrapper
~    implements Wrapable, Serializable
~    private transient Object _o;

~    public NonReplicableWrapper() { }
~    public NonReplicableWrapper(Object o)
~    {
~        _o = o;
~    }

~    public Object getObject()
~    {
~        return _o;
~    }

Now, any object you want to replicate, you wrap with ReplicableWrapper
and it will be replicated along with the wrapped object. Any object you
don't want replicated, you wrap with NonReplicableWrapper and the
wrapped object will not be replicated (though the wrapper /will/ be

So, on nodes where the data doesn't exist, the fetch from the session
will succeed, but you'll have to check the result of Wrapable.getObject.
The nice thing about using both of these wrapper classes (and treating
them as instances of interfaces) is that your code doesn't have to know
which type of object is in the session (one that is replicable or not).
You can even change your mind about a particular object simply by
changing the code that inserts it into the session.

Hope that helps,
- -chris
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla -


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message