org.lastbamboo.common.download
Class RangeTrackerImpl

java.lang.Object
  extended by org.lastbamboo.common.download.RangeTrackerImpl
All Implemented Interfaces:
RangeTracker

public class RangeTrackerImpl
extends Object
implements RangeTracker

Class for keeping track of ranges for a single download. The algorithm for choosing a range size is important for making downloads as efficient as possible. A base


Constructor Summary
RangeTrackerImpl(long fileSize, int numSources)
          Creates a new range tracker for a file of the specified size.
RangeTrackerImpl(long fileSize, int numSources, RangeSizeSelector rangeSizeSelector)
          Creates a new range tracker for a file of the specified size.
 
Method Summary
 long getBytesRead()
          Accessor for the number of bytes read.
 org.littleshoot.util.Optional<org.apache.commons.lang.math.LongRange> getNextRange()
          Gets the next range to download.
 int getNumChunks()
          Accessor for the number of chunks to download.
 boolean hasMoreRanges()
          Returns whether or not there are available ranges to download.
 void onRangeComplete(org.apache.commons.lang.math.LongRange range)
          Called when we've completed downloading the specified range.
 void onRangeFailed(org.apache.commons.lang.math.LongRange range)
          Called when the attempt to download the specified range has failed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RangeTrackerImpl

public RangeTrackerImpl(long fileSize,
                        int numSources)
Creates a new range tracker for a file of the specified size.

Parameters:
fileSize - The size of the file we're downloading.
numSources - The number of sources for the download.

RangeTrackerImpl

public RangeTrackerImpl(long fileSize,
                        int numSources,
                        RangeSizeSelector rangeSizeSelector)
Creates a new range tracker for a file of the specified size.

Parameters:
fileSize - The size of the file we're downloading.
numSources - The number of sources for the download.
rangeSizeSelector - The class for selecting the size of ranges.
Method Detail

getNextRange

public org.littleshoot.util.Optional<org.apache.commons.lang.math.LongRange> getNextRange()
Description copied from interface: RangeTracker
Gets the next range to download. This will be the highest priorty range based on a range ranking that will typically preference the beginning of files for streaming but that will also add randomization to avoid many hosts missing the same pieces, particularly when sharing partial files.

Specified by:
getNextRange in interface RangeTracker
Returns:
The next range to download.

getNumChunks

public int getNumChunks()
Description copied from interface: RangeTracker
Accessor for the number of chunks to download.

Specified by:
getNumChunks in interface RangeTracker
Returns:
The number of chunks to download.

hasMoreRanges

public boolean hasMoreRanges()
Returns whether or not there are available ranges to download.

Specified by:
hasMoreRanges in interface RangeTracker
Returns:
true if there are more ranges to download, otherwise false.

onRangeComplete

public void onRangeComplete(org.apache.commons.lang.math.LongRange range)
Called when we've completed downloading the specified range.

Specified by:
onRangeComplete in interface RangeTracker
Parameters:
range - The completed range.

onRangeFailed

public void onRangeFailed(org.apache.commons.lang.math.LongRange range)
Called when the attempt to download the specified range has failed. This indicates the range should be added again to the queue of ranges to assign.

Specified by:
onRangeFailed in interface RangeTracker
Parameters:
range - The range that could not be downloaded.

getBytesRead

public long getBytesRead()
Description copied from interface: RangeTracker
Accessor for the number of bytes read.

Specified by:
getBytesRead in interface RangeTracker
Returns:
The number of bytes read.


Copyright © 2013 LittleShoot. All Rights Reserved.