C# Client Library
A C# Client Library for the AnalyzeRe REST API
AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced > Class Template Referenceabstract

Base class that consumes from a source asynchronously and produces a queue of some other resource to be consumed. More...

Public Member Functions

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 => _runningThread != null
 Indicates whether the producer is currently running. More...
 

Protected Member Functions

 ProducerConsumerBuffer (int max_queue_size)
 Construct a new ProducerConsumer that will read from the specified source and produce a Queue of buffered items to be consumed. More...
 
virtual void Dispose (bool disposing)
 Cancel the producer thread and dispose of the queue. More...
 
abstract bool IsProducerFinished ()
 Implementer indicates whether it can produce more items. More...
 
virtual void OnDispose ()
 Deriving classes' dispose actions. More...
 
virtual void OnStart ()
 Invoked before the asynchronous producer thread is started. 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 IsConsumerWaiting [get]
 Determines whether the consumer of this buffer is currently waiting for it to produce some data. More...
 
BlockingCollection< TProduced > Produced [get]
 The collection of objects produced More...
 

Detailed Description

Base class that consumes from a source asynchronously and produces a queue of some other resource to be consumed.

Template Parameters
TProducedThe type of objects produced.

Definition at line 15 of file ProducerConsumerBuffer.cs.

Inheritance diagram for AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >:
AnalyzeRe.LargeDataUpload.IProducerConsumerBuffer< TProduced >

Constructor & Destructor Documentation

AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.ProducerConsumerBuffer ( int  max_queue_size)
inlineprotected

Construct a new ProducerConsumer that will read from the specified source and produce a Queue of buffered items to be consumed.

Parameters
max_queue_sizeThe maximum number of buffers to create before blocking and waiting for existing bytes to be consumed.

Definition at line 69 of file ProducerConsumerBuffer.cs.

Member Function Documentation

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

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 ( )
inline

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)
inlineprotectedvirtual

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.

abstract bool AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.IsProducerFinished ( )
protectedpure virtual
virtual void AnalyzeRe.LargeDataUpload.ProducerConsumerBuffer< TProduced >.OnDispose ( )
inlineprotectedvirtual

Deriving classes' dispose actions.

Reimplemented in AnalyzeRe.LargeDataUpload.GZipBufferedBytesProducer.

Definition at line 102 of file ProducerConsumerBuffer.cs.

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

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.

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

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 
)
inline

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 => _runningThread != null

Indicates whether the producer is currently running.

Definition at line 26 of file ProducerConsumerBuffer.cs.

Property Documentation

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

Can be used to cancel the buffering process.

Definition at line 53 of file ProducerConsumerBuffer.cs.

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

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.ProducerConsumerBuffer< TProduced >.IsConsumerWaiting
getprotected

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

Definition at line 23 of file ProducerConsumerBuffer.cs.

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

The collection of objects produced

Definition at line 19 of file ProducerConsumerBuffer.cs.


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