Friday, September 7, 2012

getApplicationSettings()

Years ago we built an administration tool for our servers that allows us to view and administer all of the CF applications currently running. With it we reach into the application scope of each app and can do a number of things,  like refreshing objects cached in the application scope, clearing cached files, and so on.

Anyway, the key behind this magic is the ApplicationScopeTracker object, which lives in the coldfusion runtime.

<cfset apptracker = createObject("java","coldfusion.runtime.ApplicationScopeTracker") />

Above, I have created the variable "apptracker". Let's make a dump of this.


The only method I've ever really played around here with is getApplicationScope(). This function takes the name of an application as argument, and returns the entire application scope of that app.


<cfset appscope = apptracker.getApplicationScope('someappname') />
<cfdump var="#appscope#">


That will give you a dump of your entire application scope. I'll spare you a picture of that since my application scopes tend to be pretty big. :)

What you may not realize at first when looking at the dump though, is that actually we are dealing with an object of type coldfusion.runtime.ApplicationScope, and not a struct. To prove this we can execute a method on it.

<cfdump var="#appscope.getApplicationSettings()#">

And we see this:



Now these functions have been around a pretty long time, and they're  pretty well documented on a lot of other blogs around the web. They can be pretty useful too, although it's important to remember that when working with these  underlying java functions  we are using unofficial and  thus unsupported parts of the Coldfusion engine.

These functions are subject to change and sometimes do. In fact such a change gave me my first CF10 "ouch", which I'll get to in the next post.



No comments:

Post a Comment