tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Tomcat clustering
Date Mon, 21 Apr 2008 13:32:03 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ken,

Ken--@newsgroupstats.hk 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,
while
| 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
replicated).

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgMl08ACgkQ9CaO5/Lv0PBGyQCeJJ1p+oW4CqwPzTDApWrWn/iI
ys0AoLTD066eC2kvkEfefvUDIZys4ItT
=Dyh5
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message