We have a scenario with a webapp implemented as a number of OSGi
bundles. We want to do bundle updates to transparently deploy bugfixes etc to the running system. Assuming an update cycle with refresh and bundle restarts, this will cause problems when objects, whose classes are being reloaded, have been stored on the HttpSession
leading to ClassCastException
s.
We are looking at several different ways to make bundle updates possible without losing state in logged-in sessions. To simplify the session state access dependency graph we are thinking about setting the following restrictions:
- a bundle can only access its own session state, i e no direct access to state set by another bundle (forces to instead call bundle API to indirectly access its state)
- the Java classes of objects added to session state should come from the bundle itself (to avoid having our session state affected by updates of other bundles than ourselves) These restrictions are really only needed by some of the alternatives below.
So, these are the alternatives we have come up with in some kind of least to greatest implication order:
- Store all state as
java.*
types (String
,List
, etc)
–> state classes are never subject to reloading. - Lock sessions to the service versions its state was created with (by f ex using proxying solutions that forward to the version used earlier by that session)
-> new sessions will pick up updated bundle versions while existing sessions will stay on the old versions. - Serialize session state when updating a bundle and deserialize it back into the new bundle version (like appserver session serialization but on a more granular level)
-> all sessions will pick up the updated bundles but requires that serialized state is compatible. - Avoid updating stateful services as long as there are active sessions, making use of traditional load balancer techniques to update one appserver at a time
-> longer deploy turnaround and may need more resources. - Avoid stateful
OSGi
services altogether and keep state elsewhere
-> not handling the problem inOSGi
...
Did I miss any interesting alternatives?
What solutions do you recommend?
[although this post explicitly talks about session state the same discussion could apply to other scopes such as conversation state, application state, etc]