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