SharedCollection.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5469 d78065ee4cff
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
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
"
5138
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
    43
    Instances of this class provide synchronized access (of multiple processes) to a collection.
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
    44
    Any message sent to instances are protected by an internal access lock, 
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
    45
    to prevent simultaneous access from different threads. 
1636
a3e5703901c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
    46
4148
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    47
    Notice: 
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    48
        the message-forwarding is done by catching subclassResponsibility and
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    49
        doesNotUnderstand errors.
5138
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
    50
        For performance, and for more complex operation-atomicy, 
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
    51
        more messages might need an explicit handling. 
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
    52
        See the implementation of #at: / #at:put: and #size for examples.
4148
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:]
5138
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
    58
        Semaphore RecursionLock SharedQueue
4148
0cdfbd3b63c0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4001
diff changeset
    59
        #synchronized: method in Object.
1632
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
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
examples
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
                                        [exBegin]
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
        |c|
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
        c := SharedCollection for:(OrderedCollection new).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
        c add:1.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
        c add:2.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
        c add:3.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
        c addAll:#(4 5 6).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
        c removeFirst.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
        c removeLast.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
        c inspect.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
                                        [exEnd]
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
                                        [exBegin]
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
        |c|
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
        c := SharedCollection for:(Array new:10).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
        c at:1 put:5.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
        c replaceFrom:2 to:5 with:#(20 30 40 50).
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
        c inspect.
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
                                        [exEnd]
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
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
!SharedCollection class methodsFor:'instance creation'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
for:aCollection
4336
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    92
    "create and return a new shareCollection which protects
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    93
     access to aCollection.
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    94
     I.e. to return a threadSave accessor on it."
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    95
     
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    ^ self new initializeFor:aCollection
4336
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    97
f330feaa0125 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
    98
    "Modified (comment): / 18-02-2017 / 10:49:03 / cg"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
! !
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
4710
6a37e4e17f25 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4709
diff changeset
   101
!SharedCollection methodsFor:'accessing'!
6a37e4e17f25 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4709
diff changeset
   102
4940
d5d7391bc875 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4710
diff changeset
   103
accessLock
5138
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   104
    "returns the internal lock (an instance of RecursionLock).
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   105
     For protocol compatibility with SharedQueue"
4940
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
5138
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   113
    "returns the internal lock (an instance of RecursionLock)"
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   114
4710
6a37e4e17f25 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4709
diff changeset
   115
    ^ accessLock
6a37e4e17f25 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4709
diff changeset
   116
! !
6a37e4e17f25 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4709
diff changeset
   117
1634
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   118
!SharedCollection methodsFor:'converting'!
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   119
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   120
asSharedCollection
5138
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   121
    "return a shared collection on the receiver.
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   122
     because the receiver is already synchronized, itself is returned."
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   123
1634
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   124
    ^ self.
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   125
! !
466927adcd9c +asSharedCollection
Claus Gittinger <cg@exept.de>
parents: 1632
diff changeset
   126
3212
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   127
!SharedCollection methodsFor:'copying'!
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   128
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   129
shallowCopy
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   130
    "analog to species - copy the real collection"
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   131
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   132
    ^ accessLock critical:[
3213
53857e1b18a4 class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3212
diff changeset
   133
        "get a consistent copy"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   134
        realCollection shallowCopy
3213
53857e1b18a4 class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3212
diff changeset
   135
    ].
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   136
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   137
    "Modified: / 02-02-2017 / 17:03:55 / stefan"
3212
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   138
! !
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   139
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
!SharedCollection methodsFor:'initialization'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
initializeFor:aCollection
5138
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   143
    "private; initializes the private access lock"
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   144
4499
d163f325074d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4355
diff changeset
   145
    accessLock := RecursionLock name:'SharedCollection'.
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    realCollection := aCollection.
4355
9d6595f00a6e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4336
diff changeset
   147
9d6595f00a6e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4336
diff changeset
   148
    "Modified: / 23-02-2017 / 12:41:45 / stefan"
4499
d163f325074d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4355
diff changeset
   149
    "Modified: / 09-08-2017 / 11:59:29 / cg"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
! !
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
!SharedCollection methodsFor:'message forwarding'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
1929
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   154
add:anElement
2927
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   155
    "add the argument, anObject to the receiver.
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   156
     Return the added element."
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   157
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   158
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   159
        realCollection add:anElement
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   160
    ].
1929
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   161
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   162
    "Modified: / 02-02-2017 / 17:01:08 / stefan"
1929
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   163
!
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   164
5469
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   165
addFirst:anElement
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   166
    "add the argument, anObject to the front of the receiver.
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   167
     Return the added element."
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   168
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   169
    ^ accessLock critical:[
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   170
        realCollection addFirst:anElement
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   171
    ].
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   172
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   173
    "Created: / 19-03-2020 / 18:28:50 / Stefan Vogel"
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   174
!
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   175
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   176
addLast:anElement
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   177
    "add the argument, anObject to the end of the receiver.
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   178
     Return the added element."
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   179
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   180
    ^ accessLock critical:[
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   181
        realCollection addLast:anElement
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   182
    ].
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   183
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   184
    "Created: / 19-03-2020 / 18:28:03 / Stefan Vogel"
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   185
!
d78065ee4cff #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
   186
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
at:index
5138
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   188
    "retrieve the element at index while locked"
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   189
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   190
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   191
        realCollection at:index
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   192
    ].
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   194
    "Modified: / 02-02-2017 / 17:01:23 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
at:index put:value
5138
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   198
    "update the element at index while locked"
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   199
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   200
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   201
        realCollection at:index put:value
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   202
    ].
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   204
    "Modified: / 02-02-2017 / 17:01:35 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   207
do:aBlock
5138
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   208
    "enumerate the elements while locked"
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   209
5143
de87f76d5d87 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
   210
    accessLock critical:[
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   211
        realCollection do:aBlock
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
    "Created: / 22-11-2010 / 21:01:21 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   215
    "Modified: / 02-02-2017 / 17:02:00 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   216
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   217
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
doesNotUnderstand:aMessage
5138
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   219
    "catches everything not understood by the collection protocol,
0793a0374d2a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
   220
     and forwards the message to the underlying collection while locked"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   222
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   223
        aMessage sendTo:realCollection
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    ].
1794
603885d999ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1637
diff changeset
   225
603885d999ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1637
diff changeset
   226
    "Modified: / 07-12-2006 / 17:38:30 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   227
    "Modified: / 02-02-2017 / 17:02:18 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   230
isEmpty
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   231
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   232
        realCollection isEmpty
2515
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
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   235
    "Created: / 22-11-2010 / 20:59:01 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   236
    "Modified: / 02-02-2017 / 11:40:56 / stefan"
2515
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
4941
148b29bdda05 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
   239
last
148b29bdda05 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
   240
    ^ accessLock critical:[
148b29bdda05 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
   241
        realCollection last
148b29bdda05 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
   242
    ].
148b29bdda05 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
   243
148b29bdda05 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
   244
    "Created: / 06-05-2019 / 18:51:26 / Claus Gittinger"
148b29bdda05 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
   245
!
148b29bdda05 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
   246
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   247
notEmpty
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 notEmpty
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   250
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   251
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   252
    "Created: / 22-11-2010 / 20:59:06 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   253
    "Modified: / 02-02-2017 / 17:00:36 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   254
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   255
4286
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   256
remove:someElement ifAbsent:aBlock
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   257
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   258
        realCollection remove:someElement ifAbsent:aBlock
4286
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   259
    ].
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   260
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   261
    "Created: / 25-01-2017 / 22:57:32 / stefan"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   262
    "Modified: / 02-02-2017 / 17:00:54 / stefan"
4286
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   263
!
7bd2d76a4f79 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
   264
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   265
removeAllSuchThat:aBlock
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   266
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   267
        realCollection removeAllSuchThat:aBlock
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   268
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   269
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   270
    "Created: / 22-11-2010 / 20:59:27 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   271
    "Modified: / 02-02-2017 / 17:02:38 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   272
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   273
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   274
removeIdentical:someElement ifAbsent:aBlock
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   275
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   276
       realCollection removeIdentical:someElement ifAbsent:aBlock
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   277
    ].
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   278
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   279
    "Created: / 22-11-2010 / 21:00:33 / cg"
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   280
    "Modified: / 02-02-2017 / 17:02:52 / stefan"
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   281
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   282
1635
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   283
size
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   284
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   285
        realCollection size
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   286
    ].
1635
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   287
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   288
    "Modified: / 02-02-2017 / 17:03:06 / stefan"
1635
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   289
!
a3aaefef0a2c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   290
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
subclassResponsibility
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
    "catches every required message of the collection protocol"
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   294
    |msg|
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
    msg := thisContext sender message.
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   297
    ^ accessLock critical:[
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   298
        msg sendTo:realCollection
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
    ].
4291
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   300
a67c299b4c60 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4286
diff changeset
   301
    "Modified: / 02-02-2017 / 17:03:25 / stefan"
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
! !
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
3212
5c1eba42b00f class: SharedCollection
Stefan Vogel <sv@exept.de>
parents: 3022
diff changeset
   304
!SharedCollection methodsFor:'queries'!
1637
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   305
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   306
species
3860
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
   307
    "returns non shared collection's species"
1637
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   308
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   309
    ^ realCollection species
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   310
! !
72a61c17925c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
   311
3013
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   312
!SharedCollection methodsFor:'testing'!
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   313
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   314
isFixedSize
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   315
    "return true if the receiver cannot grow"
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   316
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   317
    ^ realCollection isFixedSize
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   318
! !
28d92a912dfa added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   319
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
!SharedCollection class methodsFor:'documentation'!
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
version
3860
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
   323
    ^ '$Header$'
2515
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   324
!
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   325
104080163067 more operations without dnu-overhead
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   326
version_CVS
3860
224a3ad98604 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
   327
    ^ '$Header$'
1632
f0c09d48b17f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
! !
2927
b7b7931cb32d comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2515
diff changeset
   329