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