|
1 " |
|
2 COPYRIGHT (c) 2006 by eXept Software AG |
|
3 All Rights Reserved |
|
4 |
|
5 This software is furnished under a license and may be used |
|
6 only in accordance with the terms of that license and with the |
|
7 inclusion of the above copyright notice. This software may not |
|
8 be provided or otherwise made available to, or used by, any |
|
9 other person. No title to or ownership of the software is |
|
10 hereby transferred. |
|
11 " |
|
12 "{ Package: 'stx:libtool' }" |
|
13 |
|
14 "{ NameSpace: Tools }" |
|
15 |
|
16 BackgroundJob subclass:#BackgroundQueueProcessingJob |
|
17 instanceVariableNames:'queue queueAccessLock' |
|
18 classVariableNames:'' |
|
19 poolDictionaries:'' |
|
20 category:'Interface-CodeView' |
|
21 ! |
|
22 |
|
23 !BackgroundQueueProcessingJob class methodsFor:'documentation'! |
|
24 |
|
25 copyright |
|
26 " |
|
27 COPYRIGHT (c) 2006 by eXept Software AG |
|
28 All Rights Reserved |
|
29 |
|
30 This software is furnished under a license and may be used |
|
31 only in accordance with the terms of that license and with the |
|
32 inclusion of the above copyright notice. This software may not |
|
33 be provided or otherwise made available to, or used by, any |
|
34 other person. No title to or ownership of the software is |
|
35 hereby transferred. |
|
36 " |
|
37 ! ! |
|
38 |
|
39 !BackgroundQueueProcessingJob class methodsFor:'instance creation'! |
|
40 |
|
41 new |
|
42 "return an initialized instance" |
|
43 |
|
44 ^ self basicNew initialize. |
|
45 ! ! |
|
46 |
|
47 !BackgroundQueueProcessingJob methodsFor:'adding & removing'! |
|
48 |
|
49 add: object |
|
50 |
|
51 "includes: is not synchronized, but should not harm" |
|
52 |
|
53 queueAccessLock critical:[ |
|
54 (queue includes: object) |
|
55 ifFalse:[queue add: object]. |
|
56 self start]. |
|
57 |
|
58 "Created: / 28-04-2011 / 20:40:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
59 "Modified: / 18-05-2011 / 23:30:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
60 ! ! |
|
61 |
|
62 !BackgroundQueueProcessingJob methodsFor:'initialization'! |
|
63 |
|
64 initialize |
|
65 "Invoked when a new instance is created." |
|
66 |
|
67 |
|
68 queue := OrderedCollection new. |
|
69 queueAccessLock := RecursionLock new. |
|
70 |
|
71 "Modified: / 18-05-2011 / 23:25:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
72 ! ! |
|
73 |
|
74 !BackgroundQueueProcessingJob methodsFor:'processing'! |
|
75 |
|
76 process |
|
77 |
|
78 | item | |
|
79 |
|
80 [ |
|
81 item := nil. |
|
82 queueAccessLock critical: |
|
83 [queue isEmpty ifFalse:[item := queue removeFirst]]. |
|
84 item isNil ifFalse: |
|
85 [self processItem: item]. |
|
86 item notNil. |
|
87 ] whileTrue |
|
88 |
|
89 "Created: / 28-04-2011 / 20:36:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
90 "Modified: / 18-05-2011 / 23:30:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
91 ! |
|
92 |
|
93 processItem: item |
|
94 |
|
95 ^job value: item |
|
96 |
|
97 "Created: / 28-04-2011 / 20:36:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
98 ! ! |
|
99 |
|
100 !BackgroundQueueProcessingJob class methodsFor:'documentation'! |
|
101 |
|
102 version_CVS |
|
103 ^ '$Header: /cvs/stx/stx/libbasic2/BackgroundQueueProcessingJob.st,v 1.1 2011-07-01 13:21:58 cg Exp $' |
|
104 ! |
|
105 |
|
106 version_SVN |
|
107 ^ '§Id§' |
|
108 ! ! |