I know what you're thinking, executing code at application shutdown is nothing new, as a matter of fact there were 3 other ways to do it before this feature was added to Griffon. Let's review all of them in complexity order.
Shutdown life cycle script
This is the first option that was added to Griffon back in release 0.0 (September 10th 2008 for those keeping count). This script will be called as part of the application's life cycle (inspired by JSR 296 Swing Application Framework), and it's always guaranteed to be executed inside the UI Thread. This script is a single point of entry (good) but it does not allow other artifacts to execute code at shutdown (bad) unless you call them explicitly on that script.Application event handlers
Then came application events at a later release (0.1 to be precise); they revolutionized how artifacts interact with each other. An application will send a ShutdownStart event when the shutdown sequence is initiated. You have the option to register an application event handler at any time; as a matter of fact almost of any type too (supported types are: Script, Map, Closure and beans). Controllers happen to be application event listeners by default, meaning that the following code is validApplication event handlers are guaranteed to be called outside of the UI thread always.
GriffonApplication subclass
I almost decided to not write about this option as it is not for the faint of heart. Actually it is not that bad as it sounds, it's just that creating a GriffonApplication subclass is rarely needed. But if you do, then you have the option to override the shutdown() method.All these options allow you to execute code while the shutdown sequence is in process, however none of them let you abort the sequence (unless you go with the subclass option, but why complicate yourself?).
Enter the ShutdownHandler interface.
ShutdownHandler
This interface defines two handy methods- boolean canShutdown(GriffonApplication app) - informs the application that the shutdown sequence must be aborted if the return value is false.
- void onShutdown(GriffonApplication app) - executes the code as part of the shutdown sequence.
You will find more info on these features and other at the Griffon Guide.
Keep on Groovying!