org.lastbamboo.common.download
Class LaunchFileDispatcher

java.lang.Object
  extended by org.lastbamboo.common.download.LaunchFileDispatcher
All Implemented Interfaces:
LaunchFileTracker, org.littleshoot.util.LongRangeListener

public class LaunchFileDispatcher
extends Object
implements LaunchFileTracker

Class for dispatching file download events to all the open file launchers/streamers.


Constructor Summary
LaunchFileDispatcher(File incompleteFile, RandomAccessFile raf, int initialQueueSize, URI expectedSha1)
          Creates a new tracker for streaming the file to the browser.
 
Method Summary
 void addTracker(LaunchFileTracker tracker)
          For testing.
 int getActiveWriteCalls()
          Accessor for the number of active writers.
 Collection<org.apache.commons.lang.math.LongRange> getRanges()
          Used for testing.
 void onDownloadStopped()
          Called when a download is stopped.
 void onFailure()
          Called when a download fails for any reason.
 void onFileComplete()
          Called when the file download has completed.
 void onRangeComplete(org.apache.commons.lang.math.LongRange range)
           
 void waitForLaunchersToComplete()
          Waits until all active launcher have finished their writes, typically to the browser.
 void write(OutputStream os, boolean cancelOnStreamClose)
          Writes the file to the specified stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LaunchFileDispatcher

public LaunchFileDispatcher(File incompleteFile,
                            RandomAccessFile raf,
                            int initialQueueSize,
                            URI expectedSha1)
Creates a new tracker for streaming the file to the browser.

Parameters:
incompleteFile - The file on disk.
raf - The random access file to copy the downloaded data from.
initialQueueSize - The initial size of the queue, loosely based on number of chunks we're downloading.
expectedSha1 - The expected SHA-1 for the file.
Method Detail

waitForLaunchersToComplete

public void waitForLaunchersToComplete()
Description copied from interface: LaunchFileTracker
Waits until all active launcher have finished their writes, typically to the browser.

Specified by:
waitForLaunchersToComplete in interface LaunchFileTracker

write

public void write(OutputStream os,
                  boolean cancelOnStreamClose)
           throws IOException
Description copied from interface: LaunchFileTracker
Writes the file to the specified stream.

Specified by:
write in interface LaunchFileTracker
Parameters:
os - The stream to write to.
Throws:
IOException - If there's any read or write error writing to the stream.

onRangeComplete

public void onRangeComplete(org.apache.commons.lang.math.LongRange range)
Specified by:
onRangeComplete in interface org.littleshoot.util.LongRangeListener

getRanges

public Collection<org.apache.commons.lang.math.LongRange> getRanges()
Used for testing.

Returns:
The available ranges.

addTracker

public void addTracker(LaunchFileTracker tracker)
For testing.

Parameters:
tracker - The tracker.

onFileComplete

public void onFileComplete()
Description copied from interface: LaunchFileTracker
Called when the file download has completed.

Specified by:
onFileComplete in interface LaunchFileTracker

getActiveWriteCalls

public int getActiveWriteCalls()
Description copied from interface: LaunchFileTracker
Accessor for the number of active writers.

Specified by:
getActiveWriteCalls in interface LaunchFileTracker
Returns:
The number of active writers.

onFailure

public void onFailure()
Description copied from interface: LaunchFileTracker
Called when a download fails for any reason.

Specified by:
onFailure in interface LaunchFileTracker

onDownloadStopped

public void onDownloadStopped()
Description copied from interface: LaunchFileTracker
Called when a download is stopped.

Specified by:
onDownloadStopped in interface LaunchFileTracker


Copyright © 2013 LittleShoot. All Rights Reserved.