PageRenderTime 16ms CodeModel.GetById 13ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/vendor/memcached/com/FutureTask.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 98 lines | 88 code | 8 blank | 2 comment | 12 complexity | 8b409a8e8ee3c2aa0805b94cd48bb08f MD5 | raw file
 1<cfcomponent extends="_base" output="false">
 2
 3	<!----------
 4					Cancel() - returns a boolean - allows you to cancel the operation
 5					get( int, variables.timeunit ) - returns object - when an interger is sent in, you can 
 6							get the result in that amount of time.
 7					get() - returns an object - get the result when it is available.
 8					isCancelled() -  returns boolean - lets you know if the operation was cancelled
 9					isDone() - returns boolean - 
10	---------->
11	<cfset variables._futureTask = "">
12	<cfset variables.inited = false>
13	
14	<cffunction name="init" access="public" output="false" returntype="Any" hint="init func to set the futureTask">
15		<cfargument name="myFutureTask" required="true" type="any" 
16			hint="this must be a future Task returned by the java memcached client otherwise, this will fail.">
17		
18		<cfset variables._futureTask = arguments.myFutureTask>
19		<cfif isObject(arguments.myFutureTask)>
20			<cfset variables.inited = true>
21		</cfif>
22		<cfset super.init()>
23		<cfreturn this>
24	</cffunction>
25	
26	<cffunction name="isDone" access="public" output="false" returntype="boolean" 
27			hint="returns true when the operation has finished. otherwise it returns false">
28		<cfscript>
29			var ret = false;
30			if (variables.inited )	{
31				ret = variables._futureTask.isDone();
32			}
33			if (not isDefined("ret")) {
34				ret = false;
35			}	
36		</cfscript>
37		<cfreturn ret>
38	</cffunction>
39
40	<Cffunction name="isCancelled" access="public" output="false" returntype="boolean"
41			hint="Returns true if the fetch has been cancelled. false otherwise">
42		<cfscript>
43			var ret = false;
44			if (variables.inited )	{
45				ret = variables._futureTask.isCancelled();
46			}
47			if (not isDefined("ret")) {
48				ret = false;
49			}	
50		</cfscript>
51		<cfreturn ret>
52	</Cffunction>
53
54	<cffunction name="cancel" access="public" output="false" returntype="boolean" 
55			hint="cancels the returning result.">
56		<cfscript>
57			var ret = false;
58			if (variables.inited )	{
59				ret = variables._futureTask.cancel();
60			}
61			if (not isDefined("ret")) {
62				ret = false;
63			}
64		</cfscript>
65		<cfreturn ret>
66	</cffunction>
67
68	<cffunction name="get" access="public" output="false" returntype="any" 
69			hint="Gets the result, when available. if the result is not available, it will return an empty string">
70		<cfargument name="timeout" type="numeric" required="false" default="#variables.defaultRequestTimeout#" 
71				hint="the number of milliseconds to wait until for the response.  
72				a timeout setting of 0 will wait forever for a response from the server"/>
73		<cfargument name="timeoutUnit" type="string" required="false" default="#variables.defaultTimeoutUnit#"
74				hint="The timeout unit to use for the timeout"/>
75		<cfscript>
76			var ret = "";
77			// gotta go through all this to catch the nulls.
78			try	{
79				if ( arguments.timeout neq 0 and variables.inited)	{
80					ret = variables._futureTask.Get(arguments.timeout, getTimeUnitType(arguments.timeoutUnit));
81				} else if (variables.inited ) {
82					ret = variables._futureTask.Get();
83				}
84				// additional processing might be required.
85				if (not isdefined("ret"))	{
86					ret = "";
87				} else {
88					ret = deserialize(ret);
89				}
90			} catch(Any e)	{
91				ret = "";
92				cancel();
93			}
94		</cfscript>
95		<cfreturn ret/>
96	</cffunction> 
97
98</cfcomponent>