initial checkin
authorClaus Gittinger <cg@exept.de>
Mon, 08 May 2006 15:09:23 +0200
changeset 1632 f0c09d48b17f
parent 1631 44795d9c92b1
child 1633 399bcaa1509c
initial checkin
SharedCollection.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SharedCollection.st	Mon May 08 15:09:23 2006 +0200
@@ -0,0 +1,132 @@
+"
+ COPYRIGHT (c) 2006 by eXept Software AG
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+"{ Package: 'stx:libbasic2' }"
+
+Collection subclass:#SharedCollection
+	instanceVariableNames:'accessLock realCollection'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Collections-Unordered'
+!
+
+!SharedCollection class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 2006 by eXept Software AG
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+!
+
+documentation
+"
+    Instances of this class provide synchronized access (of multiple processes) 
+    to a collection.
+"
+!
+
+examples
+"
+                                        [exBegin]
+        |c|
+
+        c := SharedCollection for:(OrderedCollection new).
+        c add:1.
+        c add:2.
+        c add:3.
+        c addAll:#(4 5 6).
+        c removeFirst.
+        c removeLast.
+        c inspect.
+                                        [exEnd]
+
+                                        [exBegin]
+        |c|
+
+        c := SharedCollection for:(Array new:10).
+        c at:1 put:5.
+        c replaceFrom:2 to:5 with:#(20 30 40 50).
+        c inspect.
+                                        [exEnd]
+"
+! !
+
+!SharedCollection class methodsFor:'instance creation'!
+
+for:aCollection
+    ^ self new initializeFor:aCollection
+! !
+
+!SharedCollection methodsFor:'initialization'!
+
+initializeFor:aCollection
+    accessLock := RecursionLock new.
+    realCollection := aCollection.
+! !
+
+!SharedCollection methodsFor:'message forwarding'!
+
+at:index
+    |rslt|
+
+    accessLock critical:[
+        rslt := realCollection at:index
+    ].
+    ^ rslt
+!
+
+at:index put:value
+    |rslt|
+
+    accessLock critical:[
+        rslt := realCollection at:index put:value
+    ].
+    ^ rslt
+!
+
+doesNotUnderstand:aMessage
+    "catches everything not understood by the collection protocol"
+
+    |msg rslt|
+
+    msg := thisContext sender message.
+    accessLock critical:[
+        rslt := aMessage sendTo:realCollection
+    ].
+    ^ rslt
+!
+
+subclassResponsibility
+    "catches every required message of the collection protocol"
+
+    |msg rslt|
+
+    msg := thisContext sender message.
+    accessLock critical:[
+        rslt := msg sendTo:realCollection
+    ].
+    ^ rslt
+! !
+
+!SharedCollection class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libbasic2/SharedCollection.st,v 1.1 2006-05-08 13:09:23 cg Exp $'
+! !