Produces a BlockingCollection of buffered bytes asynchronously which can be consumed on some other thread.
More...
|
| BufferedBytesFromStreamProducer (Stream data_source, long? bytes_to_read=null, int? min_buffer_length=null, int? max_buffer_length=null) |
| Construct a new BufferProducer that will read bytes from the specified stream and produce a Queue of buffered byte arrays to be consumed.
|
|
virtual void | Cancel () |
| Stop the producer from reading any more bytes. Warning: This will leave the stream in its current position and any bytes that haven't been inserted into the buffer are lost.
|
|
void | Dispose () |
| Cancel the producer thread and dispose of the queue.
|
|
void | Start (CancellationToken? cancellationToken=null) |
| Start the asynchronous producer.
|
|
TProduced | TryTake (out bool success, CancellationToken? cancellation) |
| Attempts to remove an item from the produced list. May block if there is not yet an item ready, or return success:false.
|
|
|
virtual void | Dispose (bool disposing) |
| Cancel the producer thread and dispose of the queue.
|
|
override bool | IsProducerFinished () |
| Indicates whether we're done reading from the stream.
|
|
virtual void | OnDispose () |
| Deriving classes' dispose actions.
|
|
override void | OnStart () |
| Ensure the FirstBufferLength doesn't exceed the set buffer length.
|
|
override bool | TryProduceNext (out BufferedBytes buffer) |
| Attempts to read from the stream.
|
|
override bool | TryProduceNext (out BufferedBytes next, int buffer_size) |
| Attempts to read from the stream.
|
|
bool | TryProduceNext (out TProduced next) |
| The method which asynchronously produces items.
|
|
|
long? | BytesToRead [get] |
| The total number of bytes that will be read from the stream.
|
|
CancellationTokenSource | Cancellation [get] |
| Can be used to cancel the buffering process.
|
|
bool | CanTake [get] |
| Indicates whether a call to Take will ever return another item.
|
|
bool | EndOfStreamDetected [get] |
| Is set to true if the input source has closed and/or stopped returning bytes.
|
|
bool | IsConsumerWaiting [get] |
| Determines whether the consumer of this buffer is currently waiting for it to produce some data.
|
|
bool | IsRunning [get] |
| Indicates whether the producer is currently running.
|
|
int | MaximumBufferLength = 33554432 [get, set] |
| The max length of the each byte array to generate. (Default 32 MiB)
|
|
int | MinimumBufferLength = 16384 [get, set] |
| The minimum length of the byte array to generate when the consumer of this buffer is currently waiting for more data. (Default 16 KiB) Set this lower if the consumer frequently spends too much time waiting for the producer to send the prepare the next byte array. As soon as the consumer requests more data, we will return the current buffer, if we've filled more than this many bytes. Note that smaller buffers may be returned if the end of the source stream is reached.
|
|
BlockingCollection< TProduced > | Produced [get] |
| The collection of objects produced.
|
|
long | TotalBytesRead [get] |
| The total number of bytes that have been buffered since start.
|
|
Produces a BlockingCollection of buffered bytes asynchronously which can be consumed on some other thread.
Definition at line 8 of file BufferedBytesFromStreamProducer.cs.
◆ BufferedBytesFromStreamProducer()
AnalyzeRe.LargeDataUpload.BufferedBytesFromStreamProducer.BufferedBytesFromStreamProducer |
( |
Stream |
data_source, |
|
|
long? |
bytes_to_read = null , |
|
|
int? |
min_buffer_length = null , |
|
|
int? |
max_buffer_length = null |
|
) |
| |
|
inline |
Construct a new BufferProducer that will read bytes from the specified stream and produce a Queue of buffered byte arrays to be consumed.
- Parameters
-
data_source | The source from which bytes will be read. |
bytes_to_read | The number of bytes to read from the stream. If supplied, the reader will read from the stream until that many bytes have been retrieved. If left blank, the reader will read until the end of the stream is detected. If the stream does not reveal it's length, the reader will read until the first time the stream returns 0 bytes, which isn't guaranteed to be the end of the stream. |
min_buffer_length | (optional) The minimum size a buffered byte array will have. The first object returned will have this length to ensure the consumer becomes unblocked as soon as possible. See AdaptiveBufferedBytesProducer.MinimumBufferLength for details and defaults. |
max_buffer_length | (optional) The maximum size the buffered byte arrays can reach. See AdaptiveBufferedBytesProducer.MaximumBufferLength for details and defaults. |
Definition at line 46 of file BufferedBytesFromStreamProducer.cs.
◆ Cancel()
Stop the producer from reading any more bytes. Warning: This will leave the stream in its current position and any bytes that haven't been inserted into the buffer are lost.
Definition at line 172 of file ProducerConsumerBuffer.cs.
◆ Dispose() [1/2]
◆ Dispose() [2/2]
|
inlineprotectedvirtualinherited |
Cancel the producer thread and dispose of the queue.
- Parameters
-
disposing | Whether dispose is being called by the dispose method or the finalizer |
Definition at line 91 of file ProducerConsumerBuffer.cs.
◆ IsProducerFinished()
override bool AnalyzeRe.LargeDataUpload.BufferedBytesFromStreamProducer.IsProducerFinished |
( |
| ) |
|
|
inlineprotected |
Indicates whether we're done reading from the stream.
- Returns
- True if the end of stream is reached of we've read the number of bytes requested at construction time.
Definition at line 62 of file BufferedBytesFromStreamProducer.cs.
◆ OnDispose()
|
inlineprotectedvirtualinherited |
◆ OnStart()
override void AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer.OnStart |
( |
| ) |
|
|
inlineprotectedvirtualinherited |
◆ Start()
Start the asynchronous producer.
- Parameters
-
cancellationToken | Cancellation token that will notify this producer if it is cancelled and halt the producer thread. |
- Exceptions
-
InvalidOperationException | Producer is already running. |
Definition at line 110 of file ProducerConsumerBuffer.cs.
◆ TryProduceNext() [1/3]
override bool AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer.TryProduceNext |
( |
out BufferedBytes |
buffer | ) |
|
|
inlinesealedprotectedinherited |
Attempts to read from the stream.
- Parameters
-
buffer | The next buffer to add to the queue. |
- Returns
- True if some bytes were successfully buffered.
Definition at line 78 of file AdaptiveBufferedBytesProducer.cs.
◆ TryProduceNext() [2/3]
override bool AnalyzeRe.LargeDataUpload.BufferedBytesFromStreamProducer.TryProduceNext |
( |
out BufferedBytes |
next, |
|
|
int |
buffer_size |
|
) |
| |
|
inlineprotected |
Attempts to read from the stream.
- Parameters
-
next | The next buffer to add to the queue. |
buffer_size | The size of BufferedBytes to create. |
- Returns
- True if some bytes were successfully buffered.
Definition at line 71 of file BufferedBytesFromStreamProducer.cs.
◆ TryProduceNext() [3/3]
|
abstractprotectedinherited |
The method which asynchronously produces items.
- Parameters
-
next | The next item to add to the blocking collection. |
- Returns
- True if an item was successfully produced.
◆ TryTake()
Attempts to remove an item from the produced list. May block if there is not yet an item ready, or return success:false.
- Parameters
-
success | Returns true if a valid item was returned. |
cancellation | A cancellation token which can be used to cancel this Take operation. |
- Returns
- The item removed from the list.
- Exceptions
-
BufferProducerException | If the producer thread raised an exception. |
InvalidOperationException | The producer thread is not currently running, either because the Start method has not been called, or because the Cancel method has been called. |
Definition at line 138 of file ProducerConsumerBuffer.cs.
◆ BytesToRead
long? AnalyzeRe.LargeDataUpload.BufferedBytesFromStreamProducer.BytesToRead |
|
get |
◆ Cancellation
◆ CanTake
Indicates whether a call to Take will ever return another item.
- Exceptions
-
BufferProducerException | If the producer thread raised an exception. |
HACK: Need some way of surfacing asynchronous errors without consumers assuming we're done, so raise any asynchronous exception here. TODO: Revisit Implementation such that BufferProducerException is discovered elsewhere CanTake can simply be made to return false if an exception occurred.
Definition at line 36 of file ProducerConsumerBuffer.cs.
◆ EndOfStreamDetected
bool AnalyzeRe.LargeDataUpload.BufferedBytesFromStreamProducer.EndOfStreamDetected |
|
get |
◆ IsConsumerWaiting
Determines whether the consumer of this buffer is currently waiting for it to produce some data.
Definition at line 23 of file ProducerConsumerBuffer.cs.
◆ IsRunning
◆ MaximumBufferLength
int AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer.MaximumBufferLength = 33554432 |
|
getsetinherited |
◆ MinimumBufferLength
int AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer.MinimumBufferLength = 16384 |
|
getsetinherited |
The minimum length of the byte array to generate when the consumer of this buffer is currently waiting for more data. (Default 16 KiB) Set this lower if the consumer frequently spends too much time waiting for the producer to send the prepare the next byte array. As soon as the consumer requests more data, we will return the current buffer, if we've filled more than this many bytes. Note that smaller buffers may be returned if the end of the source stream is reached.
Definition at line 30 of file AdaptiveBufferedBytesProducer.cs.
◆ Produced
◆ TotalBytesRead
long AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer.TotalBytesRead |
|
getinherited |
The documentation for this class was generated from the following file: