|
.NET Framework | |||||||||
PREV TYPE NEXT TYPE | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONST | PROP | METHOD | OP | EVENT | DETAIL: FIELD | CONST | PROP | METHOD | OP | EVENT |
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 |
---|
private System.Collections.ArrayList blocksDownloaded
private long bytesDownloaded
private long bytesRequired
private bool completed
private Naanou.ResourceExchange.Downloader downloader
private System.Exception error
private System.Collections.ArrayList failedRanges
private Naanou.ResourceExchange.RangeGetter.RangeGetterWorker internalWorker
An internal worker that gets set by DownloadChunk
private Naanou.ResourceExchange.WorkStatusArgs lastStatus
private System.Collections.ArrayList miniPool
Synchronised arraylist
private Naanou.ResourceExchange.ByteRange originalRange
private System.Random random
private Naanou.ResourceExchange.ResourceAvailRange range
private System.Threading.Thread thread
private System.Collections.Hashtable workerStatus
Constructor Detail |
---|
public RangeGetter(Naanou.ResourceExchange.Downloader downloader, Naanou.ResourceExchange.ResourceAvailRange range)
Constructor
Parameters:
downloader
- Downloaderrange
- Range to getProperty Detail |
---|
public long BytesDownloaded
Gets the number of bytes downloaded in this range
public string Error
Gets the error message if any
public bool WereErrors
Gets a value indicating if there were errors while running
Method Detail |
---|
public void Abort()
Aborts a get
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
- Sourcechunk
- Chunkprivate void GetStats()
private void GetStats(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
public void Join()
Waits for getter to complete
public void Join(System.TimeSpan timeout)
Waits a finite time for getter to complete
Parameters:
timeout
- private void OnWorkerComplete(Naanou.ResourceExchange.IWorker sender, Naanou.ResourceExchange.WorkCompleteArgs args)
Notification by a worker it has completed (successfully or not)
Parameters:
sender
- Workerargs
- Completion argsprivate void OnWorkerStatus(Naanou.ResourceExchange.IWorker worker, Naanou.ResourceExchange.WorkStatusArgs args)
public void PaintStatus(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
Paints status of range getter
Parameters:
g
- rect
- public void Start()
Starts downloading (async)
private void StartImpl()
private void StartWrapper()
public string ToString()
Gets a string representation of range
Returns:
private void WaitForWorkers(bool abort)
Event Detail |
---|
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
public Naanou.ResourceExchange.WorkStatusHandler Status
Status
|
.NET Framework | |||||||||
PREV TYPE NEXT TYPE | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONST | PROP | METHOD | OP | EVENT | DETAIL: FIELD | CONST | PROP | METHOD | OP | EVENT |