root / framework / trunk / extensions / lexicon / cf / lock.cfm

Revision 123, 2.6 kB (checked in by scorfield, 3 years ago)

Addresses #19 by adding lock and updating the skeleton code to use it.

Line 
1<cfscript>
2        // example custom verb that compiles to a <cflock> tag
3        // usage:
4        // 1. add the lexicon declaration to your circuit file:
5        //    <circuit xmlns:cf="cf/">
6        // 2. use the verb in a fuseaction:
7        //    <cf:lock name="myNamedLock" timeout="10" type="exclusive">
8        //        ... some locked code ...
9        //    </cf:lock>
10        //    <cf:lock scope="session" timeout="10" type="readonly">
11        //        ... more locked code ...
12        //    </cf:lock>
13        //
14        // how this works:
15        // a. validate the attributes passed in (fb_.verbInfo.attributes)
16        // b. in start mode, generate the required CFML
17        // c. in end mode, generate the required CFML
18        //
19        if (fb_.verbInfo.executionMode is "start") {
20                //
21                // validate attributes:
22                // one of name or scope must be present:
23                if (not structKeyExists(fb_.verbInfo.attributes,"name")) {
24                        if (not structKeyExists(fb_.verbInfo.attributes,"scope")) {
25                                fb_throw("fusebox.badGrammar.requiredAttributeMissing",
26                                                        "Required attribute is missing",
27                                                        "Either the attribute 'name' or 'scope' is required, for a 'lock' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
28                        } else {
29                                // scope is present:
30                                fb_.nameOrScope = 'scope="#fb_.verbInfo.attributes.scope#"';
31                        }
32                } else {
33                        if (structKeyExists(fb_.verbInfo.attributes,"scope")) {
34                                // oops! both are present!
35                                fb_throw("fusebox.badGrammar.requiredAttributeMissing",
36                                                        "Required attribute is missing",
37                                                        "Either the attribute 'name' or 'scope' is required, for a 'lock' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
38                        } else {
39                                // name is present:
40                                fb_.nameOrScope = 'name="#fb_.verbInfo.attributes.name#"';
41                        }
42                }
43                //
44                // throwontimeout is optional:
45                if (structKeyExists(fb_.verbInfo.attributes,"throwontimeout")) {
46                        fb_.throwOnTimeout = ' throwontimeout="#fb_.verbInfo.attributes.throwontimeout#"';
47                } else {
48                        fb_.throwOnTimeout = '';
49                }
50                //
51                // timeout is required:
52                if (not structKeyExists(fb_.verbInfo.attributes,"timeout")) {
53                        fb_throw("fusebox.badGrammar.requiredAttributeMissing",
54                                                "Required attribute is missing",
55                                                "The attribute 'timeout' is required, for a 'lock' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
56                }
57                //
58                // type is optional:
59                if (structKeyExists(fb_.verbInfo.attributes,"type")) {
60                        fb_.type = ' type="#fb_.verbInfo.attributes.type#"';
61                } else {
62                        fb_.type = '';
63                }
64                //
65                // start mode:
66                fb_appendLine('<' & 'cflock #fb_.nameOrScope# timeout="#fb_.verbInfo.attributes.timeout#"#fb_.throwOnTimeout##fb_.type#>');
67        } else {
68                //
69                // end mode:
70                fb_appendLine('<' & '/cflock>');
71        }
72</cfscript>
Note: See TracBrowser for help on using the browser.