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