-
Notifications
You must be signed in to change notification settings - Fork 1
/
AbstractCompletionTask.cfc
executable file
·70 lines (56 loc) · 1.42 KB
/
AbstractCompletionTask.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Collects all completed futures and pushes them to a process() method. Implements the java.lang.Runnable interface
*/
component output="false" accessors="true"{
property name="executorCompletionService";
property name="loggingEnabled" type="boolean";
property name="lastError";
variables.loggingEnabled = false;
public function init( executorCompletionService ){
structAppend( variables, arguments );
return this;
}
public function process( array results ){
writeLog("OVERRIDE ME!");
}
public function run(){
var allResults = [];
var thisTask = javacast( "null", 0 );
try
{
thisTask = executorCompletionService.poll();
} catch( any e )
{
logError(e, "Error in Completion Task polling the queue");
}
while( NOT isNull( thisTask ) ){
try
{
var futureResult = thisTask.get();
arrayAppend( allResults, futureResult );
}
catch( any e )
{
logError(e, "Error in Completion Task polling the queue");
arrayAppend( allResults, e );
}
thisTask = executorCompletionService.poll();
}
try
{
if( NOT arrayIsEmpty(allResults) ){
process( allResults );
} else if( getLoggingEnabled() ) {
writeLog("Results were empty...");
}
}
catch( Any e )
{
logError(e, "Error in Completion Task process");
}
}
function logError( error, message ){
writeLog("#message# : #error.message#; #error.detail#");
lastError = error;
}
}