Friday, May 21, 2010

Griffon ShutdownHandler sample

Here is a simple ShutdownHandler (available since 0.3.1) sample. For simplicity, I just made the main controller implement the new ShutdownHandler interface. All it does is to print a message during shutdown, but we can imagine that it could do much more clever things. The most interesting method is canShutdown. In this sample, it always returns true, so the application will normally shutdown. Depending on some conditions, we could make it return false, to prevent the application to shutdown.

import griffon.core.*

class GriffonsampleController implements ShutdownHandler {
 def model
 def view

 void mvcGroupInit(Map args) {
  app.addShutdownHandler(this)
  }
 
 boolean canShutdown(GriffonApplication app) {
  return true;
 }
 void onShutdown(GriffonApplication app) {
  println "Shutting down..."
 }
}

No comments:

Post a Comment