Hi Will!

It seems like a strange thing to do, to write directly into the session object. 
I'd think twice about that.

Not only does the Session have a lifecycle of its own (the session may not even 
be valid any more by the time the Executor gets round to writing in it), but I 
think the AppServers more or less assume the session is only used from the 
web-layer. Deeper Layers like EJB tend to have their own session models.

I think it might be better to have a kind of "Broker" between the session and 
the executor. Eg:


*         WebApp (front-end action) asks the Broker to start a long-running 
computation.

*         Broker returns a "Ticket" to the WebApp, and begins computation.

*         The WebApp stores the Ticket in the users session.

*         The WebApp can use the Ticket to query the computation status, or 
retrieve the results.

*         When the Broker finishes a computation, it puts the result in a 
temporary "Result-Storage" for later retrieval.

*         WebApp can retrieve results via the ticket.

*         After a configurable time (larger than the session time!), results 
are deleted from the Result-Storage, to make sure it does not overflow.

Regards from Vienna,

Richard


Von: [email protected] [mailto:[email protected]] 
Im Auftrag von Rob Blake
Gesendet: Sonntag, 08. Mai 2011 15:26
An: Magnolia User-List
Betreff: Re: [magnolia-user] [OT] getting a Session by its ID / registering 
HttpSessionListener

Could you use a Servlet Filter to achieve what you want? For example: intercept 
the request in the filter to obtain the HttpSession object, start the 
background processing using your Executor and then resume the request?

You could then register the filter via a module as described here: 
http://documentation.magnolia-cms.com/reference/request-handling/filters.html, 
meaning that the web.xml remains untouched?

One benefit I can see of using the HttpSessionListener is that you are notified 
of both create and destroy lifecycle events, meaning that you could cancel the 
work if the session is invalidated whilst processing is taking place. I guess 
it really depends on your requirements.

cheers,

Rob

On Sat, May 7, 2011 at 12:41 PM, Will Scheidegger 
<[email protected]<mailto:[email protected]>> wrote:

Dear Magnolians

I'm struggling a bit with the following situation:

We need to execute a task that can sometimes be quite expensive and do not want 
to block the request-response-loop for that time. Instead we want to return a 
page immediately and have the task executed in the background. Once the task 
has been completed, it should update the users session object.

For the background execution we're planing to use 
java.util.concurrent.Executor. However I have not seen an easy way to get the 
users session object without registering a HttpSessionListener in the web.xml. 
We really would like to leave the web.xml untouched (in order to avoid update 
nightmares). Does anyone know a good way to do this? Passing the session object 
to the runnable in the background process is not a good idea, right?

Thanks!
-will


----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: 
<[email protected]<mailto:[email protected]>>
----------------------------------------------------------------



----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to