C# Client Library
A C# Client Library for the AnalyzeRe REST API
AnalyzeRe.LargeDataUpload.BufferedBytesResizer Class Referenceabstract

Produces a BlockingCollection of buffered bytes asynchronously which can be consumed on some other thread. More...

Public Member Functions

 BufferedBytesResizer (IProducerConsumerBuffer< BufferedBytes > data_source, int?min_buffer_length=null, int?max_buffer_length=null)
 Construct a new BufferProducer that will read bytes from the specified BufferedBytes and produce a new Queue of buffered byte arrays of a of a different size to be consumed. More...
 
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. More...
 
void Dispose ()
 Cancel the producer thread and dispose of the queue. More...
 
void Start (CancellationToken?cancellationToken=null)
 Start the asynchronous producer. More...
 
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. More...
 

Public Attributes

bool IsRunning
 Indicates whether the producer is currently running. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 Cancel the producer thread and dispose of the queue. More...
 
override bool IsProducerFinished ()
 Indicates whether it can produce more items. More...
 
virtual void OnDispose ()
 Deriving classes' dispose actions. More...
 
override void OnStart ()
 Invoked before the asynchronous producer thread is started. More...
 
override bool TryProduceNext (out BufferedBytes next, int buffer_size)
 Attempts to read from the stream. More...
 
sealed override bool TryProduceNext (out BufferedBytes buffer)
 Attempts to read from the stream. More...
 
abstract bool TryProduceNext (out TProduced next)
 The method which asynchronously produces items. More...
 

Properties

CancellationTokenSource Cancellation [get]
 Can be used to cancel the buffering process. More...
 
bool CanTake [get]
 Indicates whether a call to Take will ever return another item. More...
 
bool EndOfStreamDetected [get]
 Is set to true if the stream has closed and/or stopped returning bytes. More...
 
bool IsConsumerWaiting [get]
 Determines whether the consumer of this buffer is currently waiting for it to produce some data. More...
 
int MaximumBufferLength [get, set]
 The max length of the each byte array to generate. (Default 32 MiB) More...
 
int MinimumBufferLength = 33554432 [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. More...
 
BlockingCollection< TProduced > Produced [get]
 The collection of objects produced More...
 
long TotalBytesRead = 16384 [get]
 The total number of bytes that have been buffered since start. More...
 

Detailed Description

Produces a BlockingCollection of buffered bytes asynchronously which can be consumed on some other thread.

Definition at line 7 of file BufferedBytesResizer.cs.

Inheritance diagram for AnalyzeRe.LargeDataUpload.BufferedBytesResizer:
AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< BufferedBytes >

Constructor & Destructor Documentation

AnalyzeRe.LargeDataUpload.BufferedBytesResizer.BufferedBytesResizer ( IProducerConsumerBuffer< BufferedBytes data_source,
int?  min_buffer_length = null,
int?  max_buffer_length = null 
)
inline

Construct a new BufferProducer that will read bytes from the specified BufferedBytes and produce a new Queue of buffered byte arrays of a of a different size to be consumed.

Parameters
data_sourceThe source from which bytes will be read.
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 42 of file BufferedBytesResizer.cs.

Member Function Documentation

virtual void AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.Cancel ( )
inlinevirtualinherited

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.

void AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.Dispose ( )
inlineinherited

Cancel the producer thread and dispose of the queue.

Definition at line 76 of file ProducerConsumerBuffer.cs.

virtual void AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.Dispose ( bool  disposing)
inlineprotectedvirtualinherited

Cancel the producer thread and dispose of the queue.

Parameters
disposingWhether dispose is being called by the dispose method or the finalizer

Definition at line 91 of file ProducerConsumerBuffer.cs.

override bool AnalyzeRe.LargeDataUpload.BufferedBytesResizer.IsProducerFinished ( )
protectedvirtual

Indicates whether it can produce more items.

Returns
True if it is finished producing items.

Implements AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< BufferedBytes >.

virtual void AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.OnDispose ( )
inlineprotectedvirtualinherited

Deriving classes' dispose actions.

Reimplemented in AnalyzeRe.LargeDataUpload.GZipBufferedBytesProducer.

Definition at line 102 of file ProducerConsumerBuffer.cs.

override void AnalyzeRe.LargeDataUpload.BufferedBytesResizer.OnStart ( )
inlineprotectedvirtual

Invoked before the asynchronous producer thread is started.

Reimplemented from AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer.

Definition at line 52 of file BufferedBytesResizer.cs.

void AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.Start ( CancellationToken?  cancellationToken = null)
inlineinherited

Start the asynchronous producer.

Parameters
cancellationTokenCancellation token that will notify this producer if it is cancelled and halt the producer thread.
Exceptions
InvalidOperationExceptionProducer is already running.

Definition at line 110 of file ProducerConsumerBuffer.cs.

override bool AnalyzeRe.LargeDataUpload.BufferedBytesResizer.TryProduceNext ( out BufferedBytes  next,
int  buffer_size 
)
inlineprotectedvirtual

Attempts to read from the stream.

Parameters
nextThe next buffer to add to the queue.
buffer_sizeThe size of BufferedBytes to create.
Returns
True if some bytes were successfully buffered.

Implements AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer.

Definition at line 69 of file BufferedBytesResizer.cs.

sealed override bool AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer.TryProduceNext ( out BufferedBytes  buffer)
inlineprotectedinherited

Attempts to read from the stream.

Parameters
bufferThe next buffer to add to the queue.
Returns
True if some bytes were successfully buffered.

Definition at line 78 of file AdaptiveBufferedBytesProducer.cs.

abstract bool AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.TryProduceNext ( out TProduced  next)
protectedpure virtualinherited

The method which asynchronously produces items.

Parameters
nextThe next item to add to the blocking collection.
Returns
True if an item was successfully produced.
TProduced AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.TryTake ( out bool  success,
CancellationToken?  cancellation 
)
inlineinherited

Attempts to remove an item from the produced list. May block if there is not yet an item ready, or return success:false.

Parameters
successReturns true if a valid item was returned.
cancellationA cancellation token which can be used to cancel this Take operation.
Returns
The item removed from the list.
Exceptions
BufferProducerExceptionIf the producer thread raised an exception.
InvalidOperationExceptionThe 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.

Member Data Documentation

bool AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.IsRunning
inherited

Indicates whether the producer is currently running.

Definition at line 26 of file ProducerConsumerBuffer.cs.

Property Documentation

CancellationTokenSource AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.Cancellation
getprotectedinherited

Can be used to cancel the buffering process.

Definition at line 53 of file ProducerConsumerBuffer.cs.

bool AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.CanTake
getinherited

Indicates whether a call to Take will ever return another item.

Exceptions
BufferProducerExceptionIf 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 37 of file ProducerConsumerBuffer.cs.

bool AnalyzeRe.LargeDataUpload.BufferedBytesResizer.EndOfStreamDetected
get

Is set to true if the stream has closed and/or stopped returning bytes.

Definition at line 12 of file BufferedBytesResizer.cs.

bool AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.IsConsumerWaiting
getprotectedinherited

Determines whether the consumer of this buffer is currently waiting for it to produce some data.

Definition at line 23 of file ProducerConsumerBuffer.cs.

int AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer.MaximumBufferLength
getsetinherited

The max length of the each byte array to generate. (Default 32 MiB)

Definition at line 21 of file AdaptiveBufferedBytesProducer.cs.

int AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer.MinimumBufferLength = 33554432
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.

BlockingCollection<TProduced> AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.Produced
getprotectedinherited

The collection of objects produced

Definition at line 19 of file ProducerConsumerBuffer.cs.

long AnalyzeRe.LargeDataUpload.AdaptiveBufferedBytesProducer.TotalBytesRead = 16384
getinherited

The total number of bytes that have been buffered since start.

Definition at line 33 of file AdaptiveBufferedBytesProducer.cs.


The documentation for this class was generated from the following file: