eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SharedCollection':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: SharedCollection


Inheritance:

   Object
   |
   +--Collection
      |
      +--SharedCollection

Package:
stx:libbasic2
Category:
Collections-Support
Version:
rev: 1.25 date: 2019/05/06 16:51:41
user: cg
file: SharedCollection.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


Instances of this class provide synchronized access (of multiple processes) 
to a collection.

Notice: 
    the message-forwarding is done by catching subclassResponsibility and
    doesNotUnderstand errors.

For performance, and for more complex operation-atomicy, more messages might need
an explicit handling. 
See the implementation of #at: / #at:put: and #size for examples.

[auhor:]
    Claus Gittinger


Related information:

    Semaphore
    RecursionLock
    SharedQueue
    [synchronized]
    method
    in
    Object.

Class protocol:

instance creation
o  for: aCollection
create and return a new shareCollection which protects
access to aCollection.
I.e. to return a threadSave accessor on it.


Instance protocol:

accessing
o  accessLock
for protocol compatibility with SharedQueue

o  synchronizationSemaphore

converting
o  asSharedCollection

copying
o  shallowCopy
analog to species - copy the real collection

initialization
o  initializeFor: aCollection

message forwarding
o  add: anElement
add the argument, anObject to the receiver.
Return the added element.

o  at: index
(comment from inherited method)
return the indexed instance variable with index, anInteger;
this method can be redefined in subclasses.

o  at: index put: value
(comment from inherited method)
store the 2nd arg, anObject as indexed instvar with index, anInteger.
this method can be redefined in subclasses. Returns anObject (sigh)

o  do: aBlock
(comment from inherited method)
evaluate the argument, aBlock for each element

o  doesNotUnderstand: aMessage
catches everything not understood by the collection protocol

o  isEmpty
(comment from inherited method)
return true, if the receiver is empty

o  last
(comment from inherited method)
return the last element of the collection.
This is a slow fallback implementation,
and should be redefined in subclasses which can do indexed accesses.

o  notEmpty
(comment from inherited method)
return true, if the receiver is not empty

o  remove: someElement ifAbsent: aBlock
(comment from inherited method)
search for the first element, which is equal to anObject;
if found, remove and return it.
If not found, return the value of the exceptionBlock.
Uses equality compare (=) to search for the occurrence.
An error is raised here - it is to be implemented by a concrete subclass.

o  removeAllSuchThat: aBlock
(comment from inherited method)
Apply the condition to each element and remove it if the condition is true.
Return a collection of removed elements.
First elements-to-remove are collected, then removed in one operation.

o  removeIdentical: someElement ifAbsent: aBlock
(comment from inherited method)
search for the first element, which is identical to anObject;
if found, remove and return it.
If not found, return the value of the exceptionBlock.
Uses identity compare (==) to search for the occurrence.
An error is raised here - it is to be implemented by a concrete subclass.

o  size
(comment from inherited method)
return the number of elements in the receiver.
This is usually redefined in subclasses for more performance.

o  subclassResponsibility
catches every required message of the collection protocol

queries
o  species
returns non shared collection's species

testing
o  isFixedSize
return true if the receiver cannot grow


Examples:


        |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.
        |c|

        c := SharedCollection for:(Array new:10).
        c at:1 put:5.
        c replaceFrom:2 to:5 with:#(20 30 40 50).
        c inspect.


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Fri, 14 May 2021 17:32:10 GMT