Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

RE: SOLVED - commons-logging logger instances - how to initialize in replicated session objects

Richard Mixon (qwest)

2005-02-13

Replies:

In case anyone else ends up with similar problems trying to get session
replication to work for objects that have a commons logging (or other
similar) non-serializable instance variable), here's how I solved it.

I created the following abstract class with the two methods "readObject"
and "readObjectNoData" (not sure this one is really needed). All of my
classes that might bet saved in a session and be replicated drive
directly/indirectly from this class. I was hoping for something a bit
more elegant, but it works for now.

Thanks Trond for the idea.

Any comments or criticisms are welcome.

Thanks - Richard

package com.acme.common.util;
import java.io.Serializable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**Loggable Object Class.
* <p>Abstract class to derive business and utility
* objects from that require logging support and that
* may be serialized (e.g. for Session replication, etc.).
*/
public abstract class LoggableObject implements Serializable {
  private static final long serialVersionUID = 1L;
  public transient Log log = LogFactory.getLog(getClass().getName());
  private void readObject(java.io.ObjectInputStream stream) throws
java.io.IOException, ClassNotFoundException {
    stream.defaultReadObject(); // Let default behaviour occur (i.e.
handle non-static, non-transient fields)
    if (log == null) { // Initialize log instance if it is null
       log = LogFactory.getLog(getClass().getName());
    }
  }
 private void readObjectNoData() throws java.io.ObjectStreamException
{
    if (log == null) { // Initialize log instance if it is null
       log = LogFactory.getLog(getClass().getName());
    }
  }
}


-----Original Message-----
From: Richard Mixon (qwest) [mailto:rnmixon@(protected)]
Sent: Saturday, February 12, 2005 6:43 AM
To: Tomcat Users List
Subject: RE: commons-logging logger instances - how to initialize in
replicated session objects


Thanks Trond, I had forgotten about readObject.That may be a better
option than creating yet another utility method.

Trond G. Ziarkowski wrote:
> Hi,
>
> I'm maybe stepping out of my territory here, but I think that static
> members are not serialized/deserialized. To re-initialize your static
> logger maybe you should try to implement the
> readObject(java.io.ObjectInputStream in) method from the
> java.io.Serializable interface something like this:
>
> readObject(...) {
>   super.readObject(...);
>   log = LogFactory.getLog(...);
> }
>
> Hope this is of some help
>
> Trond
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
> For additional commands, e-mail: tomcat-user-help@(protected)


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.