Anyone interested ?

This stuff is never simple !

Jules

--- Begin Message ---

jules,

If you want this for fault tolerance, then I would say that the only
reasonable points that you can distribute/persist a session would be:

  + When there are no requests for that session active.
  + When explicitly requested by a knowing application.

I also think it would be better to have an old consistent session
snapshot rather than a recent inconsistent one.

Thus I believe that the weak reference implementation is probably
ideal. Soon after a session is idle, you can passivate it (protecting
against new requests by a sync withing getSession()).

I think you had best always do passivation/activation events otherwise you
are outside of the spec - in which case why use Sessions at all for your persistent
data?  You'd be better off using them as a standard event source and using some other
fault tolerant data layer.

If passivation/activation is too expensive, you can configure timeouts:

  + When session goes idle, wait n secs before passivation to see if it becomes
    active again.

  + After m secs, always passivate an idle session (so that it does not get too old
    if frequently active).


This will give you a mechanism that will moderately frequently take a snap shot
of a session that has at least some chance of being consistent.  It is also fully
compliant with the specification.

The only provision is that users should not store a reference to the session anywhere,
which I think is a reasonable thing to require.

cheers


Jules Gosnell wrote:

> I've considered granularities of various levels
> 
> 1. only flush on SessionManager shutdown.
> 
> This is what the 2.3 servlet spec mandates. It simply gives you enough fn-ality to
> migrate sessions between instances of your webapp or webcontainer.
> My first cut did this.
> 
> 2. flush every time any change occurs
> 
> Could be done - may be too expensive
> 
> 3. flush at some other interval e.g. request, a certain number of changes, a certain
> time interval etc...
> 
> I just picked on request simply because it seemed like the most meaningful 
>granularity.
> At some point there will be a lull in requests and the final flush() will bring the
> stored state back to something that might be meaningful !
> 
> 
> Once you step away from (1) you open several cans of worms. However it is important 
>to
> the JBoss guys to provide some sort of fail-over. (1) does not do this because 
>sessions
> are only flushed if the shutdown was controlled.
> 
> Worm 1 :
> 
> If the attribute you are storing implements HttpSessionActivationListener you are 
>meant
> to send an event notifying it of passivations and activations, since it may wrap an
> expensive resource that needs to be allocated/freed. This is not the sort of thing 
>that
> you want to do on every request. I propose to only send passivation events on 
>shutdown
> and activation events on the following access.
> 
> In the case of an uncontrolled shutdown and access no passivation event will be sent,
> but an activation one will. In this case I print out a warning.
> 
> I suppose I should allow the user to configure that they want the events every time.
> 
> Worm 2 :
> 
> Attributes are stored by value, not reference. This means that if you put an object 
>into
> a session then alter it's contents the session has no way of knowing that it should
> update it's copy of the object. A final passivation during controlled shutdown will
> update the store properly, but fail-over stores may be inconsistent. I have taken the
> approach that if the user wants changes like this reflected in the store, they must 
>call
> setAttribute() again after each such change.
> 
> If the attribute implements HttpSessionBindingListener it expects to be notified of
> changes in it's bindings value. I am currently not notifying of apparent re-bindings 
>in
> this case, although, once again this should probably be configurable.
> 
> 
> That's enough worms for the moment.
> 
> Anyone feel strongly about any of this. I figure it is good just to braindump on the
> lists like this occasionally anyway - in case I am hit by a bus :-)
> 
> 
> Jules
> 
> 
> Greg Wilkins wrote:
> 
> 
>>Jules,
>>
>>I have moved this to jetty-discuss as I think it would be good
>>to get some feedback on the suggestions I'm about to make.
>>
>>Jules Gosnell wrote:
>>
>>
>>>I need to arrange for someone to call my SessionManager after each request
>>>has been processed so that I can flush changes to Session state out to a
>>>distributed store. I figured I could do this with a handler - but I've had a
>>>quick look through the src and now think that handlers are like 'before'
>>>methods, whereas I need an 'around' or 'after' method. Have I missed the
>>>point ? How should i best achieve my goal ?
>>>
>>I don't know if flushing session state on request boundaries is really the
>>right thing to do as:
>>
>>  + There may be multiple requests outstanding and the end of a single
>>    request may well be mid transaction of another.
>>
>>  + The use of request dispatchers may result in multiple flushes being
>>    called.
>>
>>  + Use of servlet sessions in filters complicates the whole issue and
>>    may result in extra or missing calls to flush.
>>
>>  + Request boundaries are not guarenteed to bo recoverable states from
>>    an application point of view.
>>
>>So I have three suggestions as to how to achieve Session flushing:
>>
>>1) Time based.  Extend the access/scavange mechanism so that a session that
>>has not been accessed for some time will be flushed.
>>
>>2) Use weak references so that sessions are flushed when the objects
>>returned from getSession are no longer referenced (ie when all simultaneous
>>requests are complete).
>>
>>To do this you SessionManager would maintain two maps:
>>
>>   id            -->   SessionManager.Session
>>   WeakRef       -->   SessionManager.Session
>>
>>Each SessionManager.Session contains a WeakReference to a WeakSession
>>instance, which is simply a delegation wrapper of the SessionManager.Session.
>>
>>It is the WeakSession that is returned by newSession or getSession.
>>Once all requests have completed, the WeakRef will be enqueued and the SessionManager
>>can read this queue and use the map to find the SessionManager.Session instance that
>>needs to be flushed.   This of course does not work if somebody creates a hard ref
>>to the session?????
>>
>>3) Just put a session.flush() call in the ServletHandler so that it gets
>>called after each servlet request is serviced.  Filters that change sessions
>>and then don't call a servlet will just not get flushed????
>>
>>--
>>Greg Wilkins<[EMAIL PROTECTED]>          GB  Phone: +44-(0)7092063462
>>Mort Bay Consulting Australia and UK.    Mbl Phone: +61-(0)4 17786631
>>http://www.mortbay.com                   AU  Phone: +61-(0)2 98107029
>>
>>
>>For the latest information about Jetty, please see http://jetty.mortbay.
>>
>>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>>
> 
> 
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> 
> 
> 
> For the latest information about Jetty, please see http://jetty.mortbay. 
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 



-- 
Greg Wilkins<[EMAIL PROTECTED]>          GB  Phone: +44-(0)7092063462
Mort Bay Consulting Australia and UK.    Mbl Phone: +61-(0)4 17786631
http://www.mortbay.com                   AU  Phone: +61-(0)2 98107029


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Tiny Wireless Camera under $80!
Order Now! FREE VCR Commander!
Click Here - Only 1 Day Left!
http://us.click.yahoo.com/WoOlbB/7.PDAA/ySSFAA/CefplB/TM
---------------------------------------------------------------------~->

For the latest information about Jetty, please see http://jetty.mortbay. 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

--- End Message ---

Reply via email to