-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebsideEvaluation.cls
237 lines (176 loc) · 5.32 KB
/
WebsideEvaluation.cls
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
"Filed out from Dolphin Smalltalk 7"!
Object subclass: #WebsideEvaluation
instanceVariableNames: 'id expression receiver context requestor priority process state result error'
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''!
WebsideEvaluation guid: (GUID fromString: '{b4a27f67-df46-4a72-a342-cea2fbac33b9}')!
WebsideEvaluation comment: ''!
!WebsideEvaluation categoriesForClass!Webside-Base! !
!WebsideEvaluation methodsFor!
asWebsideJson
| json |
json := super asWebsideJson.
json
at: 'id' put: id asString;
at: 'expression' put: expression;
at: 'state' put: state.
error ifNotNil: [json at: 'error' put: error asWebsideJson].
^json!
cancel process ifNotNil: [process terminate]. self cancelled!
cancelled
state := #cancelled.
self
trigger: #cancelled;
trigger: #finalized!
context ^context!
context: anObject context := anObject!
error ^ error!
evaluate
self evaluateBlock: [result := Compiler evaluate: expression for: receiver]!
evaluateBlock: aBlock
process :=
[state := #evaluating.
aBlock on: Exception
do:
[:exception |
error := exception.
self failed.
process suspend].
self finished]
newProcess.
"priority should be already set. In fact, it is initiallized as Processor userSchedulingPriority.
However, for some reason that should be understood/modified, HttpServer loop is scheduled at a lower priority,
making the resuming of the evaluation process to take control immediately when #resume is sent below, making synchronous
what otherwise would be asynchronous evaluation."
process
priority: Processor activeProcess priority - 1;
name: 'Webside evaluation ' , id asString;
resume!
expression ^expression!
expression: aString expression := aString!
failed
state := #failed.
self
trigger: #failed;
trigger: #finalized!
finished
state := #finished.
self
trigger: #finished;
trigger: #finalized!
hasFailed ^ state == #failed!
hasFinished ^ state == #finished!
id ^id!
id: uuid id := uuid!
initialize
super initialize.
id := IID newUnique.
state := #pending.
priority := Processor userSchedulingPriority!
isEvaluating ^ state == #evaluating!
isFinalized ^ self hasFinished or: [ self hasFailed or: [ self wasCancelled ] ]!
isPaused ^ state == #paused!
isPending ^ state == #pending!
pause process suspend. self paused!
paused state := #paused. self trigger: #paused!
priority: anInteger priority := anInteger!
process ^process!
process: aProcess process := aProcess!
receiver ^ receiver!
receiver: anObject receiver := anObject!
requestor ^ requestor!
requestor: anObject requestor := anObject!
result
self hasFinished ifTrue: [^result]!
result: anObject result := anObject!
resume self resumed. process resume.!
resumed
state := #evaluating.
self trigger: #resumed!
state
^state!
waitForResult
| semaphore |
self isFinalized
ifFalse:
[semaphore := Semaphore new.
self
when: #finalized
send: #signal
to: semaphore.
semaphore wait].
^self result!
wasCancelled ^ state == #cancelled! !
!WebsideEvaluation categoriesFor: #asWebsideJson!public! !
!WebsideEvaluation categoriesFor: #cancel!public! !
!WebsideEvaluation categoriesFor: #cancelled!public! !
!WebsideEvaluation categoriesFor: #context!public! !
!WebsideEvaluation categoriesFor: #context:!public! !
!WebsideEvaluation categoriesFor: #error!public! !
!WebsideEvaluation categoriesFor: #evaluate!public! !
!WebsideEvaluation categoriesFor: #evaluateBlock:!public! !
!WebsideEvaluation categoriesFor: #expression!public! !
!WebsideEvaluation categoriesFor: #expression:!public! !
!WebsideEvaluation categoriesFor: #failed!public! !
!WebsideEvaluation categoriesFor: #finished!public! !
!WebsideEvaluation categoriesFor: #hasFailed!public! !
!WebsideEvaluation categoriesFor: #hasFinished!public! !
!WebsideEvaluation categoriesFor: #id!public! !
!WebsideEvaluation categoriesFor: #id:!public! !
!WebsideEvaluation categoriesFor: #initialize!private! !
!WebsideEvaluation categoriesFor: #isEvaluating!public! !
!WebsideEvaluation categoriesFor: #isFinalized!public! !
!WebsideEvaluation categoriesFor: #isPaused!public! !
!WebsideEvaluation categoriesFor: #isPending!public! !
!WebsideEvaluation categoriesFor: #pause!public! !
!WebsideEvaluation categoriesFor: #paused!public! !
!WebsideEvaluation categoriesFor: #priority:!public! !
!WebsideEvaluation categoriesFor: #process!public! !
!WebsideEvaluation categoriesFor: #process:!public! !
!WebsideEvaluation categoriesFor: #receiver!public! !
!WebsideEvaluation categoriesFor: #receiver:!public! !
!WebsideEvaluation categoriesFor: #requestor!public! !
!WebsideEvaluation categoriesFor: #requestor:!public! !
!WebsideEvaluation categoriesFor: #result!public! !
!WebsideEvaluation categoriesFor: #result:!public! !
!WebsideEvaluation categoriesFor: #resume!public! !
!WebsideEvaluation categoriesFor: #resumed!public! !
!WebsideEvaluation categoriesFor: #state!public! !
!WebsideEvaluation categoriesFor: #waitForResult!public! !
!WebsideEvaluation categoriesFor: #wasCancelled!public! !
!WebsideEvaluation class methodsFor!
new
^super new initialize! !
!WebsideEvaluation class categoriesFor: #new!public! !