com.massimo.tools.scriptrunner.control
Class PollTask

java.lang.Object
  extended by com.massimo.tools.scriptrunner.AbstractTask
      extended by com.massimo.tools.scriptrunner.control.AbstractCompoundTask
          extended by com.massimo.tools.scriptrunner.control.PollTask
All Implemented Interfaces:
Task

public class PollTask
extends AbstractCompoundTask

Poll the single child task until it finishes successfully or a time limit is reached.
Introduces the integer-valued attributes Constants.ATTRIBUTE_DURATION and Constants.ATTRIBUTE_POLL.


Field Summary
protected static int DEFAULT_DURATION
           
protected static int DEFAULT_POLL
           
 
Fields inherited from class com.massimo.tools.scriptrunner.AbstractTask
definition, name, parent, properties, type
 
Fields inherited from interface com.massimo.tools.scriptrunner.Task
DATA_ERROR, ERROR, FINISHED, INTERRUPTED, PROMPT, RUNNING, START, SUCCESS
 
Constructor Summary
PollTask(Task parent, String type, Element definition, Map<String,String> contextProperties)
           
 
Method Summary
protected  int doValidate(ValidationContext context)
          Check whether this task should be able to run.
protected  org.apache.log4j.Logger getLogger()
          
 void interrupt()
          Tells the Task to stop processing.
protected  int processCompound(ExecutionContext context, Elements tasks)
          Polls the child Task every Constants.ATTRIBUTE_POLL seconds for up to Constants.ATTRIBUTE_DURATION seconds.
 
Methods inherited from class com.massimo.tools.scriptrunner.control.AbstractCompoundTask
addChild, doProcess, getChildren
 
Methods inherited from class com.massimo.tools.scriptrunner.AbstractTask
getBooleanProperty, getCurrentWorkingDirectory, getDefinition, getIntProperty, getName, getParent, getProperties, getStartProcessingRow, getText, getType, isIgnoreableError, isIgnoreableError, isInterrupted, isLogProgress, postProcess, preProcess, process, resultCodeToString, substituteParameters, toString, validate, validateConnections, validateParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_DURATION

protected static final int DEFAULT_DURATION
See Also:
Constant Field Values

DEFAULT_POLL

protected static final int DEFAULT_POLL
See Also:
Constant Field Values
Constructor Detail

PollTask

public PollTask(Task parent,
                String type,
                Element definition,
                Map<String,String> contextProperties)
Parameters:
parent -
type -
definition -
contextProperties -
Method Detail

doValidate

protected int doValidate(ValidationContext context)
                  throws Exception
Check whether this task should be able to run. Implementations should check for the prescence of files, attributes,...
Validates all child tasks
Checks the attributes Constants.ATTRIBUTE_POLL and Constants.ATTRIBUTE_DURATION

Overrides:
doValidate in class AbstractCompoundTask
Returns:
O for success. Anything else is a failure.
Throws:
Exception

getLogger

protected org.apache.log4j.Logger getLogger()

Specified by:
getLogger in class AbstractTask
Returns:
Class logger

interrupt

public void interrupt()
Tells the Task to stop processing. This does not garrantee that the task will return immediately.
Attempt to interrupt all children.
Attempt to interrupt the sleeping thread.

Specified by:
interrupt in interface Task
Overrides:
interrupt in class AbstractCompoundTask

processCompound

protected int processCompound(ExecutionContext context,
                              Elements tasks)
                       throws Exception
Polls the child Task every Constants.ATTRIBUTE_POLL seconds for up to Constants.ATTRIBUTE_DURATION seconds. This succeeds if the child Tasks succeeds within the given duration.

Specified by:
processCompound in class AbstractCompoundTask
Parameters:
context -
tasks - A list of Task definition Elements
Returns:
The result of running all tasks
Throws:
Exception