edu.jhu.ece.iacl.jist.pipeline
Class ExecutionContext

java.lang.Object
  extended by edu.jhu.ece.iacl.jist.pipeline.ExecutionContext
All Implemented Interfaces:
java.lang.Comparable<ExecutionContext>, java.lang.Runnable

public class ExecutionContext
extends java.lang.Object
implements java.lang.Runnable, java.lang.Comparable<ExecutionContext>

An Execution Context provides threaded execution of a processing algorithm with a specified set of input parameters.

Author:
Blake Lucas

Nested Class Summary
static interface ExecutionContext.ContextListener
          Listener to monitor for updates to an execution context.
protected  class ExecutionContext.ProcessStatusParser
          The Class ProcessStatusParser.
static class ExecutionContext.Status
          The Enum Status.
static class ExecutionContext.Update
          The Enum Update.
 
Field Summary
protected  long actualTime
          Elapsed actual time in milliseconds.
protected  PipeAlgorithm algo
          Algorithm associated with this context.
protected  java.io.File algoRoot
          Root directory for algorithm.
protected  int allocatedMemory
          Allocated memory in MB.
protected  javax.swing.tree.DefaultMutableTreeNode ancestorTop
          Root node for ancestors.
protected  javax.swing.JTree ancestorTree
          Tree representing context ancestors.
protected  ParamCollection cachedInputParams
          Cached parameters to compare against when checking for changes.
protected  java.util.Vector<ExecutionContext> callers
          Execution contexts that forward to this context.
static java.lang.String classpath
          Java class path.
protected  java.lang.String contextId
          Identifying experiment number.
protected  java.lang.String contextName
          The context name.
protected  long cpuTime
          Elapsed cpu time in milliseconds.
protected  java.util.Vector<ExecutionContext> dependents
          Execution contexts that are dependent on the output from this context.
protected  javax.swing.tree.DefaultMutableTreeNode descendantTop
          Root node for descendants.
protected  javax.swing.JTree descendantTree
          Tree representing context descendants.
protected  java.io.File inputFile
          The input file.
protected  ParamCollection inputParams
          The input parameters.
protected  PipeLayout layout
          Layout process associated with this context.
protected  boolean outOfSync
          Out of sync flag.
protected  ParamCollection outputParams
          The output parameters.
protected  int priority
          The execution priority.
protected  java.lang.Process proc
          Running process.
protected  java.lang.Process process
          Running process.
protected  boolean runningFlag
          Flag indicating the thread is running.
protected  int scenarioId
          Identifying scenario number.
protected  java.io.File scenarioRoot
          Root directory for scenario.
protected  javax.swing.JProgressBar statusBar
          progress bar to monitor execution status.
protected  java.lang.Thread th
          Running thread.
protected static java.lang.Object treeGraphLock
          The Constant treeGraphLock.
protected  int usedMemory
          Used memory in MB.
 
Constructor Summary
ExecutionContext(int scenario, java.lang.String context, PipeLayout layout, PipeAlgorithm algo)
          Construct a new execution context.
 
Method Summary
 void addChild(ExecutionContext mod)
          Add child execution context that pulls data from this context.
 void addContextListener(ExecutionContext.ContextListener listener)
          Add context listener.
 void addParent(ExecutionContext mod)
          Add parent execution context that pushes data to this context.
protected  boolean checkInSync()
          Check if two input files are in sync.
 void clean()
          Remove the output directory and anything in it.
 int compareTo(ExecutionContext context)
          Compare execution contexts by status for sorting purposes.
 void createTreeNodes(javax.swing.event.TreeSelectionListener listener)
          Create ancestor and descendant tree and set the listener for those trees.
static boolean deleteDir(java.io.File dir, javax.swing.ProgressMonitor monitor)
          Delete all contents in a directory.
 void demote()
          Decrease context queue priority.
 boolean equals(java.lang.Object obj)
          Check if contexts are equal by comparing context names.
 long getActualTime()
          Gets the actual time.
 PipeAlgorithm getAlgorithm()
          Get algorithm.
 int getAllocatedMemory()
          Get amount of allocated memory.
 javax.swing.JTree getAncestorTree()
          Get ancestor tree.
 java.util.Vector<ExecutionContext> getCallers()
          Get contexts that call this context.
 java.lang.String getContextId()
          Get context id.
 ParamCollection getContextInputParams()
          Get context input parameters.
 java.lang.String getContextName()
          Get context name.
 java.lang.String getContextShortName()
          Get context name.
 long getCpuTime()
          Gets the cpu time.
 java.util.Vector<ExecutionContext> getDependents()
          Get contexts that depend on this context.
 javax.swing.JTree getDescendantTree()
          Get descendant tree.
 java.lang.String getElapsedTimeDescription()
          Get elapsed cpu time in milliseconds.
 java.lang.String getHashKey()
          Gets the hash key.
static java.lang.String getHashKey(java.lang.String label, java.lang.Class c, ParamCollection currentParams)
          Gets the hash key.
protected  javax.swing.tree.TreePath getInitPath(javax.swing.tree.TreeNode node)
          Get initial tree path by finding first child element.
 java.io.File getInputLocation()
          Get directory where input parameters are located.
 ParamCollection getInputParamsFromFile()
          Load parameters from file.
 PipeLayout getLayout()
          Get layout owner.
 java.io.File getOutputLocation()
          Get directory where output will be placed.
 ParamCollection getOutputParamsFromFile()
          Load output parameters from file.
 int getPriority()
          Get priority.
 java.lang.Process getProcess()
          Get running process.
 int getScenarioId()
          Get scenario id.
 ExecutionContext.Status getStatus()
          Get execution status.
 javax.swing.JProgressBar getStatusBar()
          Get progress bar.
 int getUsedMemory()
          Get used memory.
protected  boolean isCompleted()
          Check if algorithm has completed by checking if the output file exists.
 boolean isOutOfSync()
          Return true if file is out of sync.
protected  boolean isReady()
          Check if algorithm is ready to run by validating the input parameters for this context that are read from an input file.
protected  boolean loadContextInputParams()
          Copy parameters for this context into pipe graph.
protected  boolean loadContextOutputParams()
          Copy output parameters from this context into pipe graph.
protected  boolean loadLayoutInputParams()
          Copy parameters from the pipe graph into this context.
 void notifyListeners(ExecutionContext.Update type)
          Notify listeners of change.
 void promote()
          Increase context queue priority.
 boolean push()
          Push output parameters to input parameters.
 void removeAllContextListeners()
          Remove all context listeners.
 void removeListener(ExecutionContext.ContextListener listener)
          Remove context listener.
 void reset()
          Reset status for context.
 void resetStatus()
          Reset status for this contexts and its dependents.
 void restart()
          Restart algorithm by stopping, cleaning, and then starting the algorithm.
 void run()
          Thread method for running the algorithm.
protected  java.io.File saveInputContext()
          Save input parameters to file.
 void setActualTime(long actualTime)
          Set elapsed actual time in milliseconds.
 void setAlgorithm(PipeAlgorithm module)
          Set algorithm.
 void setAllocatedMemory(int totalMemory)
          Set amount of allocated memory.
 void setContextId(java.lang.String contextId)
          Set context id.
 void setCpuTime(long cpuTime)
          Set elapsed cpu time in milliseconds.
 void setLayout(PipeLayout layout)
          Set layout owner.
 void setPriority(int priority)
          Set execution priority.
 void setProcess(java.lang.Process proc)
          Set running process.
 void setScenarioId(int scenarioId)
          Set scenario id.
 void setStatus(ExecutionContext.Status status)
          Set status for context.
 void setUsedMemory(int usedMemory)
          Set used memory.
 void start()
          Start running the algorithm.
 void stop()
          Force algorithm to stop running.
protected  boolean synchronizedPush()
          Push data from output parameters into child contexts.
 java.lang.String toString()
          Get context name and algorithm label.
protected  void updateAllTreeNodes()
          Update all tree nodes for all callers and dependents.
 ExecutionContext.Status updateStatus()
          Update the status of this context by checking if algorithm is ready and completed.
protected  void updateTreeNodes()
          Update tree nodes if ancestors or descendants change.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

classpath

public static final java.lang.String classpath
Java class path.


statusBar

protected javax.swing.JProgressBar statusBar
progress bar to monitor execution status.


cpuTime

protected long cpuTime
Elapsed cpu time in milliseconds.


actualTime

protected long actualTime
Elapsed actual time in milliseconds.


usedMemory

protected int usedMemory
Used memory in MB.


allocatedMemory

protected int allocatedMemory
Allocated memory in MB.


proc

protected java.lang.Process proc
Running process.


layout

protected PipeLayout layout
Layout process associated with this context.


algo

protected PipeAlgorithm algo
Algorithm associated with this context.


contextName

protected java.lang.String contextName
The context name.


inputFile

protected java.io.File inputFile
The input file.


inputParams

protected ParamCollection inputParams
The input parameters.


cachedInputParams

protected ParamCollection cachedInputParams
Cached parameters to compare against when checking for changes.


outputParams

protected ParamCollection outputParams
The output parameters.


callers

protected java.util.Vector<ExecutionContext> callers
Execution contexts that forward to this context.


dependents

protected java.util.Vector<ExecutionContext> dependents
Execution contexts that are dependent on the output from this context.


scenarioId

protected int scenarioId
Identifying scenario number.


contextId

protected java.lang.String contextId
Identifying experiment number.


process

protected java.lang.Process process
Running process.


scenarioRoot

protected java.io.File scenarioRoot
Root directory for scenario.


algoRoot

protected java.io.File algoRoot
Root directory for algorithm.


runningFlag

protected boolean runningFlag
Flag indicating the thread is running.


th

protected java.lang.Thread th
Running thread.


treeGraphLock

protected static final java.lang.Object treeGraphLock
The Constant treeGraphLock.


ancestorTree

protected javax.swing.JTree ancestorTree
Tree representing context ancestors.


descendantTree

protected javax.swing.JTree descendantTree
Tree representing context descendants.


ancestorTop

protected javax.swing.tree.DefaultMutableTreeNode ancestorTop
Root node for ancestors.


descendantTop

protected javax.swing.tree.DefaultMutableTreeNode descendantTop
Root node for descendants.


priority

protected int priority
The execution priority.


outOfSync

protected boolean outOfSync
Out of sync flag.

Constructor Detail

ExecutionContext

public ExecutionContext(int scenario,
                        java.lang.String context,
                        PipeLayout layout,
                        PipeAlgorithm algo)
Construct a new execution context. The combination of scenario and context id should be unique

Parameters:
scenario - scenario id
context - context id
layout - graph layout associated with this context
algo - pipe algorithm associated with this context
Method Detail

deleteDir

public static boolean deleteDir(java.io.File dir,
                                javax.swing.ProgressMonitor monitor)
Delete all contents in a directory.

Parameters:
dir - directory
monitor - the monitor
Returns:
true if delete successful

addChild

public void addChild(ExecutionContext mod)
Add child execution context that pulls data from this context.

Parameters:
mod - the execution context (sync on tree)

addContextListener

public void addContextListener(ExecutionContext.ContextListener listener)
Add context listener.

Parameters:
listener - listener

addParent

public void addParent(ExecutionContext mod)
Add parent execution context that pushes data to this context.

Parameters:
mod - the execution context

clean

public void clean()
Remove the output directory and anything in it. Reset status for context.


reset

public void reset()
Reset status for context.


compareTo

public int compareTo(ExecutionContext context)
Compare execution contexts by status for sorting purposes.

Specified by:
compareTo in interface java.lang.Comparable<ExecutionContext>
Parameters:
context - the execution context
Returns:
the indicator

createTreeNodes

public void createTreeNodes(javax.swing.event.TreeSelectionListener listener)
Create ancestor and descendant tree and set the listener for those trees.

Parameters:
listener - tree event listener (sync tree)

demote

public void demote()
Decrease context queue priority.


equals

public boolean equals(java.lang.Object obj)
Check if contexts are equal by comparing context names.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the execution context
Returns:
true, if equals

getAlgorithm

public PipeAlgorithm getAlgorithm()
Get algorithm.

Returns:
algorithm

getAllocatedMemory

public int getAllocatedMemory()
Get amount of allocated memory.

Returns:
the allocated memory

getAncestorTree

public javax.swing.JTree getAncestorTree()
Get ancestor tree.

Returns:
ancestor tree

getCallers

public java.util.Vector<ExecutionContext> getCallers()
Get contexts that call this context.

Returns:
contexts (copy)

getContextId

public java.lang.String getContextId()
Get context id.

Returns:
id

getContextInputParams

public ParamCollection getContextInputParams()
Get context input parameters.

Returns:
input parameters

getContextName

public java.lang.String getContextName()
Get context name.

Returns:
context name

getContextShortName

public java.lang.String getContextShortName()
Get context name.

Returns:
context name

getElapsedTimeDescription

public java.lang.String getElapsedTimeDescription()
Get elapsed cpu time in milliseconds.

Returns:
cpu time

getDependents

public java.util.Vector<ExecutionContext> getDependents()
Get contexts that depend on this context.

Returns:
contexts (copy)

getDescendantTree

public javax.swing.JTree getDescendantTree()
Get descendant tree.

Returns:
descendant tree

getInitPath

protected javax.swing.tree.TreePath getInitPath(javax.swing.tree.TreeNode node)
Get initial tree path by finding first child element.

Parameters:
node - root tree node
Returns:
get tree path

getInputLocation

public java.io.File getInputLocation()
Get directory where input parameters are located.

Returns:
input directory

getInputParamsFromFile

public ParamCollection getInputParamsFromFile()
Load parameters from file.

Returns:
the input parameters from file

getLayout

public PipeLayout getLayout()
Get layout owner.

Returns:
layout

getOutputLocation

public java.io.File getOutputLocation()
Get directory where output will be placed.

Returns:
directory

getOutputParamsFromFile

public ParamCollection getOutputParamsFromFile()
Load output parameters from file.

Returns:
output parameters

getPriority

public int getPriority()
Get priority.

Returns:
priority

getProcess

public java.lang.Process getProcess()
Get running process.

Returns:
process

getScenarioId

public int getScenarioId()
Get scenario id.

Returns:
scenario id

getStatus

public ExecutionContext.Status getStatus()
Get execution status.

Returns:
status

getStatusBar

public javax.swing.JProgressBar getStatusBar()
Get progress bar.

Returns:
progress bar

getUsedMemory

public int getUsedMemory()
Get used memory.

Returns:
used memory

isCompleted

protected boolean isCompleted()
Check if algorithm has completed by checking if the output file exists.

Returns:
true if completed

checkInSync

protected boolean checkInSync()
Check if two input files are in sync.

Returns:
true, if check in sync

isOutOfSync

public boolean isOutOfSync()
Return true if file is out of sync.

Returns:
true, if checks if is out of sync

isReady

protected boolean isReady()
Check if algorithm is ready to run by validating the input parameters for this context that are read from an input file.

Returns:
true, if checks if is ready

loadContextInputParams

protected boolean loadContextInputParams()
Copy parameters for this context into pipe graph.

Returns:
true, if load context input params

loadContextOutputParams

protected boolean loadContextOutputParams()
Copy output parameters from this context into pipe graph.

Returns:
true if context output parameters loaded without error

loadLayoutInputParams

protected boolean loadLayoutInputParams()
Copy parameters from the pipe graph into this context.

Returns:
true, if load layout input params

notifyListeners

public void notifyListeners(ExecutionContext.Update type)
Notify listeners of change.

Parameters:
type - type of change

promote

public void promote()
Increase context queue priority.


push

public boolean push()
Push output parameters to input parameters.

Returns:
true if push succeeded

removeAllContextListeners

public void removeAllContextListeners()
Remove all context listeners.


removeListener

public void removeListener(ExecutionContext.ContextListener listener)
Remove context listener.

Parameters:
listener - listener

resetStatus

public void resetStatus()
Reset status for this contexts and its dependents.


restart

public void restart()
Restart algorithm by stopping, cleaning, and then starting the algorithm.


run

public void run()
Thread method for running the algorithm.

Specified by:
run in interface java.lang.Runnable

saveInputContext

protected java.io.File saveInputContext()
Save input parameters to file.

Returns:
input file that was saved

setAlgorithm

public void setAlgorithm(PipeAlgorithm module)
Set algorithm.

Parameters:
module - algorithm

setAllocatedMemory

public void setAllocatedMemory(int totalMemory)
Set amount of allocated memory.

Parameters:
totalMemory - the total memory

setContextId

public void setContextId(java.lang.String contextId)
Set context id.

Parameters:
contextId - context id

setCpuTime

public void setCpuTime(long cpuTime)
Set elapsed cpu time in milliseconds.

Parameters:
cpuTime - time

setActualTime

public void setActualTime(long actualTime)
Set elapsed actual time in milliseconds.

Parameters:
actualTime - time

getCpuTime

public long getCpuTime()
Gets the cpu time.

Returns:
the cpu time

getActualTime

public long getActualTime()
Gets the actual time.

Returns:
the actual time

setLayout

public void setLayout(PipeLayout layout)
Set layout owner.

Parameters:
layout - layout owner

setPriority

public void setPriority(int priority)
Set execution priority.

Parameters:
priority - priority

setProcess

public void setProcess(java.lang.Process proc)
Set running process.

Parameters:
proc - process

setScenarioId

public void setScenarioId(int scenarioId)
Set scenario id.

Parameters:
scenarioId - scenario id

setStatus

public void setStatus(ExecutionContext.Status status)
Set status for context. If algorithm is completed, push data from output to child inputs

Parameters:
status - the status

setUsedMemory

public void setUsedMemory(int usedMemory)
Set used memory.

Parameters:
usedMemory - used memory

start

public void start()
Start running the algorithm.


stop

public void stop()
Force algorithm to stop running.


synchronizedPush

protected boolean synchronizedPush()
Push data from output parameters into child contexts.

Returns:
true if parameters pushed without error

toString

public java.lang.String toString()
Get context name and algorithm label.

Overrides:
toString in class java.lang.Object
Returns:
the string

updateAllTreeNodes

protected void updateAllTreeNodes()
Update all tree nodes for all callers and dependents.


updateStatus

public ExecutionContext.Status updateStatus()
Update the status of this context by checking if algorithm is ready and completed.

Returns:
current status

updateTreeNodes

protected void updateTreeNodes()
Update tree nodes if ancestors or descendants change.


getHashKey

public java.lang.String getHashKey()
Gets the hash key.

Returns:
the hash key

getHashKey

public static java.lang.String getHashKey(java.lang.String label,
                                          java.lang.Class c,
                                          ParamCollection currentParams)
Gets the hash key.

Parameters:
label - the label
c - the c
currentParams - the current params
Returns:
the hash key