Version: ${maven.project.version}

org.soaplab.services
Class AbstractJob

java.lang.Object
  extended by org.soaplab.services.AbstractJob
All Implemented Interfaces:
Job
Direct Known Subclasses:
CmdLineJob

public abstract class AbstractJob
extends java.lang.Object
implements Job

A convenient parent of other Job's implementations.

Version:
$Id: AbstractJob.java,v 1.23 2010/10/11 14:32:53 marsenger Exp $
Author:
Martin Senger

Field Summary
static java.lang.String INTERNAL_ERROR
           
 
Method Summary
 void destroy()
          Destroy resources related to this job.
 long getCreated()
          Job created - returns number of millis from the BOE.
 long getElapsed()
          Job time elapsed - returns number in milliseconds.
 long getEnded()
          Job ended - returns number of millis from the BOE.
 java.lang.String getId()
          Return this job identity (an ID).
 java.io.File getJobDir()
          The job directory is created in a SANDBOX (see more in getSandbox()).
 java.lang.String getLastEvent()
          Get the last event.
 MetadataAccessor getMetadataAccessor()
          Get metadata accessor.
 Reporter getReporter()
          Get reporter.
 java.util.Map<java.lang.String,java.lang.Object> getResults()
          Return all (available) results.
 java.util.Map<java.lang.String,java.lang.Object> getResults(java.lang.String[] resultNames)
          Return all wanted (and available) results.
 java.util.Map<java.lang.String,java.lang.String>[] getResultsInfo()
           
 long getStarted()
          Job started - returns number of millis from the BOE.
 java.lang.String getStatus()
          Get job status.
 boolean isDataReferenceSafe(java.lang.String dataRef, ParamDef paramDef)
          Check if the 'dataRef' (which is a file name or a URL) is safe for this job.
 boolean isRecreated()
          Checks if the job is re-created
 void run()
          The meat of Soaplab.
 void setId(java.lang.String jobId)
          Set this job ID.
 void setInputs(java.util.Map<java.lang.String,java.lang.Object> inputs)
          Set input data into this job.
 void setInputValue(java.lang.String inputName, java.lang.Object value)
          Set an input value, given by its name.
 void setMetadataAccessor(MetadataAccessor metadataAccessor)
          Set metadata accessor.
 void setReporter(Reporter reporter)
          Set reporter.
 void setSharedAttributes(java.util.Map<java.lang.String,java.lang.Object> sharedAttributes)
          Shared attributes are any objects that are shared by more job instances.
 void terminate()
          Terminate this running job.
 void waitFor()
          Block and wait until job completes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERNAL_ERROR

public static final java.lang.String INTERNAL_ERROR
See Also:
Constant Field Values
Method Detail

setId

public void setId(java.lang.String jobId)
Set this job ID.

Specified by:
setId in interface Job

setReporter

public void setReporter(Reporter reporter)
Set reporter.

Specified by:
setReporter in interface Job

getReporter

public Reporter getReporter()
Get reporter.

Specified by:
getReporter in interface Job

setMetadataAccessor

public void setMetadataAccessor(MetadataAccessor metadataAccessor)
Set metadata accessor.

Specified by:
setMetadataAccessor in interface Job

getMetadataAccessor

public MetadataAccessor getMetadataAccessor()
Get metadata accessor.

Specified by:
getMetadataAccessor in interface Job

getId

public java.lang.String getId()
Return this job identity (an ID).

Specified by:
getId in interface Job

destroy

public void destroy()
Destroy resources related to this job.

It does *not* include results in persistent storages. These will be taken care of by the JobManager (the creator and creamatorium for Jobs).

Specified by:
destroy in interface Job

getJobDir

public java.io.File getJobDir()
                       throws SoaplabException
The job directory is created in a SANDBOX (see more in getSandbox()).

Specified by:
getJobDir in interface Job
Returns:
a File instance representing a directory
Throws:
SoaplabException - if the directory creation failed

isDataReferenceSafe

public boolean isDataReferenceSafe(java.lang.String dataRef,
                                   ParamDef paramDef)
Check if the 'dataRef' (which is a file name or a URL) is safe for this job. This implementation consider it safe if:

- It is an empty reference, or - It is a URL with any protocol except of 'file', or - The path of the URL with the 'file' protocol or an ordinary file name point to a non-existent file, or - The path of the URL with the 'file' protocol or an ordinary file name have an absolute path starting in SANDBOX directory (see getSandbox()) and it does not contain anywhere '..'.

Specified by:
isDataReferenceSafe in interface Job
Parameters:
dataRef - is a data reference (file name, URL) to be checked

paramDef - is a metadata definition of the input parameter whose data reference is being checked; an implementation can use it, for example, if inputs have different policy what is safe and what not (but this AbstractJob class does not use it)

Returns:
true if the data reference is considered safe to use

setInputs

public void setInputs(java.util.Map<java.lang.String,java.lang.Object> inputs)
               throws SoaplabException
Set input data into this job. The 'inputs' are not cloned - only their reference is stored (so it can be still changed by the caller - which is not, however, recommended.

Specified by:
setInputs in interface Job
Throws:
SoaplabException - if the job's status does not allow to set new inputs anymore, or if 'inputs' are null

setInputValue

public void setInputValue(java.lang.String inputName,
                          java.lang.Object value)
                   throws SoaplabException
Set an input value, given by its name.

Specified by:
setInputValue in interface Job
Throws:
SoaplabException - if the job's status does not allow to set new inputs anymore, or if 'value' is null

run

public void run()
         throws SoaplabException
The meat of Soaplab.

It is very probable, almost indisputable, that this method needs to be overridden in order to do something useful. Or, override only the 'realRun' method.

Specified by:
run in interface Job
Throws:
SoaplabException

waitFor

public void waitFor()
             throws SoaplabException
Block and wait until job completes.

Be sure that it is correctly synchronized with your own run() method. By default, it waits for "notify()" executer on the 'reporter' instance.

Specified by:
waitFor in interface Job
Throws:
SoaplabException

terminate

public void terminate()
               throws SoaplabException
Terminate this running job.

Specified by:
terminate in interface Job
Throws:
SoaplabException

getCreated

public long getCreated()
Job created - returns number of millis from the BOE.

Specified by:
getCreated in interface Job

getStarted

public long getStarted()
Job started - returns number of millis from the BOE.

Specified by:
getStarted in interface Job

getEnded

public long getEnded()
Job ended - returns number of millis from the BOE.

Specified by:
getEnded in interface Job

getElapsed

public long getElapsed()
Job time elapsed - returns number in milliseconds.

Specified by:
getElapsed in interface Job

getStatus

public java.lang.String getStatus()
Description copied from interface: Job
Get job status.

Specified by:
getStatus in interface Job

getLastEvent

public java.lang.String getLastEvent()
Description copied from interface: Job
Get the last event.

Specified by:
getLastEvent in interface Job

getResults

public java.util.Map<java.lang.String,java.lang.Object> getResults()
                                                            throws SoaplabException
Return all (available) results.

Specified by:
getResults in interface Job
Throws:
SoaplabException

getResults

public java.util.Map<java.lang.String,java.lang.Object> getResults(java.lang.String[] resultNames)
                                                            throws SoaplabException
Return all wanted (and available) results.

Specified by:
getResults in interface Job
Throws:
SoaplabException

getResultsInfo

public java.util.Map<java.lang.String,java.lang.String>[] getResultsInfo()
                                                                  throws SoaplabException
Specified by:
getResultsInfo in interface Job
Throws:
SoaplabException

setSharedAttributes

public void setSharedAttributes(java.util.Map<java.lang.String,java.lang.Object> sharedAttributes)
Description copied from interface: Job
Shared attributes are any objects that are shared by more job instances. Usually, one service keeps this container and gives it to its jobs. It depends on jobs what they store here.

Specified by:
setSharedAttributes in interface Job

isRecreated

public boolean isRecreated()
Description copied from interface: Job
Checks if the job is re-created

Specified by:
isRecreated in interface Job
Returns:
true if the job was re-created

Version: ${maven.project.version}

Submit a bug or feature
Generated: Tue Jun 14 15:18:14 AST 2011