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

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 A.:

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.

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. :slight_smile:

Cheers
Reto
Schüttel---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Am 27.07.2010 um 17:43 schrieb Reto Schüttel:

Hi Rakesh

public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext();
MyApp app = MyApp myApp(ctx.getRealPath("/"));
ctx.setAttribute(“myApp”, app);
}

Meh, removed the wrong things, this should be:

MyApp app = new MyApp(ctx.getRealPath("/"));

The ctx.getRealPath("/") is used to know the place of the public folder.
Usually you wont need this.

Cheers,
Reto

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs