FAQ
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

Search Discussions

  • Andrus Adamchik at Feb 22, 2012 at 7:06 am
    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
  • Andrus Adamchik at Feb 22, 2012 at 7:09 am
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedFeb 21, '12 at 10:13p
activeFeb 22, '12 at 7:09a
posts3
users2
websitecayenne.apache.org

2 users in discussion

Andrus Adamchik: 2 posts John Huss: 1 post

People

Translate

site design / logo © 2021 Grokbase