jruby-user - How to receive start and stop events for rails application deployed in tomcat?

by Rakesh Aroraon 2010-07-27T15:00:55+00:00
I am trying to find the best way to implement ServletContextListener for my
rails application deployed in tomcat to receive application start and stop
events.
Thanks,
-Rakesh
I am trying to find the best way to implement ServletContextListener for my rails application deployed in tomcat to receive application start and stop events. Thanks,-Rakesh
Hi Rakesh
Am 27.07.2010 um 17:00 schrieb Rakesh Arora:
this is what we use
first change your web.xml:

full.package.path.to.your.ServletContextListnerClass
org.jruby.rack.rails.RailsServletContextListener

And
package full.package.path.to.your;
public class ServletContextListnerClass implements ServletContextListener {
final static Logger logger = Logger.getLogger(ServletContextListnerClass.class);
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext();
MyApp app = MyApp myApp(ctx.getRealPath("/"));
ctx.setAttribute("myApp", app);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
logger.info("My application is being stopped...");
MyApp app = (MyApp) sce.getServletContext().getAttribute("myapp");
if (app != null) {
app.shutdown();
logger.info("My application shutdown complete, good bye!");
} else {
logger.warn("No application instance found, skipping shutdown");
}
}
}
Checkout the Java Servlet specification for more details.
I'd be interested in a more clever way to handle the application instance. :)
Cheers
Reto Schüttel
http://xircles.codehaus.org/manage-email
Am 27.07.2010 um 17:43 schrieb Reto Schüttel:
Meh, removed the wrong things, this should be:
The ctx.getRealPath("/") is used to know the place of the public folder. Usually you wont need this.
Cheers,
Reto
http://xircles.codehaus.org/manage-email