ecologylab.concurrent
Class DownloadMonitor<T extends Downloadable>

java.lang.Object
  extended by java.util.Observable
      extended by ecologylab.generic.ObservableDebug
          extended by ecologylab.concurrent.Monitor
              extended by ecologylab.concurrent.DownloadMonitor<T>
All Implemented Interfaces:
DownloadProcessor<T>

public class DownloadMonitor<T extends Downloadable>
extends Monitor
implements DownloadProcessor<T>

Non-linear flow multiplexer. Tracks downloads of Downloadable objects. Dispatches downloaded media to the appropriate DispatchTarget.

Looks out for timeout conditions. In case they happen, records state in the bad slot, and dispatches, as well.


Field Summary
static int HIGH_PRIORITY
           
static int HIGHER_PRIORITY
           
static int LOW_PRIORITY
           
static int MAX_WAIT_TIME
           
static int MID_PRIORITY
           
 
Constructor Summary
DownloadMonitor(java.lang.String name, int numDownloadThreads)
           
DownloadMonitor(java.lang.String name, int numDownloadThreads, int priorityBoost)
           
 
Method Summary
 void cancelDownload(Downloadable thatDownloadable)
          Cancel a download that has been queued, but not yet started.
 void clear()
          Stop performing downloads, and then Get rid of queued DownloadClosures.
 void download(T thatDownloadable, DispatchTarget<T> dispatchTarget)
          Entry point for Downloadables that want to be downloaded by 1 of our performDownload() threads.
 StatusReporter getStatus()
           
static NewPorterStemmer getStemmer()
           
 boolean highNumberWaiting()
           
 int highPriority()
           
 boolean isPaused()
           
 int lowPriority()
           
 boolean midNumberWaiting()
           
 int midPriority()
           
 void pause()
           
 void pause(boolean paused)
           
 int pending()
           
 void printQueue()
           
 void setHurry(boolean hurry)
           
 void setNoWait(boolean noWait)
          Set whether or not this download monitor needs to wait after each download attempt
 void setStatus(StatusReporter status)
           
 int size()
           
 void stop()
           
 void stop(boolean kill)
          Stop our threads.
 int toDownloadSize()
          check the number of elements in the toDownload Queue
 java.lang.String toString()
           
 void unpause()
           
 void waitIfTooManyPending()
           
 int waitingToDownload()
           
 
Methods inherited from class ecologylab.concurrent.Monitor
done, notify, notifyAll, wait, wait, waitForDone
 
Methods inherited from class ecologylab.generic.ObservableDebug
debug, debug, debugA, debugA, debugI, debugI, error, getClassName, print, println, println, println, show, superString
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HIGHER_PRIORITY

public static final int HIGHER_PRIORITY
See Also:
Constant Field Values

HIGH_PRIORITY

public static final int HIGH_PRIORITY
See Also:
Constant Field Values

MID_PRIORITY

public static final int MID_PRIORITY
See Also:
Constant Field Values

LOW_PRIORITY

public static final int LOW_PRIORITY
See Also:
Constant Field Values

MAX_WAIT_TIME

public static final int MAX_WAIT_TIME
See Also:
Constant Field Values
Constructor Detail

DownloadMonitor

public DownloadMonitor(java.lang.String name,
                       int numDownloadThreads)

DownloadMonitor

public DownloadMonitor(java.lang.String name,
                       int numDownloadThreads,
                       int priorityBoost)
Method Detail

download

public void download(T thatDownloadable,
                     DispatchTarget<T> dispatchTarget)
Entry point for Downloadables that want to be downloaded by 1 of our performDownload() threads. Starts the performDownload() threads, if necessary.

After performDownload() is called on the Downloadable, then in the normal case, downloadDone() is called, and then the DispatchTarget is called. In the error case, handleIOError() or handleTimeout() is called.

Specified by:
download in interface DownloadProcessor<T extends Downloadable>

cancelDownload

public void cancelDownload(Downloadable thatDownloadable)
Cancel a download that has been queued, but not yet started.

Parameters:
thatDownloadable -

pause

public void pause()

unpause

public void unpause()

pause

public void pause(boolean paused)

toString

public java.lang.String toString()
Overrides:
toString in class ObservableDebug

stop

public void stop()
Specified by:
stop in interface DownloadProcessor<T extends Downloadable>

stop

public void stop(boolean kill)
Stop our threads.


waitingToDownload

public int waitingToDownload()

highNumberWaiting

public boolean highNumberWaiting()
Returns:
true if we're backed up with unresloved downloads.

midNumberWaiting

public boolean midNumberWaiting()

lowPriority

public int lowPriority()

midPriority

public int midPriority()

highPriority

public int highPriority()

pending

public int pending()

setNoWait

public void setNoWait(boolean noWait)
Set whether or not this download monitor needs to wait after each download attempt

Parameters:
noWait -

setHurry

public void setHurry(boolean hurry)

getStemmer

public static NewPorterStemmer getStemmer()

toDownloadSize

public int toDownloadSize()
check the number of elements in the toDownload Queue

Returns:

clear

public void clear()
Stop performing downloads, and then Get rid of queued DownloadClosures.


waitIfTooManyPending

public void waitIfTooManyPending()

printQueue

public void printQueue()

getStatus

public StatusReporter getStatus()

setStatus

public void setStatus(StatusReporter status)

isPaused

public boolean isPaused()
Returns:
the paused

size

public int size()