SharedCollection.st
author Claus Gittinger <cg@exept.de>
Wed, 09 Aug 2017 14:12:50 +0200
changeset 4499 d163f325074d
parent 4355 9d6595f00a6e
child 4709 b26d6c21d910
permissions -rw-r--r--
#REFACTORING by cg class: SharedCollection changed: #initializeFor:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2006 by eXept Software AG
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
3860
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
    14
"{ NameSpace: Smalltalk }"
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
    15
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Collection subclass:#SharedCollection
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:'accessLock realCollection'
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
    20
	category:'Collections-Support'
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!SharedCollection class methodsFor:'documentation'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 2006 by eXept Software AG
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    Instances of this class provide synchronized access (of multiple processes) 
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    to a collection.
1636
a3e5703901c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
    43
4148
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    44
    Notice: 
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    45
        the message-forwarding is done by catching subclassResponsibility and
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    46
        doesNotUnderstand errors.
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    47
1636
a3e5703901c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
    48
    For performance, and for more complex operation-atomicy, more messages might need
4148
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    49
    an explicit handling. 
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    50
    See the implementation of #at: / #at:put: and #size for examples.
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    51
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    52
    [auhor:]
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    53
        Claus Gittinger
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    54
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    55
    [see also:]
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    56
        Semaphore RecursionLock
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    57
        SharedQueue
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    58
        #synchronized: method in Object.
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
examples
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
                                        [exBegin]
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
        |c|
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
        c := SharedCollection for:(OrderedCollection new).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
        c add:1.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
        c add:2.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
        c add:3.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
        c addAll:#(4 5 6).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
        c removeFirst.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
        c removeLast.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
        c inspect.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
                                        [exEnd]
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
                                        [exBegin]
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
        |c|
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
        c := SharedCollection for:(Array new:10).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
        c at:1 put:5.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
        c replaceFrom:2 to:5 with:#(20 30 40 50).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
        c inspect.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
                                        [exEnd]
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
! !
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
!SharedCollection class methodsFor:'instance creation'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
for:aCollection
4336
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    91
    "create and return a new shareCollection which protects
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    92
     access to aCollection.
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    93
     I.e. to return a threadSave accessor on it."
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    94
     
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    ^ self new initializeFor:aCollection
4336
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    96
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    97
    "Modified (comment): / 18-02-2017 / 10:49:03 / cg"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
! !
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
1634
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   100
!SharedCollection methodsFor:'converting'!
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   101
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   102
asSharedCollection
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   103
    ^ self.
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   104
! !
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   105
3212
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   106
!SharedCollection methodsFor:'copying'!
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   107
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   108
shallowCopy
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   109
    "analog to species - copy the real collection"
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   110
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   111
    ^ accessLock critical:[
3213
53857e1b18a4 class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3212
diff changeset
   112
        "get a consistent copy"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   113
        realCollection shallowCopy
3213
53857e1b18a4 class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3212
diff changeset
   114
    ].
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   115
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   116
    "Modified: / 02-02-2017 / 17:03:55 / stefan"
3212
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   117
! !
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   118
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
!SharedCollection methodsFor:'initialization'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
initializeFor:aCollection
4499
d163f325074d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4355
diff changeset
   122
    accessLock := RecursionLock name:'SharedCollection'.
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    realCollection := aCollection.
4355
9d6595f00a6e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4336
diff changeset
   124
9d6595f00a6e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4336
diff changeset
   125
    "Modified: / 23-02-2017 / 12:41:45 / stefan"
4499
d163f325074d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4355
diff changeset
   126
    "Modified: / 09-08-2017 / 11:59:29 / cg"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
! !
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
!SharedCollection methodsFor:'message forwarding'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
1929
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   131
add:anElement
2927
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   132
    "add the argument, anObject to the receiver.
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   133
     Return the added element."
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   134
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   135
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   136
        realCollection add:anElement
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   137
    ].
1929
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   138
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   139
    "Modified: / 02-02-2017 / 17:01:08 / stefan"
1929
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   140
!
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   141
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
at:index
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   143
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   144
        realCollection at:index
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   145
    ].
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   147
    "Modified: / 02-02-2017 / 17:01:23 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
at:index put:value
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   151
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   152
        realCollection at:index put:value
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   153
    ].
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   155
    "Modified: / 02-02-2017 / 17:01:35 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   158
do:aBlock
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   159
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   160
        realCollection do:aBlock
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   161
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   162
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   163
    "Created: / 22-11-2010 / 21:01:21 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   164
    "Modified: / 02-02-2017 / 17:02:00 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   165
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   166
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
doesNotUnderstand:aMessage
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
    "catches everything not understood by the collection protocol"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   170
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   171
        aMessage sendTo:realCollection
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
    ].
1794
603885d999ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1637
diff changeset
   173
603885d999ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1637
diff changeset
   174
    "Modified: / 07-12-2006 / 17:38:30 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   175
    "Modified: / 02-02-2017 / 17:02:18 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   178
isEmpty
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   179
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   180
        realCollection isEmpty
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   181
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   182
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   183
    "Created: / 22-11-2010 / 20:59:01 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   184
    "Modified: / 02-02-2017 / 11:40:56 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   185
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   186
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   187
notEmpty
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   188
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   189
        realCollection notEmpty
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   190
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   191
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   192
    "Created: / 22-11-2010 / 20:59:06 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   193
    "Modified: / 02-02-2017 / 17:00:36 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   194
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   195
4286
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   196
remove:someElement ifAbsent:aBlock
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   197
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   198
        realCollection remove:someElement ifAbsent:aBlock
4286
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   199
    ].
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   200
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   201
    "Created: / 25-01-2017 / 22:57:32 / stefan"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   202
    "Modified: / 02-02-2017 / 17:00:54 / stefan"
4286
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   203
!
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   204
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   205
removeAllSuchThat:aBlock
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   206
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   207
        realCollection removeAllSuchThat:aBlock
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   208
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   209
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   210
    "Created: / 22-11-2010 / 20:59:27 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   211
    "Modified: / 02-02-2017 / 17:02:38 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   212
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   213
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   214
removeIdentical:someElement ifAbsent:aBlock
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   215
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   216
       realCollection removeIdentical:someElement ifAbsent:aBlock
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   217
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   218
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   219
    "Created: / 22-11-2010 / 21:00:33 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   220
    "Modified: / 02-02-2017 / 17:02:52 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   221
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   222
1635
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   223
size
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   224
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   225
        realCollection size
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   226
    ].
1635
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   227
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   228
    "Modified: / 02-02-2017 / 17:03:06 / stefan"
1635
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   229
!
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   230
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
subclassResponsibility
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    "catches every required message of the collection protocol"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   234
    |msg|
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
    msg := thisContext sender message.
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   237
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   238
        msg sendTo:realCollection
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    ].
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   240
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   241
    "Modified: / 02-02-2017 / 17:03:25 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
! !
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
3212
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   244
!SharedCollection methodsFor:'queries'!
1637
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   245
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   246
species
3860
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
   247
    "returns non shared collection's species"
1637
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   248
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   249
    ^ realCollection species
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   250
! !
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   251
3013
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   252
!SharedCollection methodsFor:'testing'!
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   253
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   254
isFixedSize
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   255
    "return true if the receiver cannot grow"
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   256
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   257
    ^ realCollection isFixedSize
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   258
! !
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   259
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
!SharedCollection class methodsFor:'documentation'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
version
3860
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
   263
    ^ '$Header$'
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   264
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   265
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   266
version_CVS
3860
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
   267
    ^ '$Header$'
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
! !
2927
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   269