Fields (10) Events (12) Methods (33) Properties (9)
Namespace: SchwabenCode.QuickIO.Transfer

Syntax

public class QuickIOTransferServiceBase

Summary

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.

Remarks

All methods and properties are thread-safe

Uses

Used by

Fields

_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

Events

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

Methods

QuickIOTransferServiceBase(IQuickIOTransferObserver observer)

Creates a new instance of QuickIOTransferServiceBase and sets required properties

private void QuickIOTransferServiceBase(IQuickIOTransferObserver observer)
protected void QuickIOTransferServiceBase(IQuickIOTransferObserver observer, Int32 maxWorkerCount, Int32 maxFileRetry)

Parameters

observer

IQuickIOTransferObserver

Required server. Can be null to create default observer

maxWorkerCount

Int32

Count of parallel workers to transfer the files

maxFileRetry

Int32

Max 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

Int32

Must 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

QuickIOTransferJob

Item 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

IEnumerable

Collection 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()
private void JobExecuteSwitch(IQuickIOTransferJob job)

Parameters

job

IQuickIOTransferJob

Queue Item

OnCancellationRequested()

Fire CancellationRequested

private void OnCancellationRequested()

OnCompletedAddingRequested()

Fire CompletedAddingRequested

private void OnCompletedAddingRequested()
protected void OnJobDequeued(IQuickIOTransferJob job)

Parameters

job

IQuickIOTransferJob

Affected job

protected void OnJobEnqueued(IQuickIOTransferJob job)

Parameters

job

IQuickIOTransferJob

Affected job

OnJobRequeued(IQuickIOTransferJob job, Exception e)

Fire JobRequeued for this service and specified observer

protected void OnJobRequeued(IQuickIOTransferJob job, Exception e)

Parameters

job

IQuickIOTransferJob

Affected job

e

Exception

Caused exception

protected void OnJobRetryMaxReached(IQuickIOTransferJob job, Exception lastException)

Parameters

job

IQuickIOTransferJob

Affected job

lastException

Exception

Last exception

private void OnWorkerCreated(Int32 threadId)

Parameters

threadId

Int32

affcted Worker Thread ID

private void OnWorkerIsWaiting(Int32 threadId)

Parameters

threadId

Int32

affcted Worker Thread ID

private void OnWorkerPickedJob(Int32 threadId, IQuickIOTransferJob job)

Parameters

threadId

Int32

affcted Worker Thread ID

job

IQuickIOTransferJob

picked job

private void OnWorkerShutdown(Int32 threadId)

Parameters

threadId

Int32

affcted Worker Thread ID

private void OnWorkerStarted(Int32 threadId)

Parameters

threadId

Int32

affcted Worker Thread ID

private void OnWorkerWokeUp(Int32 threadId)

Parameters

threadId

Int32

affcted Worker Thread ID

RemoveThread(Int32 threadId)

Removes a Thread from _workerThreads and raises OnWorkerShutdown

private void RemoveThread(Int32 threadId)

Parameters

threadId

Int32

Affcted Thread ID

RemoveWorker(Int32 count)

Remove workers from the service.

protected void RemoveWorker(Int32 count)

Parameters

count

Int32

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

Properties

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; }

Classdiagram

public classQuickIOTransferServiceBase_jobQueue_jobQueueLock_maxBufferSize_maxJobRetryAttempts_maxWorkerCount_workerCountRemoveRequested_workerCountRemoveRequestedLock_workerShutdownLock_workerThreads_workerThreadsLockCancellationRequestedCompletedAddingRequestedJobDequeuedJobEnqueuedJobRequeuedJobRetryMaxReachedWorkerCreatedWorkerIsWaitingWorkerPickedJobWorkerShutdownWorkerStartedWorkerWokeUpAddWorkerCancelClearCompleteAddingCreateWorkersInternalAddInternalAddRangeInternalCreateNewWorkerInternalReSortLockedQueueInternalStartWorkerInternalWaitForNewQueueItemsJobExecuteSwitchOnCancellationRequestedOnCompletedAddingRequestedOnJobDequeuedOnJobEnqueuedOnJobRequeuedOnJobRetryMaxReachedOnWorkerCreatedOnWorkerIsWaitingOnWorkerPickedJobOnWorkerShutdownOnWorkerStartedOnWorkerWokeUpRemoveThreadRemoveWorkerStartConsumingStartWorkersStartWorkingWaitForFinishWakeUpSleepingWorkersQuickIOTransferServiceBaseQuickIOTransferServiceBaseAddingCompleted { get; set; }CancelRequested { get; set; }IsWorking { get; }MaxBufferSize { get; set; }MaxJobRetryAttempts { get; set; }MaxWorkerCount { get; set; }Observer { get; set; }PriorityComparer { get; set; }WorkerCount { get; }public classQuickIOTransferBackgroundServiceAddAddWorkerRemoveWorkerStartWaitForFinishQuickIOTransferBackgroundServiceQuickIOTransferBackgroundServicepublic classQuickIOTransferDirectoryCopyService_runningDetermineDirectoryTransferPrefencesStartStartAsyncQuickIOTransferDirectoryCopyServiceQuickIOTransferDirectoryCopyServiceIsRunning { get; set; }Overwrite { get; set; }SearchOption { get; set; }SourceDirectoryInfo { get; set; }TargetFullName { get; set; }public classQuickIOTransferFileCopyService_totalBytes_totalBytesLock_totalBytesTransfered_totalBytesTransferedLockStartStartAsyncQuickIOTransferFileCopyServiceQuickIOTransferFileCopyServiceBytesPerSecond { get; }Duration { get; }Overwrite { get; set; }Percentage { get; }SourceFileInfos { get; set; }TargetFullName { get; set; }TotalBytes { get; set; }TotalBytesTransfered { get; set; }TransferFinished { get; set; }TransferStarted { get; set; }public interfaceIQuickIOTransferObserverCancellationRequestedCompletedAddingRequestedDirectoryCreatedDirectoryCreatingDirectoryCreationErrorFileCopyErrorFileCopyFinishedFileCopyProgressFileCopyStartedFileCreationErrorFileCreationFinishedFileCreationProgressFileCreationStartedJobDequeuedJobEndJobEnqueuedJobErrorJobRequeuedJobRetryMaxReachedJobRunWorkerCreatedWorkerIsWaitingWorkerPickedJobWorkerShutdownWorkerStartedWorkerWokeUpOnCancellationRequestedOnCompletedAddingRequestedOnDirectoryCreatedOnDirectoryCreatingOnDirectoryCreationErrorOnFileCopyErrorOnFileCopyFinishedOnFileCopyProgressOnFileCopyStartedOnFileCreationErrorOnFileCreationFinishedOnFileCreationProgressOnFileCreationStartedOnJobDequeuedOnJobEndOnJobEnqueuedOnJobErrorOnJobRequeuedOnJobRetryMaxReachedOnJobRunOnWorkerCreatedOnWorkerIsWaitingOnWorkerPickedJobOnWorkerShutdownOnWorkerStartedOnWorkerWokeUp

save

reset

Drag to pan - Use Mousewheel + Ctrl to zoom