public class QuickIOTransferServiceBase
Base Class for transfer service implementations.
A QuickIO service is an instance for processing multiple jobs. QuickIO services offer multiple workers (one worker = one Thread), to enable parallel processing for jobs. By default the priority that a job has, is observed during the processing with PriorityComparer.
All methods and properties are thread-safe
_jobQueue
Queue
private readonly List<IQuickIOTransferJob> _jobQueue
private readonly object _jobQueueLock
private Int32 _maxBufferSize
private Int32 _maxJobRetryAttempts
private Int32 _maxWorkerCount
private Int32 _workerCountRemoveRequested
private readonly object _workerCountRemoveRequestedLock
private readonly object _workerShutdownLock
private readonly Dictionary<Int32, Thread> _workerThreads
private readonly object _workerThreadsLock
CancellationRequested
This event is raised if the service has been made known that he should cancel the processing
public CancellationRequested
CompletedAddingRequested
This event is raised if the service has been made known that no new elements will be added.
public CompletedAddingRequested
JobDequeued
This event is raised if the job was taken from of a queue.
public JobDequeued
JobEnqueued
This event is raised if the job of a queue has been added.
public JobEnqueued
JobRequeued
This event is raised if the job was re-added to a queue.
public JobRequeued
JobRetryMaxReached
This event is raised if the max retry count is reached.
public JobRetryMaxReached
WorkerCreated
This event is raised when a new processing thread was created
public WorkerCreated
WorkerIsWaiting
This event is raised when a processing thread is waiting for new items
public WorkerIsWaiting
WorkerPickedJob
This event is raised when a processing thread has taken a new item from the queue
public WorkerPickedJob
WorkerShutdown
This event is raised when a processing thread was shutdown
public WorkerShutdown
WorkerStarted
This event is raised when a processing thread started
public WorkerStarted
WorkerWokeUp
This event is raised when a processing thread, which so far has been waiting for, was notified of a new item in the queue. It may be that he gets no element from the queue, because another thread was faster. He would sleep lie down again, if no more items available.
public WorkerWokeUp
QuickIOTransferServiceBase(IQuickIOTransferObserver observer)
Creates a new instance of QuickIOTransferServiceBase and sets required properties
private void QuickIOTransferServiceBase(IQuickIOTransferObserver observer)
QuickIOTransferServiceBase(IQuickIOTransferObserver observer, Int32 maxWorkerCount, Int32 maxFileRetry)
Creates a new instance of QuickIOTransferServiceBase
protected void QuickIOTransferServiceBase(IQuickIOTransferObserver observer, Int32 maxWorkerCount, Int32 maxFileRetry)
Parameters
observer
IQuickIOTransferObserverRequired server. Can be null to create default observer
maxWorkerCount
Int32Count of parallel workers to transfer the files
maxFileRetry
Int32Max retry on transfer failure
AddWorker(Int32 count)
Adds a new worker to the service. Worker will be created and started instantly.
protected void AddWorker(Int32 count)
Parameters
count
Int32Must be 1 or greater
Remarks
It's not recommended to use more workers than the count of useable CPU cores.
Cancel()
Cancels the file provider and all transfers
public void Cancel()
Clear()
Clears the queue and returns all queued elements
protected IEnumerable<IQuickIOTransferJob> Clear()
Returns
Collection of IQuickIOTransferJob
CompleteAdding()
Marks the queue as completed. No more items can be added.
public void CompleteAdding()
CreateWorkers()
Creates the amount of workers
protected void CreateWorkers()
InternalAdd(QuickIOTransferJob queueItem)
Locks the queue and adds the element.
protected void InternalAdd(QuickIOTransferJob queueItem)
Parameters
queueItem
QuickIOTransferJobItem to add
Remarks
The service will inject his observer to the job. If the job already has an observer, it will be overwritten.
InternalAddRange(IEnumerable queueItems)
Locks the queue and adds the collection to the queue.
protected void InternalAddRange(IEnumerable queueItems)
Parameters
queueItems
IEnumerableCollection of items to add
InternalCreateNewWorker()
Creates a new worker
private Thread InternalCreateNewWorker()
Returns
Created thread
InternalReSortLockedQueue()
Resorts the Queue
private void InternalReSortLockedQueue()
InternalStartWorker(Thread wt)
Starts the given worker by ID
private void InternalStartWorker(Thread wt)
InternalWaitForNewQueueItems()
waits for queue items
private void InternalWaitForNewQueueItems()
JobExecuteSwitch(IQuickIOTransferJob job)
Consuming - transfer file
private void JobExecuteSwitch(IQuickIOTransferJob job)
Parameters
job
IQuickIOTransferJobQueue Item
OnCancellationRequested()
Fire CancellationRequested
private void OnCancellationRequested()
OnCompletedAddingRequested()
Fire CompletedAddingRequested
private void OnCompletedAddingRequested()
OnJobDequeued(IQuickIOTransferJob job)
Fire JobDequeued
protected void OnJobDequeued(IQuickIOTransferJob job)
Parameters
job
IQuickIOTransferJobAffected job
OnJobEnqueued(IQuickIOTransferJob job)
Fire JobEnqueued
protected void OnJobEnqueued(IQuickIOTransferJob job)
Parameters
job
IQuickIOTransferJobAffected job
OnJobRequeued(IQuickIOTransferJob job, Exception e)
Fire JobRequeued for this service and specified observer
protected void OnJobRequeued(IQuickIOTransferJob job, Exception e)
Parameters
job
IQuickIOTransferJobAffected job
e
ExceptionCaused exception
OnJobRetryMaxReached(IQuickIOTransferJob job, Exception lastException)
Fire JobRetryMaxReached
protected void OnJobRetryMaxReached(IQuickIOTransferJob job, Exception lastException)
Parameters
job
IQuickIOTransferJobAffected job
lastException
ExceptionLast exception
OnWorkerCreated(Int32 threadId)
Fire WorkerCreated
private void OnWorkerCreated(Int32 threadId)
Parameters
threadId
Int32affcted Worker Thread ID
OnWorkerIsWaiting(Int32 threadId)
Fire WorkerPickedJob
private void OnWorkerIsWaiting(Int32 threadId)
Parameters
threadId
Int32affcted Worker Thread ID
OnWorkerPickedJob(Int32 threadId, IQuickIOTransferJob job)
Fire WorkerPickedJob
private void OnWorkerPickedJob(Int32 threadId, IQuickIOTransferJob job)
Parameters
threadId
Int32affcted Worker Thread ID
job
IQuickIOTransferJobpicked job
OnWorkerShutdown(Int32 threadId)
Fire WorkerShutdown
private void OnWorkerShutdown(Int32 threadId)
Parameters
threadId
Int32affcted Worker Thread ID
OnWorkerStarted(Int32 threadId)
Fire WorkerStarted
private void OnWorkerStarted(Int32 threadId)
Parameters
threadId
Int32affcted Worker Thread ID
OnWorkerWokeUp(Int32 threadId)
Fire WorkerWokeUp
private void OnWorkerWokeUp(Int32 threadId)
Parameters
threadId
Int32affcted Worker Thread ID
RemoveThread(Int32 threadId)
Removes a Thread from _workerThreads and raises OnWorkerShutdown
private void RemoveThread(Int32 threadId)
Parameters
threadId
Int32Affcted Thread ID
RemoveWorker(Int32 count)
Remove workers from the service.
protected void RemoveWorker(Int32 count)
Parameters
count
Int32Must be 1 or greater
StartConsuming(object threadId)
Element consuming. Breaks if element is null.
private void StartConsuming(object threadId)
StartWorkers()
Creates the amount of workers
protected void StartWorkers()
StartWorking()
Starts the service
protected Boolean StartWorking()
Returns
false if service is already started
WaitForFinish()
Joins all threads and blocks until all threads and queue items are completed. Queue has to be completed.
protected void WaitForFinish()
WakeUpSleepingWorkers()
Wakes sleeping workers up
private void WakeUpSleepingWorkers()
AddingCompleted
true if queue adding is completed. No more items will be added.
public Boolean AddingCompleted { get; set; }
CancelRequested
true is cancel is requested
public Boolean CancelRequested { get; set; }
IsWorking
True if service is running
protected Boolean IsWorking { get; }
MaxBufferSize
Size of Buffer
public Int32 MaxBufferSize { get; set; }
MaxJobRetryAttempts
Max Job Retry Count
public Int32 MaxJobRetryAttempts { get; set; }
MaxWorkerCount
Max count of active workers
public Int32 MaxWorkerCount { get; set; }
Observer
Provides Events and Settings for transfer monitoring
public IQuickIOTransferObserver Observer { get; set; }
PriorityComparer
Comparer for job sorting. By default it's QuickIOTransferJobPriorityComparer. FIFO if comparer is null.
public IComparer<IQuickIOTransferJob> PriorityComparer { get; set; }
WorkerCount
Count of active workers
public Int32 WorkerCount { get; }