For many Cocoon applications, there is the need to initialize Context, Session and Request (C/R/S) attributes, e.g. with database connections, and dispose those attributes after use so there are no leaks. Right now, there are several methods for hooking into C/R/S creation and destruction: ServletContextListener and HttpSessionListener from the Servlet API for Requests and Sessions, using o.a.c.RequestListener for Requests or even subclassing the Cocoon Servlet. This has several disadvantages:
1. It's ugly. You use different APIs (Cocoon and Servlet API) to achieve similar goals. When you're done, you don't have a Cocoon application, you have a Cocoon & Servlet container application. What about an easy switch to Cocoon's 'batch mode'? 2. It's not that easy to access the Cocoon API from the servlet API functions. For example, ServletContextListener.contextInitialized is called before the Cocoon servlet is initialized. This means there's no ComponentManager available, so no access to Avalon/Cocoon components if you need them to initialize the session. 3. Although the order of calls is well defined (at least I hope so :), it still takes more time to figure out than a common API with a well-defined contract. 4. Lazy initialization of session and context attributes depends on synchronization (mainly done on the session and context objects) which poses its own problems, as seen in [1]. When there's a defined initialization hook before the C/R/S goes to work, you don't need synchronization. And when you need lazy initialization, you can use a lightweight proxy object. When you create the proxied heavyweight, you can synchronize on the proxy instead of the whole session or even context. How about introducing C/R/S listeners in Cocoon that are notified of creation and destruction events? Something like Cocoon.addSessionListener(SessionListener)? Since this would make my life easier, too, I would gladly help to write it... Regards, Jochen [1] http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=111574488018276&w=2
