cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Where to put the ServerRuntime in a servlet app?
Date Wed, 22 Feb 2012 07:09:24 GMT
And since ROPHessianServlet already does something similar to what CayenneFilter does, let
it handle startup and shutdown, but in other servlets, simply retrieve an instance that ROPHessianServlet
created from the application scope:

CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);

WebUtil.getCayenneRuntime() is a thin wrapper for servletContext.getAttribute(WebUtil.CAYENNE_RUNTIME_KEY);

Andrus

On Feb 22, 2012, at 10:05 AM, Andrus Adamchik wrote:

> Yes, normally a Cayenne stack should be shared between all servlets, filters, etc. in
a webapp. "Application" scope is provided by javax.servlet.ServletContext per servlet specification.

> 
> Bootstrapping ServerRuntime and placing it in the app scope can be done via a variety
of ways - Filter.init, Servlet.init, ServletContextListener.contextInitialized. CayenneFilter
provided by Cayenne is a good template for how ServerRuntime should be started and stopped:
> 
> https://github.com/apache/cayenne/blob/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
> 
> Andrus
> 
> 
> On Feb 22, 2012, at 1:12 AM, John Huss wrote:
>> I'm new to Servlets and containers and all that.  If I have multiple
>> servlets, where is the best place to create and store a reference to the
>> cayenne ServerRuntime (I'm using 3.1)?  One of my servlets is an
>> ROPHessianServlet and it gets the ServerRuntime information from the
>> web.xml file.  But the others are just regular servlets.  I want to avoid
>> creating a bunch of different runtimes and just have one.
>> 
>> Thanks,
>> John
> 
> 


Mime
View raw message