com.massimo.tools.scriptrunner.context
Class FileExecutionContext

java.lang.Object
  extended by com.massimo.tools.scriptrunner.context.AbstractExecutionContext
      extended by com.massimo.tools.scriptrunner.context.FileExecutionContext
All Implemented Interfaces:
ExecutionContext

public class FileExecutionContext
extends AbstractExecutionContext

Implement ExecutionContext in flat files, housed in a directory sruns.
There are two files per run: a serialized Map of restart data, and a simple log file.


Field Summary
 
Fields inherited from class com.massimo.tools.scriptrunner.context.AbstractExecutionContext
lastException, runId
 
Constructor Summary
FileExecutionContext(Map<String,String> properties)
          Get parent directory from properties or assume user directory.
 
Method Summary
protected  void finalize()
           
 void finished(String taskName, int lastStepProcessed)
          Audit trail: record successful finish of Task execution
protected  String generateRunIdentifier(Map<String,String> properties)
           The run identifier is saved in a file as a String.
protected  org.apache.log4j.Logger getLogger()
          
 String getRunIdentifier(Map<String,String> properties)
          
If the runId is not set, look for a run identifier in properties.
 boolean isFinished(String taskName)
          Audit trail: check whether Task has already been executed in this run
 void log(String taskName, int log_code, String message, int lastStepProcessed, String key)
          Log informational messages
 void progress(String taskName, int lastStepProcessed, String key)
          Audit trail: Task has finished executing its lastStepProcessed step
 int start(String taskName)
          Audit trail: start Task execution
 
Methods inherited from class com.massimo.tools.scriptrunner.context.AbstractExecutionContext
getLastException, log, setLastException, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileExecutionContext

public FileExecutionContext(Map<String,String> properties)
Get parent directory from properties or assume user directory.

Parameters:
properties -
Throws:
FileAccessException
Method Detail

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable
See Also:
Object.finalize()

finished

public void finished(String taskName,
                     int lastStepProcessed)
              throws SRException
Audit trail: record successful finish of Task execution

Throws:
SRException

generateRunIdentifier

protected String generateRunIdentifier(Map<String,String> properties)
The run identifier is saved in a file as a String.

Specified by:
generateRunIdentifier in class AbstractExecutionContext
Returns:
a newly generate run identifier
Throws:
NumberFormatException - if the contents of the run identifier file are not a long.

getLogger

protected org.apache.log4j.Logger getLogger()

Specified by:
getLogger in class AbstractExecutionContext
Returns:
The concrete class's Logger

getRunIdentifier

public String getRunIdentifier(Map<String,String> properties)
                        throws SRException

If the runId is not set, look for a run identifier in properties.
If not found, call AbstractExecutionContext.generateRunIdentifier(Map).
Can only initiate the save files once the run identifier is known.

Specified by:
getRunIdentifier in interface ExecutionContext
Overrides:
getRunIdentifier in class AbstractExecutionContext
Returns:
String The existing or a new run identifier.
Throws:
SRException - if unable to find or generate a run identifier

isFinished

public boolean isFinished(String taskName)
                   throws SRException
Audit trail: check whether Task has already been executed in this run

Returns:
boolean
Throws:
SRException

log

public void log(String taskName,
                int log_code,
                String message,
                int lastStepProcessed,
                String key)
         throws SRException
Log informational messages

log_code - The Task constants or an error code
key - A identifier for the last step, e.g. a database row's primary key value. May be empty.
Throws:
SRException

progress

public void progress(String taskName,
                     int lastStepProcessed,
                     String key)
              throws SRException
Audit trail: Task has finished executing its lastStepProcessed step

lastStepProcessed - On re-start, this value will returned by ExecutionContext.start(String)
key - A identifier for the last step, e.g. a database row's primary key value. May be empty.
Throws:
SRException

start

public int start(String taskName)
          throws SRException
Audit trail: start Task execution

Returns:
int The index of the last executed step or 0.
Throws:
SRException