core.background
Class BackgroundMonitor

java.lang.Object
  extended by java.lang.Thread
      extended by core.background.BackgroundMonitor
All Implemented Interfaces:
java.lang.Runnable

public class BackgroundMonitor
extends java.lang.Thread

The BackgroundMonitor class is used to start and stop a FolderWatcher instance. The class also sets listeners on the AllFiles object, and FolderWatcher instances through a Status interface to monitor progress and report it to the user.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int DEFAULT_SLEEP_TIME_HOURS
          The default time to check the directory is 1 hours.
static long DEFAULT_SLEEP_TIME_MILLISECS
          The default time to check the directory is 1 hour.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BackgroundMonitor()
          Creates a new BackgroundMonitor object with the default time delay.
BackgroundMonitor(int timeHoursDelay)
          Creates a new BackgroundMonitor object.
BackgroundMonitor(long timeDelay)
          Creates a new BackgroundMonitor object with the given time delay in milliseconds.
 
Method Summary
 void addBackgroundMonitorStatusListener(BackgroundMonitorStatusListener listener)
          Adds a new BackgroundMonitorStatusListener object to the background monitor object.
 java.util.Date getNextRunTime()
          Returns a Data object that details the next check for new tracks.
 int getTimeHoursDelay()
          Returns the amount of time in hours between checks for changed folders.
 boolean isRunning()
          Returns whether or not a new add tracks task will execute after the background monitor thread has finished sleeping.
 void removeBackgroundMonitorStatusListener(BackgroundMonitorStatusListener listener)
          Removes the listener from the BackgroundMonitor object.
 void run()
           
 void setStatus(Status status)
          Sets the status object the background monitor object should report status information to.
 void setTimeDelay(long delay)
          Sets the time delay to the given long value.
 void setTimeDelayHours(int hours)
          Sets the time delay to the given time in hours.
 void startBackgroundMonitor(java.util.ArrayList<java.io.File> filesToMonitor, int timeHoursDelay)
          Starts a new Folder Watcher instance given the constructor variables.
 void stopBackgroundMonitor()
          Stops the folder watcher instance if it is running.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_SLEEP_TIME_MILLISECS

public static final long DEFAULT_SLEEP_TIME_MILLISECS
The default time to check the directory is 1 hour. This value is 1 hour represented in milliseconds.

See Also:
Constant Field Values

DEFAULT_SLEEP_TIME_HOURS

public static final int DEFAULT_SLEEP_TIME_HOURS
The default time to check the directory is 1 hours.

See Also:
Constant Field Values
Constructor Detail

BackgroundMonitor

public BackgroundMonitor()
Creates a new BackgroundMonitor object with the default time delay. The background monitor thread is automatically started.


BackgroundMonitor

public BackgroundMonitor(int timeHoursDelay)
Creates a new BackgroundMonitor object. The status object must be initialized here with the setStatus method before starting or stopping a background monitor object. Otherwise NullPointerExceptions will be thrown.

Parameters:
timeHoursDelay - The time in hours to delay execution of searching for new tracks.

BackgroundMonitor

public BackgroundMonitor(long timeDelay)
Creates a new BackgroundMonitor object with the given time delay in milliseconds. The background monitor thread is automatically started within this constructor.

Parameters:
timeDelay - The amount of time between new track searches in milliseconds.
Method Detail

setTimeDelay

public void setTimeDelay(long delay)
Sets the time delay to the given long value.

Parameters:
delay - The amount of time between searches for new tracks in milliseconds.

setTimeDelayHours

public void setTimeDelayHours(int hours)
Sets the time delay to the given time in hours.

Parameters:
hours - The amount of time between searches for new tracks in hours.

setStatus

public void setStatus(Status status)
Sets the status object the background monitor object should report status information to.

Parameters:
status - The status object that the Background Monitor object will report status updates too. If the status object has not been initialized NullPointerExceptions will be thrown.

stopBackgroundMonitor

public void stopBackgroundMonitor()
Stops the folder watcher instance if it is running. The status instance and the system tray icon report the stopped folder watcher as well.


startBackgroundMonitor

public void startBackgroundMonitor(java.util.ArrayList<java.io.File> filesToMonitor,
                                   int timeHoursDelay)
Starts a new Folder Watcher instance given the constructor variables. The requisite listeners are also applied to the folder watcher instance.

Parameters:
filesToMonitor - The directories to monitor.
timeHoursDelay - The amount of time between checks for changed folders in hours.

isRunning

public boolean isRunning()
Returns whether or not a new add tracks task will execute after the background monitor thread has finished sleeping. In other words, the background thread is always running, but whether or not a new task to check for new files is created is determined by this boolean value.

Returns:
runATT If true, a new AddTracksTask object will be run when the BackgroundMonitor thread is finished sleeping.

getTimeHoursDelay

public int getTimeHoursDelay()
Returns the amount of time in hours between checks for changed folders.

Returns:
Returns the amount of time in hours between checks for changed folders.

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getNextRunTime

public java.util.Date getNextRunTime()
Returns a Data object that details the next check for new tracks.

Returns:
The date when the next background monitor add tracks task will be run. This is a rough estimate as the Thread simply sleeps until the next run time.

addBackgroundMonitorStatusListener

public void addBackgroundMonitorStatusListener(BackgroundMonitorStatusListener listener)
Adds a new BackgroundMonitorStatusListener object to the background monitor object.

Parameters:
listener - The listener to add to the background monitor object.

removeBackgroundMonitorStatusListener

public void removeBackgroundMonitorStatusListener(BackgroundMonitorStatusListener listener)
Removes the listener from the BackgroundMonitor object.

Parameters:
listener - The listener to remove from the BackgroundMonitor object.