author | Stefan Vogel <sv@exept.de> |
Fri, 05 Aug 2011 22:03:09 +0200 | |
changeset 2611 | 9087baddf7d0 |
parent 2602 | 44d00fea6ee0 |
child 2674 | 88904093a5aa |
permissions | -rw-r--r-- |
2574 | 1 |
" |
2576 | 2 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
2587 | 3 |
All Rights Reserved |
2574 | 4 |
|
2576 | 5 |
Permission is hereby granted, free of charge, to any person |
6 |
obtaining a copy of this software and associated documentation |
|
7 |
files (the 'Software'), to deal in the Software without |
|
8 |
restriction, including without limitation the rights to use, |
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10 |
copies of the Software, and to permit persons to whom the |
|
11 |
Software is furnished to do so, subject to the following |
|
12 |
conditions: |
|
13 |
||
14 |
The above copyright notice and this permission notice shall be |
|
15 |
included in all copies or substantial portions of the Software. |
|
16 |
||
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
24 |
OTHER DEALINGS IN THE SOFTWARE. |
|
2574 | 25 |
" |
2587 | 26 |
"{ Package: 'stx:libbasic2' }" |
2574 | 27 |
|
28 |
Object subclass:#BackgroundJob |
|
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
29 |
instanceVariableNames:'name job priority thread running' |
2574 | 30 |
classVariableNames:'' |
31 |
poolDictionaries:'' |
|
2590 | 32 |
category:'System-Support' |
2574 | 33 |
! |
34 |
||
35 |
!BackgroundJob class methodsFor:'documentation'! |
|
36 |
||
37 |
copyright |
|
38 |
" |
|
2576 | 39 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
2587 | 40 |
All Rights Reserved |
2574 | 41 |
|
2576 | 42 |
Permission is hereby granted, free of charge, to any person |
43 |
obtaining a copy of this software and associated documentation |
|
44 |
files (the 'Software'), to deal in the Software without |
|
45 |
restriction, including without limitation the rights to use, |
|
46 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
47 |
copies of the Software, and to permit persons to whom the |
|
48 |
Software is furnished to do so, subject to the following |
|
49 |
conditions: |
|
50 |
||
51 |
The above copyright notice and this permission notice shall be |
|
52 |
included in all copies or substantial portions of the Software. |
|
53 |
||
54 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
55 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
56 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
57 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
58 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
59 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
60 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
61 |
OTHER DEALINGS IN THE SOFTWARE. |
|
2574 | 62 |
" |
2590 | 63 |
! |
64 |
||
65 |
documentation |
|
66 |
" |
|
2602
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
67 |
A BackgroundJob is a helper class for any kind of background |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
68 |
processing. Possible uses include (but not limited to): |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
69 |
copying files, syntax higlighting, live searching, autosave, etc. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
70 |
|
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
71 |
A task to be processed in a background is given to instances |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
72 |
in a form of a block or a message send. The background task must |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
73 |
be then started by sending a #start message to the instance of |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
74 |
the job. A job may be restarted any time by sending #restart or |
2611 | 75 |
terminated by sending #stop. Sending #start to already started |
2602
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
76 |
job does nothing. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
77 |
|
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
78 |
Implementation note: |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
79 |
The the task is actually processed in a separate, exclusive |
2611 | 80 |
worker thread, so an explicit synchronization have to |
2602
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
81 |
be done iff the task accesses possibly shared data. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
82 |
The worker exists only iff the job is actually running. When |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
83 |
the task is finished, worker thread terminates. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
84 |
|
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
85 |
[author:] |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
86 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
87 |
|
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
88 |
[instance variables:] |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
89 |
name <String|nil> A user friendly name of a job, |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
90 |
useful for identifing job's thread in |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
91 |
process list. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
92 |
job <Block|MessageSend> A task to perform in background. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
93 |
priority<Integer> A priority of worker thread. Defaults to |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
94 |
Processor userBackgroundPriority. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
95 |
thread <Process|nil> The worker thread |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
96 |
running <Boolean> Boolean value indicating whether |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
97 |
tasks already started or not. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
98 |
|
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
99 |
[see also:] |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
100 |
BackgroundQueueProcessingJob |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
101 |
Tools::CodeHighlightingService (uses this class) |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
102 |
|
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
103 |
|
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
104 |
|
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
105 |
" |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
106 |
! |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
107 |
|
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
108 |
examples |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
109 |
" |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
110 |
| job text | |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
111 |
job := BackgroundJob named: 'example job' on:[ |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
112 |
Delay waitForSeconds: 3. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
113 |
Transcript showCR:'One guy said: ', text |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
114 |
]. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
115 |
text := 'Hello world'. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
116 |
job restart. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
117 |
Delay waitForSeconds: 5. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
118 |
text := 'Ahoj Svete!!'. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
119 |
job restart. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
120 |
Delay waitForSeconds: 1. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
121 |
text := 'Haya, I''m talking fast, you should not see the czech greeting'. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
122 |
job restart. |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
123 |
|
2590 | 124 |
" |
2574 | 125 |
! ! |
126 |
||
127 |
!BackgroundJob class methodsFor:'instance creation'! |
|
128 |
||
129 |
named: name |
|
130 |
||
131 |
^self new name: name |
|
132 |
||
133 |
"Created: / 28-04-2011 / 20:26:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
134 |
! |
|
135 |
||
136 |
named: name on: block |
|
137 |
||
138 |
^self new name: name; job: block |
|
139 |
||
140 |
"Created: / 28-04-2011 / 20:27:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
141 |
! |
|
142 |
||
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
143 |
new |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
144 |
"return an initialized instance" |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
145 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
146 |
^ self basicNew initialize. |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
147 |
! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
148 |
|
2574 | 149 |
on: block |
150 |
||
151 |
^self new job: block |
|
152 |
||
153 |
"Created: / 28-04-2011 / 20:30:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
154 |
! ! |
|
155 |
||
156 |
!BackgroundJob methodsFor:'accessing'! |
|
157 |
||
158 |
job |
|
159 |
^ job |
|
160 |
! |
|
161 |
||
162 |
job:aBlockOrMessageSend |
|
2602
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
163 |
|
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
164 |
"Sets the job to be done. The job is sent |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
165 |
#value from the worker thread once started" |
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
166 |
|
2574 | 167 |
job := aBlockOrMessageSend. |
2602
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
168 |
|
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
169 |
"Modified (comment): / 03-08-2011 / 21:02:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2574 | 170 |
! |
171 |
||
172 |
name |
|
173 |
^ name ? '<unnamed background job>' |
|
174 |
||
175 |
"Modified: / 28-04-2011 / 20:29:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
176 |
! |
|
177 |
||
178 |
name:aString |
|
179 |
name := aString. |
|
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
180 |
! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
181 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
182 |
priority |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
183 |
^ priority |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
184 |
! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
185 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
186 |
priority:anInteger |
2602
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
187 |
"Set the priority of a worker thread" |
2587 | 188 |
|
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
189 |
priority := anInteger. |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
190 |
|
2588 | 191 |
"Modified (format): / 03-08-2011 / 16:42:45 / cg" |
2602
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
192 |
"Modified (comment): / 03-08-2011 / 21:01:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
193 |
! ! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
194 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
195 |
!BackgroundJob methodsFor:'initialization'! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
196 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
197 |
initialize |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
198 |
priority := Processor userBackgroundPriority. |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
199 |
running := false. |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
200 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
201 |
"/ super initialize. -- commented since inherited method does nothing |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
202 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
203 |
"Modified: / 29-07-2011 / 10:52:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2588 | 204 |
"Modified (format): / 03-08-2011 / 16:42:51 / cg" |
2574 | 205 |
! ! |
206 |
||
207 |
!BackgroundJob methodsFor:'processing'! |
|
208 |
||
209 |
process |
|
210 |
"Do the job. May be overriden by subclasses to |
|
211 |
do some more complex operations" |
|
212 |
||
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
213 |
running := true. |
2574 | 214 |
job value |
215 |
||
216 |
"Created: / 28-04-2011 / 20:23:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2588 | 217 |
"Modified (format): / 03-08-2011 / 16:42:42 / cg" |
2574 | 218 |
! ! |
219 |
||
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
220 |
!BackgroundJob methodsFor:'queries'! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
221 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
222 |
running |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
223 |
"Return true if the job is actually running, i.e., if it |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
224 |
is actually computing a value, contrary to #scheduled, that |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
225 |
returns true even if computation actually did not start |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
226 |
(i.e., thread is created but was not scheduled so far)" |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
227 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
228 |
^running |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
229 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
230 |
"Created: / 29-07-2011 / 10:23:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2588 | 231 |
"Modified (format): / 03-08-2011 / 16:42:35 / cg" |
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
232 |
! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
233 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
234 |
scheduled |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
235 |
"Return true, if the job has been already started" |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
236 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
237 |
^thread notNil |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
238 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
239 |
"Created: / 29-07-2011 / 10:47:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2588 | 240 |
"Modified (format): / 03-08-2011 / 16:42:32 / cg" |
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
241 |
! ! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
242 |
|
2574 | 243 |
!BackgroundJob methodsFor:'start & stop'! |
244 |
||
245 |
restart |
|
2602
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
246 |
|
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
247 |
running ifTrue:[ |
2588 | 248 |
self stop. |
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
249 |
]. |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
250 |
self start |
2574 | 251 |
|
252 |
"Created: / 28-04-2011 / 20:31:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2588 | 253 |
"Modified (format): / 03-08-2011 / 16:42:39 / cg" |
2602
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
254 |
"Modified (comment): / 03-08-2011 / 21:03:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2574 | 255 |
! |
256 |
||
257 |
start |
|
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
258 |
self startWithPriority: priority |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
259 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
260 |
"Created: / 28-04-2011 / 20:23:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2590 | 261 |
"Modified (format): / 03-08-2011 / 16:44:36 / cg" |
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
262 |
! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
263 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
264 |
startWithPriority: prio |
2588 | 265 |
| t | |
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
266 |
|
2588 | 267 |
((t := thread) isNil or:[t isDead]) ifTrue:[ |
268 |
thread := [ |
|
269 |
[ |
|
270 |
self process |
|
271 |
] ensure: [ |
|
272 |
running := false. |
|
273 |
thread := nil |
|
274 |
] |
|
275 |
] newProcess. |
|
276 |
thread priority: prio. |
|
277 |
thread name: name. |
|
278 |
thread resume. |
|
2574 | 279 |
] |
280 |
||
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
281 |
"Created: / 29-07-2011 / 11:04:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2588 | 282 |
"Modified (format): / 03-08-2011 / 16:42:19 / cg" |
2574 | 283 |
! |
284 |
||
285 |
stop |
|
286 |
| t | |
|
287 |
||
288 |
(t := thread) ifNil:[^self]. |
|
289 |
thread := nil. |
|
290 |
t terminate. |
|
291 |
"/ raise its prio to make it terminate quickly |
|
292 |
t priority:(Processor userSchedulingPriority + 1) |
|
293 |
||
294 |
"Created: / 28-04-2011 / 20:31:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2588 | 295 |
"Modified (format): / 03-08-2011 / 16:41:53 / cg" |
2574 | 296 |
! ! |
297 |
||
298 |
!BackgroundJob class methodsFor:'documentation'! |
|
299 |
||
2590 | 300 |
version |
2611 | 301 |
^ '$Header: /cvs/stx/stx/libbasic2/BackgroundJob.st,v 1.8 2011-08-05 20:03:09 stefan Exp $' |
2590 | 302 |
! |
303 |
||
2574 | 304 |
version_CVS |
2611 | 305 |
^ '$Header: /cvs/stx/stx/libbasic2/BackgroundJob.st,v 1.8 2011-08-05 20:03:09 stefan Exp $' |
2574 | 306 |
! |
307 |
||
308 |
version_SVN |
|
309 |
^ '§Id§' |
|
310 |
! ! |