-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgateway.cfc
93 lines (71 loc) · 1.65 KB
/
gateway.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
component {
variables.state = 'stopped';
public void function init(
string id,
struct config
) {
local.e = '';
try {
variables.id = arguments.id;
variables.config = arguments.config;
_log('init');
} catch ( any e ) {
_handleError( e , 'init' );
}
}
public void function start() {
// Just giving it a little chance to stop if it's stopping
while ( variables.state == 'stopping' ) {
sleep( 10 );
}
_log( 'start' );
// Do whatever you like here, a good option here is an infinite loop until state !== 'running'
try {
variables.state = 'starting';
// You could perform some startup logic right here
variables.state = 'running';
while ( variables.state == 'running' ) {
// Do stuff here
// Do stuff here
// Do stuff here
// Do stuff here
// Do stuff here
// You probably want to sleep between iterations instead of killing your server
sleep( 100 );
}
} catch (e) {
variables.state = 'failed : ' & cfcatch.message;
_handleError( cfcatch , 'start' );
rethrow;
}
}
public void function stop() {
_log( 'stop' );
variables.state = 'stopping';
// Cleanup logic could come in to here
variables.state = 'stopped';
}
public void function restart() {
if (
variables.state == 'running'
) {
stop();
}
start();
}
public string function getState() {
return variables.state;
}
private void function _handleError(
struct catchData = {},
string functionName
) {
_log( 'error' );
}
private void function _log(
required string text,
string type = 'information'
) {
log text=arguments.text type=arguments.type file='event-gateway-skeleton';
}
}