tags:

views:

183

answers:

1

Hi all,

I am currently working on one messy web application. In this application there is a class which holds all the datasources. And when ever need to connect to specific datasource, method in the instance of class is called with parameter to select datasource.And class is like follows

   public class MyConnection implements Runnable,DbConnection, Serializable
   { 
       private static final long serialVersionUID=2007L;
       public static transient DataSource FirstDatasource;
       public static transient DataSource SecondDatasource;
           BaseDbConnection _bidc;
           ....

And in each page this object is get and set to session(I don't know why like this). And it works fine with current setup. (clustering, load balancing etc..)

But my work is to implement fail-over , and when I enable session replication(in memory - simple tcp), writing the session is failing and its throwing following exception

 org.apache.catalina.ha.session.DeltaManager requestCompleted
 SEVERE: Unable to serialize delta request for sessionid [FE02AF01C76F41D042FE04692462D983.tomcat1]
 java.io.NotSerializableException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
 at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
 .....

Since there are more than "I can count" no of pages, its not easy to replace the code which sets the connection object in session from each and every page. And the complete app is based on this connection object(Datasources also plays an important role).

Is there way i can change this class so that it can be persisted in session?

Thanks in advance

+2  A: 

If I understood correctly, I would say that replicating a DataSource is not correct, it can not work.

What need to be done is, after deserialing, to get a new (local) DataSource that corresponds to the need, and set it in the field. It is possible that this happens already in your code, look for a readResolve method.

If some parameters are needed to know which DataSource, they can be serialized themselves (because they are no DataSource, they could be just Strings for example).

KLE