Reinitializing an Application Using Blackstone Events

One of the most useful tags I’ve ever written is the init tag. Typically, it goes
in your Application.cfm file, and the body of the tag gets executed only the first
time it’s encountered, which means it’s the perfect place to put initialization
code. You can also force the body to execute again by passing a certain query string
parameter in with any request. This is very useful during development when you need
to flush cached components or other data.

As I started thinking more in Blackstone terms, however, I wondered what the Blackstone
equivalent on the init tag would be. Of course, the init tag still works in Blackstone
as does all the CFMX 6.1 code I’ve run so far, but I wanted to take advantage of
the new event handling
mechanisms available in Blackstone
. So here’s what I’ve come
up with so far.

Now, I handle application initialization using the onApplicationStart event. That
takes care of running the code only once (usually when the application receives
its first request since the server was last started). I then added the following
inside my onRequestStart event handler:

<!--- Re-initialize the application, if necessary --->
<cfif structKeyExists(url, "restart") and url.restart>
<!--- Invoke onApplicationStart event --->

Now, when I want to invoke the onApplicationStart event, I just append a restart=true
parameter to any request, and my application is reinitialized without me having
to restart the server.

One Response to Reinitializing an Application Using Blackstone Events

  1. Behrang says:

    But how do you invoke onApplicationStart event??? By writing something like this.onApplicationStart()??