author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 20 Jan 2012 18:26:27 +0100 | |
changeset 2706 | 99b71585e8d0 |
parent 2674 | 88904093a5aa |
child 2711 | 4e821abc0c2e |
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 |
||
2706
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
207 |
!BackgroundJob methodsFor:'private'! |
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
208 |
|
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
209 |
setupThread: t priority: p |
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
210 |
"Sets up worker thread" |
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
211 |
|
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
212 |
t priority: p. |
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
213 |
t name: name. |
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
214 |
|
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
215 |
"Created: / 20-01-2012 / 16:38:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
216 |
! ! |
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
217 |
|
2574 | 218 |
!BackgroundJob methodsFor:'processing'! |
219 |
||
220 |
process |
|
221 |
"Do the job. May be overriden by subclasses to |
|
222 |
do some more complex operations" |
|
223 |
||
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
224 |
running := true. |
2574 | 225 |
job value |
226 |
||
227 |
"Created: / 28-04-2011 / 20:23:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2588 | 228 |
"Modified (format): / 03-08-2011 / 16:42:42 / cg" |
2574 | 229 |
! ! |
230 |
||
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
231 |
!BackgroundJob methodsFor:'queries'! |
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 |
running |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
234 |
"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
|
235 |
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
|
236 |
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
|
237 |
(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
|
238 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
239 |
^running |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
240 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
241 |
"Created: / 29-07-2011 / 10:23:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2588 | 242 |
"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
|
243 |
! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
244 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
245 |
scheduled |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
246 |
"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
|
247 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
248 |
^thread notNil |
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 |
"Created: / 29-07-2011 / 10:47:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2588 | 251 |
"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
|
252 |
! ! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
253 |
|
2574 | 254 |
!BackgroundJob methodsFor:'start & stop'! |
255 |
||
256 |
restart |
|
2602
44d00fea6ee0
Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2590
diff
changeset
|
257 |
|
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
258 |
running ifTrue:[ |
2588 | 259 |
self stop. |
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
260 |
]. |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
261 |
self start |
2574 | 262 |
|
263 |
"Created: / 28-04-2011 / 20:31:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2588 | 264 |
"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
|
265 |
"Modified (comment): / 03-08-2011 / 21:03:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2574 | 266 |
! |
267 |
||
268 |
start |
|
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
269 |
self startWithPriority: priority |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
270 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
271 |
"Created: / 28-04-2011 / 20:23:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2590 | 272 |
"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
|
273 |
! |
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
274 |
|
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
275 |
startWithPriority: prio |
2588 | 276 |
| t | |
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
277 |
|
2588 | 278 |
((t := thread) isNil or:[t isDead]) ifTrue:[ |
279 |
thread := [ |
|
280 |
[ |
|
281 |
self process |
|
282 |
] ensure: [ |
|
283 |
running := false. |
|
284 |
thread := nil |
|
285 |
] |
|
286 |
] newProcess. |
|
2706
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
287 |
self setupThread: thread priority: prio. |
2588 | 288 |
thread resume. |
2574 | 289 |
] |
290 |
||
2585
af78d4b32e4d
- CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2576
diff
changeset
|
291 |
"Created: / 29-07-2011 / 11:04:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2588 | 292 |
"Modified (format): / 03-08-2011 / 16:42:19 / cg" |
2706
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
293 |
"Modified: / 20-01-2012 / 16:39:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2574 | 294 |
! |
295 |
||
296 |
stop |
|
297 |
| t | |
|
298 |
||
2674 | 299 |
(t := thread) isNil ifTrue:[^self]. |
2574 | 300 |
thread := nil. |
301 |
t terminate. |
|
302 |
"/ raise its prio to make it terminate quickly |
|
303 |
t priority:(Processor userSchedulingPriority + 1) |
|
304 |
||
305 |
"Created: / 28-04-2011 / 20:31:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2674 | 306 |
"Modified: / 18-11-2011 / 14:07:28 / cg" |
2574 | 307 |
! ! |
308 |
||
309 |
!BackgroundJob class methodsFor:'documentation'! |
|
310 |
||
2590 | 311 |
version |
2706
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
312 |
^ '$Header: /cvs/stx/stx/libbasic2/BackgroundJob.st,v 1.10 2012-01-20 17:26:27 vrany Exp $' |
2590 | 313 |
! |
314 |
||
2574 | 315 |
version_CVS |
2706
99b71585e8d0
Refactoring to allow custom thread setup in subclasses
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2674
diff
changeset
|
316 |
^ '$Header: /cvs/stx/stx/libbasic2/BackgroundJob.st,v 1.10 2012-01-20 17:26:27 vrany Exp $' |
2574 | 317 |
! |
318 |
||
319 |
version_SVN |
|
320 |
^ '§Id§' |
|
321 |
! ! |