BackgroundQueueProcessingJob.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 07 Sep 2011 14:10:12 +0200
changeset 2637 41e0362d5631
parent 2612 922aa3063807
child 2696 689bb9231455
permissions -rw-r--r--
support for nil objects in job's queue
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
"
2601
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    63
!
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    64
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    65
documentation
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    66
"
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    67
    A BackgroundQueueProcessingJob is a specialized form
2612
922aa3063807 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 2601
diff changeset
    68
    of a BackgroundJob for background processing of a queue.
2601
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    69
    Each item in the queue (added by sending #add: item) 
2612
922aa3063807 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 2601
diff changeset
    70
    is processed (using the instance variable job).
2601
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    71
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    72
    Implementation notes:
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    73
    The thread is running only if there is at least one item
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    74
    to process. When the queue is empty, the thread teminates.
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    75
    It is started again when a new item is added to the queue.
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    76
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    77
    [author:]
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    78
        Jan Vrany <jan.vrany@fit.cvut.cz>
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    79
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    80
    [instance variables:]
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    81
        queue       <OrderedCollection>     the queue of items to be procesed
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    82
        queueAccessLock<RecursionLock>      a lock used to synchronize
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    83
                                            access to the queue
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    84
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    85
    [class variables:]
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    86
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    87
    [see also:]
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    88
        BackgroundJob
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    89
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    90
"
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    91
!
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    92
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    93
examples
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    94
"
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    95
    | job text |
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    96
    job :=  BackgroundQueueProcessingJob named: 'example job' on:[:text|
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    97
                Delay waitForSeconds: 3.
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    98
                Transcript showCR:'One guy said: ', text
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
    99
            ].
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
   100
    job add:'Hello world'. 
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
   101
    Delay waitForSeconds: 5.
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
   102
    job add:'Ahoj Svete!!'.
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
   103
    job restart.
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
   104
    Delay waitForSeconds: 1.
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
   105
    job add:'Haya, looks like proper queue, you should see all greetings'.
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
   106
55c6a3887ebf Added documentation and examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2591
diff changeset
   107
"
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
! !
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
!BackgroundQueueProcessingJob methodsFor:'adding & removing'!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
add: object
2637
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   113
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   114
    ^self add: object at: nil
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   115
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   116
    "Created: / 28-04-2011 / 20:40:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   117
    "Modified (format): / 03-08-2011 / 16:43:01 / cg"
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   118
    "Modified: / 07-09-2011 / 12:35:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   119
!
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   120
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   121
add: object at: index
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
    "includes: is not synchronized, but should not harm"
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
    queueAccessLock critical:[
2637
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   125
        (queue includes: object) ifFalse:[
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   126
            index notNil ifTrue:[
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   127
                queue add: object at: index
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   128
            ] ifFalse:[
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   129
                queue add: object
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   130
            ]
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   131
        ].
2589
Claus Gittinger <cg@exept.de>
parents: 2587
diff changeset
   132
        self start
Claus Gittinger <cg@exept.de>
parents: 2587
diff changeset
   133
    ].
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
2589
Claus Gittinger <cg@exept.de>
parents: 2587
diff changeset
   135
    "Modified (format): / 03-08-2011 / 16:43:01 / cg"
2637
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   136
    "Created: / 07-09-2011 / 12:34:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
! !
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
!BackgroundQueueProcessingJob methodsFor:'initialization'!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
initialize
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    "Invoked when a new instance is created."
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
2584
a6cbe910605d - CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2575
diff changeset
   144
    super initialize.
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    queue := OrderedCollection new.
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    queueAccessLock := RecursionLock new.
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
2584
a6cbe910605d - CodeHighlightingService refactored to use
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2575
diff changeset
   148
    "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
   149
! !
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
!BackgroundQueueProcessingJob methodsFor:'processing'!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
process
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
2637
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   155
    | cookie item |
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
2637
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   157
    cookie := 'cookie'.
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
    [
2637
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   159
        item := cookie.
2589
Claus Gittinger <cg@exept.de>
parents: 2587
diff changeset
   160
        queueAccessLock critical:[
Claus Gittinger <cg@exept.de>
parents: 2587
diff changeset
   161
            queue isEmpty ifFalse:[item := queue removeFirst]
Claus Gittinger <cg@exept.de>
parents: 2587
diff changeset
   162
        ].
2637
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   163
        item ~~ cookie ifTrue:[
2589
Claus Gittinger <cg@exept.de>
parents: 2587
diff changeset
   164
            self processItem: item
Claus Gittinger <cg@exept.de>
parents: 2587
diff changeset
   165
        ].
2637
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   166
        item ~~ cookie.
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
    ] whileTrue
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
    "Created: / 28-04-2011 / 20:36:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
2589
Claus Gittinger <cg@exept.de>
parents: 2587
diff changeset
   170
    "Modified (format): / 03-08-2011 / 16:43:21 / cg"
2637
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   171
    "Modified: / 07-09-2011 / 13:02:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
processItem: item
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
    ^job value: item
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
    "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
   179
! !
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
!BackgroundQueueProcessingJob class methodsFor:'documentation'!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
2591
Claus Gittinger <cg@exept.de>
parents: 2589
diff changeset
   183
version
2637
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   184
    ^ '$Header: /cvs/stx/stx/libbasic2/BackgroundQueueProcessingJob.st,v 1.9 2011-09-07 12:10:12 vrany Exp $'
2591
Claus Gittinger <cg@exept.de>
parents: 2589
diff changeset
   185
!
Claus Gittinger <cg@exept.de>
parents: 2589
diff changeset
   186
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
version_CVS
2637
41e0362d5631 support for nil objects in job's queue
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2612
diff changeset
   188
    ^ '$Header: /cvs/stx/stx/libbasic2/BackgroundQueueProcessingJob.st,v 1.9 2011-09-07 12:10:12 vrany Exp $'
2573
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
!
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
version_SVN
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
    ^ '§Id§'
7c39e920ef05 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
! !