You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Stanimir Komitov <st...@devbg.piranko.com> on 2009/02/10 17:25:12 UTC

How to exclude some classes to being serialized in sharing session with clustered tomcats?

Hi,

How to exclude some classes to being serialized in sharing session with
clustered tomcats?
I`m using hibernate, spring, java mail, apache commons dbcp, pool ...
and to serialize/deserialize sessions all the classes must implement
Serializable (or Externalizable), and I think that it`s not a solution
to correct all classes I use in all APIs. And why the application scope
beans are serialized too?

Thanks

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


Re: How to exclude some classes to being serialized in sharing session with clustered tomcats?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stanimir,

On 2/10/2009 11:25 AM, Stanimir Komitov wrote:
> How to exclude some classes to being serialized in sharing session with
> clustered tomcats?

Do you mean avoiding serializing some /objects/ in shared sessions?

I can see your problem. You want:

1.  An object in the session
2a. The object's class is not serializable
or
2b. The object is very large
3.  The session should properly migrate between cluster nodes

The only way I can think of doing this is writing an object wrapper.
Something like this:

public class TransientObjectWrapper
  implements Serializable
{
  private static final Object UNINITIALIZED = new Object();
  private transient final Object _wrapped;

  public TransientObjectWrapper(Object wrapped)
  {
    _wrapped = wrapped;
  }

  public Object get()
  {
    return initialized() ? _wrapped : null;
  }

  public boolean initialized()
  {
    return _wrapped != UNINITIALIZED;
  }

  // Capture de-serialization events and mark the wrapped
  // object as uninitialized
  private void readObject(ObjectInputStream in)
  {
    in.defaultReadObject();

    _wrapped = UNINITIALIZED;
  }
}

> And why the application scope beans are serialized too?

Objects placed in the application scope do not need to be serializable.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmR4fAACgkQ9CaO5/Lv0PBJJQCfZPhLXNWLOEzP6V8GsJWfiCxQ
fIcAnjISVtRwyOAl87xKZECvkXLZsWEA
=ZN8E
-----END PGP SIGNATURE-----

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


Re: How to exclude some classes to being serialized in sharing session with clustered tomcats?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stanimir,

On 2/11/2009 10:10 AM, Stanimir Komitov wrote:
> when the application is restarted, the session scoped beans are
> serialized on stop and restored on requesting the same session after
> start, but when the class is deserialized, transient fields are null.
> Is there any "easy" way to restore transient fields references from the
> new session or at deserialization to get only available fields from the
> object, not the whole object?

How about using the standard serialization framework built-into Java.
You've come up with the right idea, you just haven't researched it:

http://java.sun.com/developer/technicalArticles/Programming/serialization/
http://www273.pair.com/med/columns/Durable4.html

...or any other Java Serialization tutorial will show you how to
customize the process of deserialization. As long as you have enough
non-transient information in the object to re-build that transient
information, you should be fine.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmTAUEACgkQ9CaO5/Lv0PBBcACeO2jPGz+ialJohaBfRCGo7IVc
7M4AnR4TD4AjsTg55qc+TXi+ENcemuJQ
=238/
-----END PGP SIGNATURE-----

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


Re: How to exclude some classes to being serialized in sharing session with clustered tomcats?

Posted by Stanimir Komitov <st...@devbg.piranko.com>.
Ok, I`m using jsf and have managed beans with session scope and
properties other managed beans. Most of them have application scoped
beans references as properties, which makes connection to DB...and...
these fields are defined as transient to prevent serialization.

eg.
class TestBean implements Serializable {
        private String xyz;
        private transient MyService service;
        :
}

in faces-config.xml
<managed-bean>
        <managed-bean-name>testBean</managed-bean-name>
  <managed-bean-class>aaa.bbb.ccc.ddd.eee.TestBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
        <managed-property>
		<property-name>service</property-name>
		<property-class>aaa.bbb.ccc.ddd.MyService</property-class>
		<value>#{service}</value>
	</managed-property>
</managed-bean>

but when the application is restarted, the session scoped beans are
serialized on stop and restored on requesting the same session after
start, but when the class is deserialized, transient fields are null.
Is there any "easy" way to restore transient fields references from the
new session or at deserialization to get only available fields from the
object, not the whole object? Maybe a wrapper of StandardManager!

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


Re: How to exclude some classes to being serialized in sharing session with clustered tomcats?

Posted by Kees Jan Koster <kj...@gmail.com>.
Dear Stanimir,

> How to exclude some classes to being serialized in sharing session  
> with
> clustered tomcats?
> I`m using hibernate, spring, java mail, apache commons dbcp, pool ...
> and to serialize/deserialize sessions all the classes must implement
> Serializable (or Externalizable), and I think that it`s not a solution
> to correct all classes I use in all APIs. And why the application  
> scope
> beans are serialized too?


They are probably referenced from objects in your sessions. Please  
read up on the Serializable and Externalizable interfaces and Java's  
transient keyword.
--
Kees Jan

http://java-monitor.com/forum/
kjkoster@kjkoster.org
06-51838192

Human beings make life so interesting. Do you know that in a universe  
so full of wonders,
they have managed to invent boredom. Quite astonishing... -- Terry  
Pratchett


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


Re: How to exclude some classes to being serialized in sharing session with clustered tomcats?

Posted by Mark Thomas <ma...@apache.org>.
Stanimir Komitov wrote:
> Hi,
> 
> How to exclude some classes to being serialized in sharing session with
> clustered tomcats?
> I`m using hibernate, spring, java mail, apache commons dbcp, pool ...
> and to serialize/deserialize sessions all the classes must implement
> Serializable (or Externalizable), and I think that it`s not a solution
> to correct all classes I use in all APIs. And why the application scope
> beans are serialized too?

If you don't want it serialized, don't put it in the session. More seriously,
most of what you quote above should never go anywhere near a user's session.

Mark

> 
> Thanks
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 



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