eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'CollectingSharedQueueStream':

Home

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

Class: CollectingSharedQueueStream


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--CollectingSharedQueueStream

Package:
stx:libbasic2
Category:
Streams
Version:
rev: 1.9 date: 2023/07/15 18:39:28
user: cg
file: CollectingSharedQueueStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


This class provides a buffering mechanism between a reader and a writer
process (i.e. it is much like a sharedQueue), but remembers the data as
written by the writer internally, providing indexed access to elements.

The reader side may read from it using #next, and possibly access
elements via #at:.
Reading/accessing may start immediately, but will block until enough elements
have been added by another process, the writer.

Instances of this class may be useful to start processing on
big document/data collection immediately, while the data is still being
read by another thread; 
A concrete application is the HTMLDocumentReader, which is being changed to
start processing and displaying the document while the rest is still being read.

copyright

COPYRIGHT (c) 1997 by Claus Gittinger 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.

Class protocol:

instance creation
o  new
(comment from inherited method)
return an instance of myself without indexed variables


Instance protocol:

accessing
o  at: index
synchronized read - possibly wait for elements up to index
being added (by someone else); then return it.

accessing-special
o  close
signal the end of input; to be used by the writer

o  finalSize: aNumber
can be used by the writer, if the final size is known in
advance.

o  signalChanges: aBoolean
controls if I should send out size-changeMessages when new elements arrive

dummy converting
o  asStringCollection
(comment from inherited method)
return a new string collection containing the elements;
these ought to be strings. (i.e. String or Text instances)

initialization
o  initialize
(comment from inherited method)
just to ignore initialize to objects which do not need it

queries
o  atEnd

o  currentSize

o  size
must wait until closed

reading
o  next
return the next value in the queue; if there is none,
wait 'til something is put into the receiver.

writing
o  nextPut: anObject
append anObject to the queue; if anyone is waiting, tell him.
Answer anObject


Examples:


two processes synchronized much like with a sharedQueue:
  |s reader|

  s := CollectingSharedQueueStream new.
  reader := [
              [s atEnd] whileFalse:[
                  Transcript showCR:s next
              ].
            ] fork.

  1 to:10 do:[:i |
      Delay waitForSeconds:1.
      s nextPut:i
  ].
the writer reads from a (slow) pipe; the reader sends it to the transcript.
  |pipe s reader|

  s := CollectingSharedQueueStream new.
  reader := [
              [s atEnd] whileFalse:[
                  Transcript showCR:s next
              ].
            ] forkAt:9.

  pipe := PipeStream readingFrom:'ls -lR /usr'.
  pipe notNil ifTrue:[
      [pipe atEnd] whileFalse:[
          pipe readWait.
          s nextPut:(pipe nextLine).
      ].
      pipe close.
  ].
  s close
the writer reads from a (slow) pipe; the collection is used in a TextView, which will block whenever lines are to be displayed, which have not yet been read:
  |view pipe buffer reader|

  buffer := CollectingSharedQueueStream new.
  buffer finalSize:100.

  [
      pipe := PipeStream readingFrom:'ls -lR /usr'.
      pipe notNil ifTrue:[
          [pipe atEnd] whileFalse:[
              pipe readWait.
              buffer nextPut:(pipe nextLine).
          ].
          pipe close.
      ].
      buffer changed:#size.
      buffer close.
  ] fork.

  view := ScrollableView for:TextView.
  view model:buffer; listMessage:#value; aspectMessage:#value.
  view open.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 16:12:16 GMT