BackgroundQueueProcessingJob.st
author Claus Gittinger <cg@exept.de>
Sun, 03 Jul 2011 19:50:13 +0200
changeset 2575 b86b3329f23c
parent 2573 7c39e920ef05
child 2584 a6cbe910605d
permissions -rw-r--r--
changed: #copyright
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
2575
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
     2
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
2575
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
     5
Permission is hereby granted, free of charge, to any person
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
     6
obtaining a copy of this software and associated documentation
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
     7
files (the 'Software'), to deal in the Software without
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
     8
restriction, including without limitation the rights to use,
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
     9
copy, modify, merge, publish, distribute, sublicense, and/or sell
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    10
copies of the Software, and to permit persons to whom the
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    11
Software is furnished to do so, subject to the following
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    12
conditions:
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    13
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    14
The above copyright notice and this permission notice shall be
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    15
included in all copies or substantial portions of the Software.
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    16
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    17
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    18
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    19
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    20
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    21
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    22
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    23
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    24
OTHER DEALINGS IN THE SOFTWARE.
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"{ Package: 'stx:libtool' }"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"{ NameSpace: Tools }"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
BackgroundJob subclass:#BackgroundQueueProcessingJob
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
	instanceVariableNames:'queue queueAccessLock'
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
	classVariableNames:''
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
	poolDictionaries:''
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
	category:'Interface-CodeView'
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!BackgroundQueueProcessingJob class methodsFor:'documentation'!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
copyright
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
2575
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    41
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
              All Rights Reserved
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
2575
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    44
Permission is hereby granted, free of charge, to any person
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    45
obtaining a copy of this software and associated documentation
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    46
files (the 'Software'), to deal in the Software without
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    47
restriction, including without limitation the rights to use,
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    48
copy, modify, merge, publish, distribute, sublicense, and/or sell
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    49
copies of the Software, and to permit persons to whom the
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    50
Software is furnished to do so, subject to the following
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    51
conditions:
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    52
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    53
The above copyright notice and this permission notice shall be
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    54
included in all copies or substantial portions of the Software.
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    55
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    56
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    57
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    58
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    59
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    60
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    61
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    62
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
    63
OTHER DEALINGS IN THE SOFTWARE.
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
! !
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
!BackgroundQueueProcessingJob class methodsFor:'instance creation'!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
new
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    "return an initialized instance"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    ^ self basicNew initialize.
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
! !
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
!BackgroundQueueProcessingJob methodsFor:'adding & removing'!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
add: object
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    "includes: is not synchronized, but should not harm"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    queueAccessLock critical:[
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
        (queue includes: object)
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
            ifFalse:[queue add: object].
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
        self start].
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    "Created: / 28-04-2011 / 20:40:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    "Modified: / 18-05-2011 / 23:30:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
! !
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
!BackgroundQueueProcessingJob methodsFor:'initialization'!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
initialize
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    "Invoked when a new instance is created."
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    queue := OrderedCollection new.
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
    queueAccessLock := RecursionLock new.
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    "Modified: / 18-05-2011 / 23:25:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
! !
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
!BackgroundQueueProcessingJob methodsFor:'processing'!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
process
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    | item |
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
    [
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
	item := nil.	 
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
        queueAccessLock critical:
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
            [queue isEmpty ifFalse:[item := queue removeFirst]].        
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
	item isNil ifFalse:
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
	    [self processItem: item].
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
	item notNil.
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    ] whileTrue
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    "Created: / 28-04-2011 / 20:36:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
    "Modified: / 18-05-2011 / 23:30:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
processItem: item
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    ^job value: item
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    "Created: / 28-04-2011 / 20:36:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
! !
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
!BackgroundQueueProcessingJob class methodsFor:'documentation'!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
version_CVS
2575
b86b3329f23c changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 2573
diff changeset
   131
    ^ '$Header: /cvs/stx/stx/libbasic2/BackgroundQueueProcessingJob.st,v 1.2 2011-07-03 17:50:13 cg Exp $'
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
version_SVN
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    ^ '§Id§'
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
! !