CollectingSharedQueueStream.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5240 52484606278b
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:
4329
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
     1
"
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
     2
 COPYRIGHT (c) 1997 by Claus Gittinger
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
     3
              All Rights Reserved
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
     4
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
     5
 This software is furnished under a license and may be used
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
     6
 only in accordance with the terms of that license and with the
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
     9
 other person.  No title to or ownership of the software is
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    10
 hereby transferred.
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    11
"
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    13
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    14
"{ NameSpace: Smalltalk }"
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    15
502
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
    16
SequenceableCollection subclass:#CollectingSharedQueueStream
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
    17
	instanceVariableNames:'contents readPosition writePosition dataAvailable closed
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
    18
		finalSizeIfKnown signalChanges'
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	classVariableNames:''
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	poolDictionaries:''
501
3299cf782635 category change
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    21
	category:'Streams'
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!CollectingSharedQueueStream class methodsFor:'documentation'!
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
4329
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    26
copyright
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    27
"
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    28
 COPYRIGHT (c) 1997 by Claus Gittinger
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    29
              All Rights Reserved
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    30
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    31
 This software is furnished under a license and may be used
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    32
 only in accordance with the terms of that license and with the
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    33
 inclusion of the above copyright notice.   This software may not
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    34
 be provided or otherwise made available to, or used by, any
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    35
 other person.  No title to or ownership of the software is
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    36
 hereby transferred.
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    37
"
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    38
!
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
    39
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
documentation
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
501
3299cf782635 category change
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    42
    This class provides a buffering mechanism between a reader and a writer
3299cf782635 category change
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    43
    process (i.e. it is much like a sharedQueue), but remembers the data as
3299cf782635 category change
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    44
    written by the writer internally, providing indexed access to elements.
3299cf782635 category change
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    45
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    The reader side may read from it using #next, and possibly access
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    elements via #at:.
501
3299cf782635 category change
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    48
    Reading/accessing may start immediately, but will block until enough elements
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    have been added by another process, the writer.
501
3299cf782635 category change
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    50
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    Instances of this class may be useful to start processing on
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    big document/data collection immediately, while the data is still being
501
3299cf782635 category change
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    53
    read by another thread; 
3299cf782635 category change
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    54
    A concrete application is the HTMLDocumentReader, which is being changed to
3299cf782635 category change
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    55
    start processing and displaying the document while the rest is still being read.
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    [author:]
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
        Claus Gittinger
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    [see also:]
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
        Stream OrderedCollection SharedQueue
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
"
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
!
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
examples
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
"
502
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
    67
  two processes synchronized much like with a sharedQueue:
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
                                                        [exBegin]
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    |s reader|
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    s := CollectingSharedQueueStream new.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    reader := [
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
                [s atEnd] whileFalse:[
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
                    Transcript showCR:s next
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
                ].
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
              ] fork.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    1 to:10 do:[:i |
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
        Delay waitForSeconds:1.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
        s nextPut:i
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    ].
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
                                                        [exEnd]
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
502
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
    84
  the writer reads from a (slow) pipe;
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
    85
  the reader sends it to the transcript.
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
                                                        [exBegin]
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    |pipe s reader|
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    s := CollectingSharedQueueStream new.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    reader := [
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
                [s atEnd] whileFalse:[
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
                    Transcript showCR:s next
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
                ].
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
              ] forkAt:9.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    pipe := PipeStream readingFrom:'ls -lR /usr'.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
    pipe notNil ifTrue:[
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
        [pipe atEnd] whileFalse:[
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
            pipe readWait.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
            s nextPut:(pipe nextLine).
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
        ].
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
        pipe close.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    ].
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    s close
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
                                                        [exEnd]
502
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   106
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   107
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   108
  the writer reads from a (slow) pipe;
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   109
  the collection is used in a TextView, which
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   110
  will block whenever lines are to be displayed, which have not
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   111
  yet been read:
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   112
                                                        [exBegin]
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   113
    |view pipe buffer reader|
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   114
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   115
    buffer := CollectingSharedQueueStream new.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   116
    buffer finalSize:100.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   117
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   118
    [
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   119
        pipe := PipeStream readingFrom:'ls -lR /usr'.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   120
        pipe notNil ifTrue:[
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   121
            [pipe atEnd] whileFalse:[
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   122
                pipe readWait.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   123
                buffer nextPut:(pipe nextLine).
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   124
            ].
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   125
            pipe close.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   126
        ].
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   127
        buffer changed:#size.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   128
        buffer close.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   129
    ] fork.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   130
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   131
    view := ScrollableView for:TextView.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   132
    view model:buffer; listMessage:#value; aspectMessage:#value.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   133
    view open.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   134
                                                        [exEnd]
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
"
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
! !
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
!CollectingSharedQueueStream class methodsFor:'instance creation'!
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
new
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    ^ self basicNew initialize
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    "Created: 5.3.1997 / 14:30:36 / cg"
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
! !
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
!CollectingSharedQueueStream methodsFor:'accessing'!
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
at:index
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    "synchronized read - possibly wait for elements up to index
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
     being added (by someone else); then return it."
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
    writePosition > index ifTrue:[
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
        ^ contents at:index
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    ].
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    [writePosition <= index] whileTrue:[
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
        closed ifTrue:[
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
            ^ self subscriptBoundsError:index
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
        ].
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
        dataAvailable wait.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
    ].
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
    ^ contents at:index
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
    "Created: 5.3.1997 / 14:44:41 / cg"
502
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   166
! !
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   167
4540
9f49e01f4e9c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4329
diff changeset
   168
!CollectingSharedQueueStream methodsFor:'accessing-special'!
502
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   169
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   170
close
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   171
    "signal the end of input; to be used by the writer"
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   172
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   173
    closed := true.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   174
    dataAvailable signal
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   175
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   176
    "Modified: 5.3.1997 / 14:45:11 / cg"
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   177
!
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   178
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   179
finalSize:aNumber
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   180
    "can be used by the writer, if the final size is known in
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   181
     advance."
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   182
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   183
    finalSizeIfKnown := aNumber.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   184
    signalChanges ifTrue:[
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   185
        self changed:#size
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   186
    ].
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   187
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   188
    "Created: 5.3.1997 / 15:36:07 / cg"
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   189
    "Modified: 5.3.1997 / 15:57:24 / cg"
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   190
!
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   191
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   192
signalChanges:aBoolean
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   193
    "controls if I should send out size-changeMessages when new elements arrive"
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   194
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   195
    signalChanges := aBoolean.
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   196
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   197
    "Created: 5.3.1997 / 15:40:57 / cg"
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   198
! !
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   199
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   200
!CollectingSharedQueueStream methodsFor:'dummy converting'!
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   201
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   202
asStringCollection
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   203
     ^ self
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   204
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   205
    "Created: 5.3.1997 / 16:02:57 / cg"
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
! !
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
!CollectingSharedQueueStream methodsFor:'initialization'!
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
initialize
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
    readPosition := writePosition := 1.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    dataAvailable := Semaphore new.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    contents := OrderedCollection new.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
    closed := false.
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    "Modified: 5.3.1997 / 14:34:55 / cg"
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
! !
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
!CollectingSharedQueueStream methodsFor:'queries'!
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
atEnd
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
    closed ifFalse:[^ false].
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    ^ readPosition >= writePosition
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    "Modified: 5.3.1997 / 14:41:04 / cg"
502
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   226
!
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   227
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   228
currentSize
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   229
    ^ contents size
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   230
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   231
    "Modified: 5.3.1997 / 15:56:36 / cg"
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   232
!
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   233
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   234
size
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   235
    closed ifTrue:[^ contents size].
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   236
    finalSizeIfKnown notNil ifTrue:[^ finalSizeIfKnown].
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   237
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   238
    "/ must wait until closed
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   239
    [closed] whileFalse:[
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   240
        dataAvailable wait
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   241
    ].
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   242
    closed ifTrue:[^ contents size].
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   243
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   244
    "Created: 5.3.1997 / 15:35:29 / cg"
1d4a576e4955 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 501
diff changeset
   245
    "Modified: 5.3.1997 / 15:57:08 / cg"
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
! !
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
5240
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   248
!CollectingSharedQueueStream methodsFor:'reading'!
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   249
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   250
next
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   251
    "return the next value in the queue; if there is none,
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   252
     wait 'til something is put into the receiver."
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   253
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   254
    |value|
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   255
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   256
    [readPosition >= writePosition] whileTrue:[
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   257
        closed ifTrue:[
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   258
            ^ nil
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   259
        ].
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   260
        dataAvailable wait
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   261
    ].
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   262
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   263
    value := contents at:readPosition.
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   264
    readPosition := readPosition + 1.
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   265
    ^ value
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   266
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   267
    "Created: 5.3.1997 / 14:28:57 / cg"
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   268
    "Modified: 5.3.1997 / 14:45:54 / cg"
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   269
! !
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   270
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   271
!CollectingSharedQueueStream methodsFor:'writing'!
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   272
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   273
nextPut:anObject
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   274
    "append anObject to the queue; if anyone is waiting, tell him.
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   275
     Answer anObject"
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   276
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   277
    contents add:anObject.
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   278
    writePosition := writePosition + 1.
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   279
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   280
    finalSizeIfKnown isNil ifTrue:[
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   281
        signalChanges ifTrue:[
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   282
            self changed:#size with:nil
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   283
        ]
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   284
    ].
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   285
    dataAvailable signal.
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   286
    ^ anObject
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   287
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   288
    "Created: 5.3.1997 / 14:33:44 / cg"
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   289
    "Modified: 5.3.1997 / 15:42:33 / cg"
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   290
! !
52484606278b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5162
diff changeset
   291
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
!CollectingSharedQueueStream class methodsFor:'documentation'!
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
version
4329
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
   295
    ^ '$Header$'
500
f1df3a589fb4 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
! !
4329
a9d435360ebb #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 502
diff changeset
   297