A
andrewfsears
I can't seem to get my head around this one. For reasons of having my
application in a cluster/failover setup, I want to be able to store
any data that is in session, and have it transferred to the other
server in case the first goes down...
So, I've added "implements Serializable" to my objects, and for the
most part, everything is saved in the session, and loads seamlessly
after I've shutdown the first server. I'm using a file persistence
setup, and I can see the values being saved there as well.
Now, here's the tricky part. There is one type of value that isn't
being saved in the session. It is a list of objects that is defined
by an interface. For example:
<code>
public class MyClass implements Serializable {
private static final long serialVersionUID = some_long;
private List<Shape> shapes;
// getter and setter for shapes here;
public addShape(Shape shape) { shapes.add(shape); }
}
public interface Shape { ... }
public class Square implements Shape, Serializable {
private static final long serialVersionUID = some_long;
....
}
public class Circle implements Shape, Serializable {
private static final long serialVersionUID = some_long;
....
}
</code>
Now, somewhere along the line, I'll have some commands like (make up
constructors as I go along here):
<code>
MyClass blah = new MyClass("This is my class with 3 items in the
list of shapes.");
blah.addShape( new Circle("circle1", 3) );
blah.addShape( new Square("square1", 5) );
blah.addShape( new Circle("circle2", 8) );
</code>
I kill the server, the session file is created with the instance of
blah, and the string will be saved as one of the attributes. But the
three shapes are not there.
If, instead of List<Shape>, I made it List<Square>, and the three
"addShape()" lines were all for squares, then they would appear in
that session file.
Does anyone have idea why this might be happening, and if so, is there
a solution out there?
Thanks in advance, Andy
application in a cluster/failover setup, I want to be able to store
any data that is in session, and have it transferred to the other
server in case the first goes down...
So, I've added "implements Serializable" to my objects, and for the
most part, everything is saved in the session, and loads seamlessly
after I've shutdown the first server. I'm using a file persistence
setup, and I can see the values being saved there as well.
Now, here's the tricky part. There is one type of value that isn't
being saved in the session. It is a list of objects that is defined
by an interface. For example:
<code>
public class MyClass implements Serializable {
private static final long serialVersionUID = some_long;
private List<Shape> shapes;
// getter and setter for shapes here;
public addShape(Shape shape) { shapes.add(shape); }
}
public interface Shape { ... }
public class Square implements Shape, Serializable {
private static final long serialVersionUID = some_long;
....
}
public class Circle implements Shape, Serializable {
private static final long serialVersionUID = some_long;
....
}
</code>
Now, somewhere along the line, I'll have some commands like (make up
constructors as I go along here):
<code>
MyClass blah = new MyClass("This is my class with 3 items in the
list of shapes.");
blah.addShape( new Circle("circle1", 3) );
blah.addShape( new Square("square1", 5) );
blah.addShape( new Circle("circle2", 8) );
</code>
I kill the server, the session file is created with the instance of
blah, and the string will be saved as one of the attributes. But the
three shapes are not there.
If, instead of List<Shape>, I made it List<Square>, and the three
"addShape()" lines were all for squares, then they would appear in
that session file.
Does anyone have idea why this might be happening, and if so, is there
a solution out there?
Thanks in advance, Andy