Friday, October 04, 2002

Get CFMX Version of the CFML Reference to Studio and HomeSite+ Help Tab

If you're running CF4.5 or 5 of Studio, you may be interested in having the CFMX version of the CFML Reference available in the Help Reference Tab in Studio (Help>Help References Window). Also, folks running HomeSite+ may have noticed that there, too, the help reference doesn't include any CF manuals at all. Grr.

(I'm not referring here to the help shown when you press F1 on a tag or function, but instead the actual help tab listing several available books.)

Macromedia has solved the problem, at least a little. You can go to http://download.macromedia.com/pub/homesite/updates/cfml_ref.zip and download a zip file. Follow the instructions in the CFMLRef_install.txt file on where to install it and optionally how to improve its appearance inside the help tab once installed (by editing the booktree.xml file it talks about). This will cause you to have the CFMX version of the CFML Reference manual available in the help, but not the other CFMX manuals.

While the instructions apply to HomeSite+, they're equally applicable to previous releases of HomeSite and Studio. Try it!

BTW, if you're still using Studio 4.5 or 5 and want to update those, such as to add patches that came out after the product's release or to get tag help, insight and completion for CF 5 in Studio 4.5, those are all separate updates. See my blog entry of August 1 for more details.

How CFMX creates the filename for the compiled version of your CF code

In previous bog entries I've talked about compilation and precompilation of CFMX code into Java. And I've shared how all CF templates get compiled into the one [cfusionmx]\wwwroot\WEB-INF\cfclasses directory. 

Ever wonder how CF creates that file name? A CF template named Setsession.cfm might lead to a class file named cfsetsession2ecfm1011928409.class.  The "cf" is always there, while the next part is the file name and extension, but with "2e" where the period in the filename was. The number that follows represents a hash of the file/folder name.

Here are the details from Mike Nimer at Macromedia:
How CFMX creates the .class name, or how you can find the name of the .class file you want to delete

The formula is: "cf" + filename + hashCode

The fully canonicalized filename is used, with "/" as the directory separator. The following substitutions are made in the filename:
1.) / becomes __
2.) any other character which would be illegal in a Java identifier is represented as 2 hex digits

hashCode is the hashCode() of the File object which represents this file as documented at http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#hashCode()

If the hashCode() is negative, it is exclusive-OR'd with 0xFFFFFFFF to get the value used by ColdFusion.
It seems that hashcode call uses the filename AND the folder, as even two files in the same directory could end up with hashcode values that are different. 

You can prove this by creating two templates in the same folder, with distinctive names that you can readily identify, and then save and execute those pages, and view the latest class files created in the cfclasses folder. Those distinctively named files in the same folder may show having the same or different hashcodes. 

So sadly, this is like a one-way hash: cf can figure out what file exists in the cfclasses for a given filename/folder it wants to run, but we can't look at that hashcode and figure out what folder that file was in. At least we can see the name: though again you may well see many classes with the same name, for different folders in which a given filename may live. 

And note that for components (CFCs), note that there is a class for each method in that cfc (technically there is also a class for each cffunction in a cfm, as well). So you could have far more class files than you may expect if you somehow had an idea of how many cfm templates you had. :-)

Thursday, October 03, 2002

Pausing your CFMX code

Folks have often wanted to pause their CFcode, particularly when wanting to simulate some sort of long-running task. Usually they use a CFLOOP, but now that CMX is built upon Java, there is a better and less resource intensive way. Java has a "sleep" method in the java.lang.Thread object. You can get a wait by doing the equivalent:

<cfobject type="JAVA" name="obj" class="java.lang.Thread" action="CREATE">

<cfset obj.sleep(10000)>

This will pause 10 seconds.

CF_SLEEP

To make it even easier, I've created a custom tag to handle this, called cf_sleep. It's available both at the DevExchange and via my site. You would use it in the form:

<cf_sleep seconds="nn">

SLEEP UDF

It's also available as a UDF, in which you might use it in the form:

<cfinclude template="sleep_udf.cfm">
<cfset tmp=sleep(2)>

Believe it or not, this approach works in CF5 (and 4.5) as well as MX, since the ability to call Java objects was introduced back then.