jAudioFeatureExtractor
Class BatchExecutionThread

java.lang.Object
  extended by java.lang.Thread
      extended by jAudioFeatureExtractor.BatchExecutionThread
All Implemented Interfaces:
Updater, java.lang.Runnable

public class BatchExecutionThread
extends java.lang.Thread
implements Updater

GUI components that handles the execution of the feature extraction. The unusual structure is to get around the limitations of Swing - since swing is not thread safe, gui componenets can only operate from the main thread without race conditions. This means that either long running activities must execute on the main thread (making the system unresponsive) or fire updates on the main thread, potentially causing race conditions. This problem can be circumvented by pumping updates to the main event thread via small runnable objects (Geary 1999, 281-91). It works, but makes for obscure code with several inner or anonymous classes that encapsulate a message to the gui thread.

Geary, D. 1999. Graphic Java 2: Mastering the JFC. Palo Alto: Sun Microsystems.

Author:
Daniel McEnnis

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BatchExecutionThread(Controller controller, OuterFrame of)
          Creates a new thread.
 
Method Summary
 void announceUpdate(int fileDone)
          Called at periodic intervals during the execution of the code.
 void announceUpdate(int fileNumber, int fileDone)
          Called after each file executes
 void run()
          Executes a batch.
 void setFileLength(int windows)
          Informs the file progress bar on how many windows of data are present in this file.
 void setNumberOfFiles(int files)
          Informs the batch progress bar about many files are present in this batch.
 
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
 

Constructor Detail

BatchExecutionThread

public BatchExecutionThread(Controller controller,
                            OuterFrame of)
Creates a new thread. Prepares the thread for execution, creating each of the runnable objects that can be later inserted into the swing event queue.

Parameters:
controller - Near global object containing actions and model components.
of - Reference to the main frame so it can be disabled during execution - preventing modification to the system in mid run.
Method Detail

run

public void run()
Executes a batch. Executes in its own thread, communicating with the swing thread via runnable objects that are inserted into the swing thread. Acts as a controller in a classic MVC pattern (with the batches as model and the swing thread as view).

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

announceUpdate

public void announceUpdate(int fileNumber,
                           int fileDone)
Called after each file executes

Specified by:
announceUpdate in interface Updater
Parameters:
fileNumber - How many files are completed.
fileDone - Position in the file (usually 0).

announceUpdate

public void announceUpdate(int fileDone)
Called at periodic intervals during the execution of the code.

Specified by:
announceUpdate in interface Updater
Parameters:
fileDone - Position in file.

setNumberOfFiles

public void setNumberOfFiles(int files)
Informs the batch progress bar about many files are present in this batch.

Specified by:
setNumberOfFiles in interface Updater
Parameters:
files - Number of files to be processed.

setFileLength

public void setFileLength(int windows)
Informs the file progress bar on how many windows of data are present in this file.

Specified by:
setFileLength in interface Updater
Parameters:
windows - Total number of windows of data to be processed.