Naanou.ResourceExchange
Class RangeGetter

Downloads a specific range of a file using multiple sources simulatenously

This class will attempt to `swarm' or multi-source download a given range. Each range has a specified list of sources available for it, and RangeGetter will randomly choose from among them to spread load. A range could be an entire file or some subset, so the class does not attempt to download it all at once. Instead, it will cut the range up into chunks, their size being the powers of two above 8 kilobytes. Which sized chunk that is attempted depends on the source. RangeGetter aims to fetch small chunks (say, 512KB) from slower hosts and larger chunks (upto 16MB) from faster hosts. This heuristic reduces unnecessary communication bandwidth if there was a set chunk size, and maximises the ability for slower hosts to participate fully in the resource exchanging. Multiple chunks are then transferred from sources simultaneously. When the process is over, RangeGetter signals via its completetion via the Naanou.ResourceExchange.RangeGetter.Complete event.

Field Summary
System.Collections.ArrayList blocksDownloaded
long bytesDownloaded
long bytesRequired
bool completed
Naanou.ResourceExchange.Downloader downloader
System.Exception error
System.Collections.ArrayList failedRanges
Naanou.ResourceExchange.RangeGetter.RangeGetterWorker internalWorker
         An internal worker that gets set by DownloadChunk
Naanou.ResourceExchange.WorkStatusArgs lastStatus
System.Collections.ArrayList miniPool
         Synchronised arraylist
Naanou.ResourceExchange.ByteRange originalRange
System.Random random
Naanou.ResourceExchange.ResourceAvailRange range
System.Threading.Thread thread
System.Collections.Hashtable workerStatus

Constructor Summary
RangeGetter(Naanou.ResourceExchange.Downloader downloader, Naanou.ResourceExchange.ResourceAvailRange range)
         Constructor

Property Summary
long BytesDownloaded
         Gets the number of bytes downloaded in this range
string Error
         Gets the error message if any
bool WereErrors
         Gets a value indicating if there were errors while running

Method Summary
void Abort()
         Aborts a get
void DownloadChunk(Naanou.ResourceExchange.Source.Manifest source, Naanou.ResourceExchange.ResourceAvailRange chunk)
         Downloads a chunk. Either spawns off work in new thread and is async, or does work in own thread and blocks until done.
void GetStats()
void GetStats(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
void Join()
         Waits for getter to complete
void Join(System.TimeSpan timeout)
         Waits a finite time for getter to complete
void OnWorkerComplete(Naanou.ResourceExchange.IWorker sender, Naanou.ResourceExchange.WorkCompleteArgs args)
         Notification by a worker it has completed (successfully or not)
void OnWorkerStatus(Naanou.ResourceExchange.IWorker worker, Naanou.ResourceExchange.WorkStatusArgs args)
void PaintStatus(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
         Paints status of range getter
void Start()
         Starts downloading (async)
void StartImpl()
void StartWrapper()
string ToString()
         Gets a string representation of range
void WaitForWorkers(bool abort)

Methods inherited from class System.Object
Equals, Finalize, GetHashCode, GetType, MemberwiseClone

Event Summary
Naanou.ResourceExchange.WorkCompleteHandler Complete
         Signal that the range has been downloaded, or all sources have been exhausted. Args contains an ArrayList of all blocks downloaded
Naanou.ResourceExchange.WorkStatusHandler Status
         Status


Field Detail

blocksDownloaded

private System.Collections.ArrayList blocksDownloaded


bytesDownloaded

private long bytesDownloaded


bytesRequired

private long bytesRequired


completed

private bool completed


downloader

private Naanou.ResourceExchange.Downloader downloader


error

private System.Exception error


failedRanges

private System.Collections.ArrayList failedRanges


internalWorker

private Naanou.ResourceExchange.RangeGetter.RangeGetterWorker internalWorker

An internal worker that gets set by DownloadChunk


lastStatus

private Naanou.ResourceExchange.WorkStatusArgs lastStatus


miniPool

private System.Collections.ArrayList miniPool

Synchronised arraylist


originalRange

private Naanou.ResourceExchange.ByteRange originalRange


random

private System.Random random


range

private Naanou.ResourceExchange.ResourceAvailRange range


thread

private System.Threading.Thread thread


workerStatus

private System.Collections.Hashtable workerStatus

Constructor Detail

RangeGetter

public RangeGetter(Naanou.ResourceExchange.Downloader downloader,
                   Naanou.ResourceExchange.ResourceAvailRange range)

Constructor

Parameters:
downloader - Downloader
range - Range to get
Property Detail

BytesDownloaded

public long BytesDownloaded

Gets the number of bytes downloaded in this range


Error

public string Error

Gets the error message if any


WereErrors

public bool WereErrors

Gets a value indicating if there were errors while running

Method Detail

Abort

public void Abort()

Aborts a get


DownloadChunk

private void DownloadChunk(Naanou.ResourceExchange.Source.Manifest source,
                           Naanou.ResourceExchange.ResourceAvailRange chunk)

Downloads a chunk. Either spawns off work in new thread and is async, or does work in own thread and blocks until done.

Parameters:
source - Source
chunk - Chunk

GetStats

private void GetStats()


GetStats

private void GetStats(System.Drawing.Graphics g,
                      System.Drawing.Rectangle rect)


Join

public void Join()

Waits for getter to complete


Join

public void Join(System.TimeSpan timeout)

Waits a finite time for getter to complete

Parameters:
timeout -

OnWorkerComplete

private void OnWorkerComplete(Naanou.ResourceExchange.IWorker sender,
                              Naanou.ResourceExchange.WorkCompleteArgs args)

Notification by a worker it has completed (successfully or not)

Parameters:
sender - Worker
args - Completion args

OnWorkerStatus

private void OnWorkerStatus(Naanou.ResourceExchange.IWorker worker,
                            Naanou.ResourceExchange.WorkStatusArgs args)


PaintStatus

public void PaintStatus(System.Drawing.Graphics g,
                        System.Drawing.Rectangle rect)

Paints status of range getter

Parameters:
g -
rect -

Start

public void Start()

Starts downloading (async)


StartImpl

private void StartImpl()


StartWrapper

private void StartWrapper()


ToString

public string ToString()

Gets a string representation of range

Returns:
String representation of range

WaitForWorkers

private void WaitForWorkers(bool abort)

Event Detail

Complete

public Naanou.ResourceExchange.WorkCompleteHandler Complete

Signal that the range has been downloaded, or all sources have been exhausted. Args contains an ArrayList of all blocks downloaded


Status

public Naanou.ResourceExchange.WorkStatusHandler Status

Status