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

java.lang.Object
  extended by edu.jhu.ece.iacl.jist.pipeline.PipeScheduler
All Implemented Interfaces:
ExecutionContext.ContextListener, java.lang.Runnable

public class PipeScheduler
extends java.lang.Object
implements java.lang.Runnable, ExecutionContext.ContextListener

Pipe scheduler creates and schedules the execution of execution contexts.

Author:
Blake Lucas

Nested Class Summary
protected  class PipeScheduler.CleanAllDialog
          The Class CleanAllDialog.
protected  class PipeScheduler.DestinationProcessor
          The Class DestinationProcessor.
 
Field Summary
protected  boolean completed
          indicate that scheduler has completed running and processing destinations.
protected  java.util.LinkedList<ExecutionContext> completedQueue
          Queue to store completed contexts.
protected  java.util.Vector<java.util.Vector<ExecutionContext>> contextTable
          Table of dependent contexts for each scheduled context.
protected  java.util.Vector<PipeDestination> dests
          List of all destinations.
protected  int initializedCount
          Counter to indicate the number of initialized experiments.
protected  boolean initializing
          Flag indicating the scheduler is initializing.
protected  PipeLayout layout
          pipeline layout to schedule.
protected  int pauseCount
          The pause count.
protected  boolean refreshQueuesLock
          Semaphore for locking queue.
protected  boolean requestTreeUpdate
          Flag indicating a request to update input/output information about the experiments.
protected  boolean runningFlag
          Flag indicates the scheduler is running.
protected  java.util.LinkedList<ExecutionContext> runningQueue
          Queue to store contexts that are currently running.
protected  java.util.LinkedList<ExecutionContext> schedule
          List storing all contexts.
protected  java.util.Vector<PipeSource> srcRoots
          List of all source roots.
protected  boolean stopped
          Flag indicating a request to stop the running process.
protected  java.lang.Thread th
          Thread for running a process.
protected  java.lang.Object thLock
          The th lock.
protected  boolean useWorker
          Use worker to process destination.
protected  java.lang.String uuid
          Global ID.
protected  java.util.Vector<ExecutionContext> waitingQueue
          Queue to store contexts that are waiting to run.
protected  java.util.HashMap waitingQueueHash
          The waiting queue hash.
 
Constructor Summary
PipeScheduler(PipeLayout layout, ProcessManager parentFrame)
          Constructor.
 
Method Summary
protected  void addDependencyContexts(java.util.Vector<PipeAlgorithm> algoRoots, int iter)
          Create dependent contexts for specified parent contexts.
 void clean(java.util.Vector<ExecutionContext> contexts, boolean forceRemoveLock)
          Clean output directory for specified contexts.
 void cleanAll()
          Clean all experiments in output directory
 void cleanAll(boolean quiet)
           
 void contextUpdate(ExecutionContext context, ExecutionContext.Update type)
          Update queues if a context's status changes.
protected  ExecutionContext createNewContext(PipeAlgorithm algo, int iter)
          Create new context for specific algorithm.
 java.lang.String createUniqueName(ExecutionContext parentContext)
          Create unique name for specified context.
 void demote(java.util.Vector<ExecutionContext> contexts)
          Demote position of processes in queue.
protected  ExecutionContext dequeue()
          Remove and process context in waiting queue.
 void dispose()
          Dispose of scheduler by killing all current processes.
protected  ExecutionContext doesScenarioExist(PipeAlgorithm algo)
          Find existing context with the same parameters as the algorithm module if one exists.
 void enqueue()
          Enqueue all waiting processes.
 void enqueue(java.util.Vector<ExecutionContext> contexts)
          Enqueue processes in queue.
 int getCompletedCount()
          Get the number of completed experiments.
 long getElapsedActualTime()
          Gets the elapsed actual time.
 long getElapsedCpuTime()
          Gets the elapsed cpu time.
 int getFailedCount()
          Get number of failed experiments.
 int getInitializedCount()
          Get the total number of initialized experiments.
 int getNotReadyCount()
          Get number of experiments that are not ready to run.
 int getQueuedCount()
          Get number of queued waiting to run experiments.
 int getQueuePosition(ExecutionContext context)
          Return queue position based on status and priority.
 int getReadyCount()
          Get number of experiments that are ready to run.
 int getRunningCount()
          Get number of running experiments.
 java.util.LinkedList<ExecutionContext> getRunningQueue()
          Get running queue for the scheduler.
 java.lang.String getUUID()
          Gets the uUID.
 int getWaitingCount()
          Get number of waiting to run experiments.
protected  boolean hasNext()
          Returns true if sources have move elements.
 boolean hasRunningQueue()
          Checks for running queue.
 void init()
          Generate list of contexts parsed on sources.
protected  void insertIntoProperQueue(ExecutionContext context)
          Insert experiment into proper queue based on experiment status.
 boolean isCompleted()
          Checks if is completed.
 boolean isInitializing()
          Indicates the scheduler is initializing.
 boolean isRunning()
          Indicates that the scheduler is running.
 boolean isUsingWorker()
          Checks if is using worker.
protected  boolean iterate(java.util.Vector<PipeSource> srcRoots)
          Iterate through all values for sources.
 void killAll()
          Kill all running processes.
 void pause()
          Pausing the scheduler will prevent new execution contexts from starting or completing.
 void processDestinations()
          Process all destinations for this scheduler.
 void promote(java.util.Vector<ExecutionContext> contexts)
          Promote position of processes in queue.
protected  void refreshQueues()
          Refresh queues based on current status of context.
 void restart(java.util.Vector<ExecutionContext> contexts)
          Restart specified contexts.
 void resume()
          Resume the scheduler.
 void run()
          Schedule and run all experiments.
 void run(java.util.Vector<ExecutionContext> contexts)
          Enqueue and run processes.
 void setOverrideRunOutOfProcess(boolean val)
           
 void setUseWorker(boolean useWorker)
          Sets the use worker.
 void start()
          Start scheduler thread.
 void stop()
          Stop scheduler thread.
 void stop(java.util.Vector<ExecutionContext> contexts)
          Stop running specified contexts.
 void updateManagerTable()
          Update table describing.
protected  void useExistingContext(ExecutionContext c)
          Load existing context into graph instead of creating a new one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

layout

protected PipeLayout layout
pipeline layout to schedule.


waitingQueue

protected java.util.Vector<ExecutionContext> waitingQueue
Queue to store contexts that are waiting to run.


waitingQueueHash

protected java.util.HashMap waitingQueueHash
The waiting queue hash.


runningQueue

protected java.util.LinkedList<ExecutionContext> runningQueue
Queue to store contexts that are currently running.


completedQueue

protected java.util.LinkedList<ExecutionContext> completedQueue
Queue to store completed contexts.


schedule

protected java.util.LinkedList<ExecutionContext> schedule
List storing all contexts.


refreshQueuesLock

protected boolean refreshQueuesLock
Semaphore for locking queue.


th

protected java.lang.Thread th
Thread for running a process.


thLock

protected java.lang.Object thLock
The th lock.


contextTable

protected java.util.Vector<java.util.Vector<ExecutionContext>> contextTable
Table of dependent contexts for each scheduled context.


stopped

protected boolean stopped
Flag indicating a request to stop the running process.


pauseCount

protected int pauseCount
The pause count.


requestTreeUpdate

protected boolean requestTreeUpdate
Flag indicating a request to update input/output information about the experiments.


initializing

protected boolean initializing
Flag indicating the scheduler is initializing.


initializedCount

protected int initializedCount
Counter to indicate the number of initialized experiments.


runningFlag

protected boolean runningFlag
Flag indicates the scheduler is running.


srcRoots

protected java.util.Vector<PipeSource> srcRoots
List of all source roots.


dests

protected java.util.Vector<PipeDestination> dests
List of all destinations.


useWorker

protected boolean useWorker
Use worker to process destination.


completed

protected boolean completed
indicate that scheduler has completed running and processing destinations.


uuid

protected java.lang.String uuid
Global ID.

Constructor Detail

PipeScheduler

public PipeScheduler(PipeLayout layout,
                     ProcessManager parentFrame)
Constructor.

Parameters:
layout - Layout to schedule
parentFrame - Parent frame that monitors scheduler
Method Detail

isUsingWorker

public boolean isUsingWorker()
Checks if is using worker.

Returns:
true, if is using worker

setUseWorker

public void setUseWorker(boolean useWorker)
Sets the use worker.

Parameters:
useWorker - the new use worker

setOverrideRunOutOfProcess

public void setOverrideRunOutOfProcess(boolean val)

getUUID

public java.lang.String getUUID()
Gets the uUID.

Returns:
the uUID

addDependencyContexts

protected void addDependencyContexts(java.util.Vector<PipeAlgorithm> algoRoots,
                                     int iter)
Create dependent contexts for specified parent contexts.

Parameters:
algoRoots - parent contexts
iter - the iteration

clean

public void clean(java.util.Vector<ExecutionContext> contexts,
                  boolean forceRemoveLock)
Clean output directory for specified contexts.

Parameters:
contexts - the contexts
forceRemoveLock - the force remove lock

cleanAll

public void cleanAll()
Clean all experiments in output directory


cleanAll

public void cleanAll(boolean quiet)

contextUpdate

public void contextUpdate(ExecutionContext context,
                          ExecutionContext.Update type)
Update queues if a context's status changes.

Specified by:
contextUpdate in interface ExecutionContext.ContextListener
Parameters:
context - the context
type - the type

createNewContext

protected ExecutionContext createNewContext(PipeAlgorithm algo,
                                            int iter)
Create new context for specific algorithm.

Parameters:
algo - algorithm
iter - experiment number id
Returns:
new execution context

createUniqueName

public java.lang.String createUniqueName(ExecutionContext parentContext)
Create unique name for specified context. It is necessary that contexts have a unique name.

Parameters:
parentContext - parent context
Returns:
the string

demote

public void demote(java.util.Vector<ExecutionContext> contexts)
Demote position of processes in queue.

Parameters:
contexts - the contexts

dequeue

protected ExecutionContext dequeue()
Remove and process context in waiting queue.

Returns:
the execution context

dispose

public void dispose()
Dispose of scheduler by killing all current processes.


doesScenarioExist

protected ExecutionContext doesScenarioExist(PipeAlgorithm algo)
Find existing context with the same parameters as the algorithm module if one exists.

Parameters:
algo - Algorithm module
Returns:
Existing context

enqueue

public void enqueue()
Enqueue all waiting processes.


enqueue

public void enqueue(java.util.Vector<ExecutionContext> contexts)
Enqueue processes in queue.

Parameters:
contexts - the contexts

getCompletedCount

public int getCompletedCount()
Get the number of completed experiments.

Returns:
number of completed experiments

getFailedCount

public int getFailedCount()
Get number of failed experiments.

Returns:
number of failed experiments

getInitializedCount

public int getInitializedCount()
Get the total number of initialized experiments.

Returns:
number of contexts

getNotReadyCount

public int getNotReadyCount()
Get number of experiments that are not ready to run.

Returns:
number of not ready experiments

getQueuedCount

public int getQueuedCount()
Get number of queued waiting to run experiments.

Returns:
number of queued experiments

getQueuePosition

public int getQueuePosition(ExecutionContext context)
Return queue position based on status and priority.

Parameters:
context - the context
Returns:
the queue position

getReadyCount

public int getReadyCount()
Get number of experiments that are ready to run.

Returns:
number of ready experiments

getRunningCount

public int getRunningCount()
Get number of running experiments.

Returns:
number of running experiments

getRunningQueue

public java.util.LinkedList<ExecutionContext> getRunningQueue()
Get running queue for the scheduler.

Returns:
the running queue

hasRunningQueue

public boolean hasRunningQueue()
Checks for running queue.

Returns:
true, if successful

getWaitingCount

public int getWaitingCount()
Get number of waiting to run experiments.

Returns:
number of waiting to run experiments

init

public void init()
Generate list of contexts parsed on sources.


insertIntoProperQueue

protected void insertIntoProperQueue(ExecutionContext context)
Insert experiment into proper queue based on experiment status.

Parameters:
context - experiment

isInitializing

public boolean isInitializing()
Indicates the scheduler is initializing.

Returns:
true if initializing

isRunning

public boolean isRunning()
Indicates that the scheduler is running.

Returns:
true if the scheduler is running

iterate

protected boolean iterate(java.util.Vector<PipeSource> srcRoots)
Iterate through all values for sources.

Parameters:
srcRoots - source roots to iterate
Returns:
true if there are more items to iterate

hasNext

protected boolean hasNext()
Returns true if sources have move elements.

Returns:
true, if checks for next

killAll

public void killAll()
Kill all running processes. This is a blocking operation.


pause

public void pause()
Pausing the scheduler will prevent new execution contexts from starting or completing.


processDestinations

public void processDestinations()
Process all destinations for this scheduler.


promote

public void promote(java.util.Vector<ExecutionContext> contexts)
Promote position of processes in queue.

Parameters:
contexts - the contexts

refreshQueues

protected void refreshQueues()
Refresh queues based on current status of context.


restart

public void restart(java.util.Vector<ExecutionContext> contexts)
Restart specified contexts.

Parameters:
contexts - the contexts

resume

public void resume()
Resume the scheduler.


run

public void run()
Schedule and run all experiments.

Specified by:
run in interface java.lang.Runnable

isCompleted

public boolean isCompleted()
Checks if is completed.

Returns:
true, if is completed

run

public void run(java.util.Vector<ExecutionContext> contexts)
Enqueue and run processes.

Parameters:
contexts - the contexts

start

public void start()
Start scheduler thread.


stop

public void stop()
Stop scheduler thread. This is a blocking operation.


stop

public void stop(java.util.Vector<ExecutionContext> contexts)
Stop running specified contexts.

Parameters:
contexts - the contexts

updateManagerTable

public void updateManagerTable()
Update table describing.


useExistingContext

protected void useExistingContext(ExecutionContext c)
Load existing context into graph instead of creating a new one. This will also load all descendants that are also redundant.

Parameters:
c - context

getElapsedCpuTime

public long getElapsedCpuTime()
Gets the elapsed cpu time.

Returns:
the elapsed cpu time

getElapsedActualTime

public long getElapsedActualTime()
Gets the elapsed actual time.

Returns:
the elapsed actual time