44 CHAPTER 30 Extending ColdFusion with CFX
If the CFX Tag Works with Files
If the guts of the CFX tag are thread-safe, but you are asking the tag to do something like create or
manipulate a file on the server’s drive, then you might want to lock access to the file, rather than to
the tag itself. The
<cflock> tags would still surround the CFX tag in your ColdFusion code, but
you would most likely use the complete filename as the
NAME of the lock, rather than the tag. If the
tag is merely reading the file, you could use
type=”ReadOnly”; if the tag might be creating or chang-
ing the file, you would have to use
type=”Exclusive”.
You would also want to surround other portions of your CFML code that access the same file—
regardless of whether they involve CFX tags—with
<cflock> tags. The <cflock> tags should have
the same
name as the ones around the CFX tag itself, and should use type=”Exclusive” for creation
or modifications and
type=”ReadOnly” if merely reading the file.
Keeping the Page Itself in Mind
It’s worth noting that just because a tag is thread-safe internally, that doesn’t automatically mean
that a ColdFusion page’s use of the tag is thread-safe. For instance, if you were supplying
APPLICA-
TION
or SESSION variables to the various attributes of a CFX tag, or if you were asking the CFX tag
to set variables in the
APPLICATION or SESSION scope, then it is theoretically possible for a logical “race
condition” problem to occur if one page request changes those variables at the same time, perhaps
resulting in some kind of data loss or logical data corruption. If the nature of your application is
such that this could be a problem (and only you can determine that), you should continue to lock.
NOTE
As you probably already know, the need for locking dramatically decreased as of ColdFusion MX. That doesn’t change the fact that
any access to shared resources in CFML pages—whether dealing with CFX tags or not—must be locked if the nature of the application
logic (that means your stuff, not ColdFusion’s internals) is such that problems could arise if multiple threads execute the code at the
same time. For more details on this topic, see the “Introducing the Web Application Framework” chapter in our companion volume,
The Macromedia ColdFusion MX 7 Web Application Construction Kit (Macromedia Press).
Using CFX Tags with Previous Versions of ColdFusion
CFX tags are not something that can only be used with current versions of ColdFusion. The CFX
API was actually the means of extending the server introduced first in the product’s history, predat-
ing CFML custom tags, user-defined functions, and CFCs.
CFX tags written with C++ can be used with any version of the product after (drumroll, please)
ColdFusion 2.0.
CFX tags written with Java can be used with ColdFusion 4.5 or later without any additional soft-
ware. You can use Java CFX tags with version 4.0 using the
<CFX_J> add-on package, which was
freely available from Macromedia’s Web site as of this writing.
Of course, the exception to this rule is the newfound ability for CFX tags to return structures to
ColdFusion pages (which was first introduced in ColdFusion MX). See the “Returning Structures
from CFX Tags” section earlier in this chapter for details.
Commenti su questo manuale