public class UWSJob extends SerializableUWSObject
Default implementation of a job of the UWS pattern.
UWSJob
. You don't
have to do anything! The date/time format is managed automatically by
the library and can not be customized since it is imposed by the UWS
protocol definition: ISO-8601.
ABORTED
.setQuote(long)
method (a negative
value or QUOTE_NOT_KNOWN
value indicates the quote is not
known ; QUOTE_NOT_KNOWN
is the default value). This duration in
seconds will be added to the startTime and then automatically
formatted into an ISO-8601 date by the used serializer.
generateJobId()
:
This function is called at the construction of any UWSJob
. It
allows to generate a unique job ID. By default:
time (in milliseconds) + a upper-case letter (A, B, C, ....).
If you want customizing the job ID of your jobs, you need to
override this function or to use the new function
UWSJob(JobOwner, UWSParameters, String)
.
clearResources()
:
This method is called only at the destruction of the job.
By default, the job is stopped (if running), thread resources are freed,
the job is removed from its jobs list and result/error files are
deleted.
setPhaseManager(JobPhase)
:
Lets customizing the default behaviors of all the execution phases for
any job instance. For more details see JobPhase
.
addObserver(JobObserver)
:
An instance of any kind of AbstractJob can be observed by objects which
implements JobObserver
(i.e. UWSService
).
Observers are notified at any change of the execution phase.
Modifier and Type | Class and Description |
---|---|
protected class |
UWSJob.JobTimeOut
Stop/Cancel this job when its maximum execution duration has been reached.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ACTION_DELETE
Name of the DELETE action.
|
static java.lang.String |
ANONYMOUS_OWNER
Default value of
owner if no ID are given at the job creation. |
protected java.util.Date |
creationTime
Date of the initial creation of this job.
|
static java.text.DateFormat |
dateFormat
Deprecated.
Replaced by
ISO8601Format . |
static java.lang.String |
DEFAULT_DATE_FORMAT
Deprecated.
Replaced by
ISO8601Format . |
protected ErrorSummary |
errorSummary
This error summary gives a human-readable error message for the
underlying job.
|
protected UWSParameters |
inputParams
List of all input parameters (UWS standard and non-standard parameters).
|
protected java.lang.String |
jobId
The identifier of the job (it MUST be different from any other job).
|
protected JobInfo |
jobInfo
Additional description of this job.
|
protected static java.lang.String |
lastId
The last generated job ID.
|
protected JobOwner |
owner
The identifier of the creator of this job.
|
static java.lang.String |
PARAM_ACTION
Name of the parameter ACTION.
|
static java.lang.String |
PARAM_CREATION_TIME
Name of the parameter creationTime.
|
static java.lang.String |
PARAM_DESTRUCTION_TIME
Name of the parameter destructionTime.
|
static java.lang.String |
PARAM_END_TIME
Name of the parameter endTime.
|
static java.lang.String |
PARAM_ERROR_SUMMARY
Name of the parameter errorSummary.
|
static java.lang.String |
PARAM_EXECUTION_DURATION
Name of the parameter executionDuration.
|
static java.lang.String |
PARAM_JOB_ID
Name of the parameter jobId.
|
static java.lang.String |
PARAM_JOB_INFO
Name of the parameter jobInfo.
|
static java.lang.String |
PARAM_OWNER
Name of the parameter owner.
|
static java.lang.String |
PARAM_PARAMETERS
Name of the parameter otherParameters.
|
static java.lang.String |
PARAM_PHASE
Name of the parameter phase.
|
static java.lang.String |
PARAM_QUOTE
Name of the parameter quote.
|
static java.lang.String |
PARAM_RESULTS
Name of the parameter results.
|
static java.lang.String |
PARAM_RUN_ID
Name of the parameter runId.
|
static java.lang.String |
PARAM_START_TIME
Name of the parameter startTime.
|
static java.lang.String |
PHASE_ABORT
Value of the parameter phase which aborts the job.
|
static java.lang.String |
PHASE_RUN
Value of the parameter phase which starts the job.
|
static long |
QUOTE_NOT_KNOWN
The quote value that indicates the quote of this job is not known.
|
protected java.util.Map<java.lang.String,Result> |
results
This is a list of all results of this job.
|
protected boolean |
stopping
Used by the thread to known whether the
stop() method has
already been called, and so, that the job is stopping. |
protected JobThread |
thread
The thread to start for executing the job.
|
static long |
UNLIMITED_DURATION
The duration that implies an unlimited execution duration.
|
protected long |
waitForStop
The time (in ms) to wait the end of the thread after an interruption.
|
Constructor and Description |
---|
UWSJob(JobOwner owner,
UWSParameters params)
Builds a job of the given owner and from a map of all parameters (UWS
and additional parameters).
|
UWSJob(JobOwner owner,
UWSParameters params,
java.lang.String requestID)
Builds a job of the given owner and from a map of all parameters (UWS and
additional parameters).
|
UWSJob(java.lang.String jobID,
long creationTime,
JobOwner owner,
UWSParameters params,
long quote,
long startTime,
long endTime,
java.util.List<Result> results,
ErrorSummary error)
CONSTRUCTOR TO USE TO RESTORE A JOB whatever is its phase.
|
UWSJob(UWSParameters params)
Builds a job with no owner from a map of all parameters (UWS and
additional parameters).
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Stops immediately the job, sets its phase to
ABORTED and sets its end time. |
boolean |
addObserver(JobObserver observer)
Lets adding an observer of this job.
|
boolean |
addOrUpdateParameter(java.lang.String paramName,
java.lang.Object paramValue)
Adds or updates the specified parameter with the given value ONLY IF the
job can be updated (considering its current execution phase, see
JobPhase.isJobUpdatable() ). |
boolean |
addOrUpdateParameter(java.lang.String paramName,
java.lang.Object paramValue,
JobOwner user)
Adds or updates the specified parameter with the given value ONLY IF the
job can be updated (considering its current execution phase, see
JobPhase.isJobUpdatable() ). |
boolean |
addOrUpdateParameters(UWSParameters params)
Adds or updates the given parameters ONLY IF the job can be updated
(considering its current execution phase, see
JobPhase.isJobUpdatable() ). |
boolean |
addOrUpdateParameters(UWSParameters params,
JobOwner user)
Adds or updates the given parameters ONLY IF the job can be updated
(considering its current execution phase, see
JobPhase.isJobUpdatable() ). |
boolean |
addResult(Result res)
Adds the given result in the results list of this job.
|
void |
applyPhaseParam(JobOwner user)
Looks for an additional parameters which corresponds to the Execution
Phase.
|
boolean |
archive()
Archive this job.
|
void |
clearResources()
Stops the job if running, removes the job from the execution manager,
stops the timer for the execution duration.
|
void |
clearResources(boolean fullClean)
Stops the job if running, removes the job from the execution manager,
stops the timer for the execution duration.
|
boolean |
equals(java.lang.Object anotherJob)
2 instances of AbstractJob are equals ONLY IF their ID are equals.
|
void |
error(ErrorSummary error)
Stops immediately the job, sets its error summary, sets its phase to
ExecutionPhase.ERROR and sets its end time. |
protected java.lang.String |
generateJobId()
This function lets generating a unique ID.
|
java.util.Set<java.lang.String> |
getAdditionalParameters()
Gets the list of parameters' name.
|
java.lang.Object |
getAdditionalParameterValue(java.lang.String paramName)
Gets the value of the specified additional parameter.
|
java.util.Date |
getCreationTime()
Gets the creation date/time of this job.
|
java.util.Date |
getDestructionTime()
Gets the instant when the job shall be destroyed.
|
java.util.Date |
getEndTime()
Gets the time at which the job execution has finished.
|
ErrorSummary |
getErrorSummary()
Gets the error that occurs during the execution of this job.
|
long |
getExecutionDuration()
Gets the duration (in seconds) for which this job shall run.
|
ExecutionManager |
getExecutionManager()
Gets the execution manager of this job, if any.
|
UWSFactory |
getFactory()
Gets the factory to use to create the thread to execute when this job
starts.
|
UWSFileManager |
getFileManager()
Gets the file manager used in this job.
|
java.lang.String |
getJobId()
Gets the ID of this job (this ID MUST be unique).
|
JobInfo |
getJobInfo()
Get the additional information about this job.
|
JobList |
getJobList()
Gets its jobs list, if known.
|
UWSLog |
getLogger()
Gets the logger of its UWS or a default one if the job list or the UWS
is unknown.
|
int |
getNbAdditionalParameters()
Gets the number of additional parameters.
|
int |
getNbObservers()
Gets the total number of observers this job has.
|
int |
getNbResults()
Gets the total number of results.
|
java.util.Iterator<JobObserver> |
getObservers()
Gets the observers of this job.
|
JobOwner |
getOwner()
Gets the owner of this job.
|
java.lang.Object |
getParameter(java.lang.String name)
Gets the value of the specified parameter.
|
ExecutionPhase |
getPhase()
Gets the phase in which this job is now.
|
JobPhase |
getPhaseManager()
Gets the phase manager of this job.
|
long |
getQuote()
Get the quote attribute of this job.
|
java.util.Date |
getRestorationDate()
Gets the date of the restoration of this job.
|
Result |
getResult(java.lang.String resultId)
Gets the specified result.
|
java.util.Iterator<Result> |
getResults()
Gets the results list of this job.
|
java.lang.String |
getRunId()
Gets the RunID of this job given by the UWS user (presumed to be the
owner of this job).
|
java.util.Date |
getStartTime()
Gets the time at which the job execution has started.
|
long |
getTimeToWaitForEnd()
Gets the time to wait for the end of the thread after an interruption.
|
UWSUrl |
getUrl()
Gets the UWS URL of this job in function of its jobs list.
|
UWSException |
getWorkError()
Gets the error (if any) which has occurred during the job execution.
|
int |
hashCode() |
boolean |
isFinished()
Tells whether the job is already finished (completed, aborted,
error, archived, ...).
|
boolean |
isRunning()
Tells whether the job is still running.
|
protected boolean |
isStopped()
Tells whether the thread is different from null, is not alive or
is finished (see
JobThread.isFinished() ). |
void |
notifyObservers(ExecutionPhase oldPhase)
Notifies all the observer of this job that its phase has changed.
|
boolean |
removeAdditionalParameter(java.lang.String paramName)
Removes the specified additional parameter ONLY IF the job can be updated
(considering its current execution phase, see
JobPhase.isJobUpdatable() ). |
void |
removeAllObservers()
Lets removing all observers of this job.
|
boolean |
removeObserver(JobObserver observer)
Lets removing the given object from the list of observers of this job.
|
void |
serialize(javax.servlet.ServletOutputStream output,
java.lang.String[] attributes,
UWSSerializer serializer)
Serializes the specified attribute of this job in the given output stream
by using the given serializer.
|
java.lang.String |
serialize(java.lang.String[] attributes,
UWSSerializer serializer)
Serializes the specified attribute of this job by using the given
serializer.
|
java.lang.String |
serialize(UWSSerializer serializer,
JobOwner user)
Serializes the whole object considering the given owner (supposed to be the current user)
and thanks to the given serializer.
|
void |
setDestructionTime(java.util.Date destructionTime)
Sets the instant when the job shall be destroyed ONLY IF the job can
updated (considering its current execution phase, see
JobPhase.isJobUpdatable() ). |
protected void |
setEndTime(java.util.Date newDateTime)
Sets the time at which the job execution has finished.
|
void |
setErrorSummary(ErrorSummary errorSummary)
Sets the error that occurs during the execution of this job.
|
void |
setExecutionDuration(long executionDuration)
Sets the duration (in seconds) for which this job shall run ONLY IF the
job can updated (considering its current execution phase, see
JobPhase.isJobUpdatable() ). |
void |
setJobInfo(JobInfo newJobInfo)
Set the additional information about this job.
|
protected void |
setJobList(JobList jobList)
Sets its jobs list.
|
void |
setPhase(ExecutionPhase p)
Sets the current phase of this job.
|
void |
setPhase(ExecutionPhase p,
boolean force)
Sets the current phase of this job, respecting or not the imposed order.
|
void |
setPhaseManager(JobPhase jobPhase)
Sets the phase manager of this job.
|
void |
setQuote(long nbSeconds)
Sets the quote attribute of this job ONLY IF the job is not yet
finished according to its current status (i.e.
|
void |
setRunId(java.lang.String name)
Sets the RunID of this job ONLY IF the job can updated (considering
its current execution phase, see
JobPhase.isJobUpdatable() ). |
protected void |
setStartTime(java.util.Date newDateTime)
Sets the time at which the job execution has started.
|
void |
setTimeToWaitForEnd(long timeToWait)
Sets the time to wait for the end of the thread after an interruption.
|
void |
start()
Starts the job by using the execution manager if any.
|
void |
start(boolean useManager)
Starts the job.
|
protected void |
stop()
Stops the thread that executes the work of this job.
|
java.lang.String |
toString() |
serialize, serialize, serialize
public static final java.lang.String PARAM_ACTION
public static final java.lang.String ACTION_DELETE
public static final java.lang.String PARAM_JOB_ID
public static final java.lang.String PARAM_CREATION_TIME
public static final java.lang.String PARAM_RUN_ID
public static final java.lang.String PARAM_OWNER
public static final java.lang.String PARAM_PHASE
public static final java.lang.String PHASE_RUN
public static final java.lang.String PHASE_ABORT
public static final java.lang.String PARAM_QUOTE
public static final java.lang.String PARAM_START_TIME
public static final java.lang.String PARAM_END_TIME
public static final java.lang.String PARAM_EXECUTION_DURATION
public static final java.lang.String PARAM_DESTRUCTION_TIME
public static final java.lang.String PARAM_ERROR_SUMMARY
public static final java.lang.String PARAM_PARAMETERS
public static final java.lang.String PARAM_RESULTS
public static final java.lang.String PARAM_JOB_INFO
public static final java.lang.String ANONYMOUS_OWNER
owner
if no ID are given at the job creation.@Deprecated public static final java.lang.String DEFAULT_DATE_FORMAT
ISO8601Format
.public static final long QUOTE_NOT_KNOWN
public static final long UNLIMITED_DURATION
protected static java.lang.String lastId
generateJobId()
!protected final java.lang.String jobId
Note:
It is assigned automatically at the job creation in any job constructor
by the function generateJobId()
. To change the way this ID is
generated or its format you must override this function.
protected final java.util.Date creationTime
Note: This attribute can be set only automatically at creation by the UWS service and can not be set or changed by a user (even its owner).
protected final JobOwner owner
Note: This object will not exist for all invocations of the UWS conformant protocol, but only in cases where the access to the service is authenticated.
@Deprecated public static final java.text.DateFormat dateFormat
ISO8601Format
.protected ErrorSummary errorSummary
Note: This object is intended to be a detailed error message, and consequently, might be a large piece of text such as a stack trace.
protected java.util.Map<java.lang.String,Result> results
protected final UWSParameters inputParams
protected JobInfo jobInfo
protected transient JobThread thread
protected long waitForStop
protected boolean stopping
stop()
method has
already been called, and so, that the job is stopping.public UWSJob(UWSParameters params)
Note:
If the parameter PARAM_PHASE
(phase) is given with
the value PHASE_RUN
the job execution starts immediately
after the job has been added to a job list or after
applyPhaseParam(JobOwner)
is called.
params
- UWS standard and non-standard parameters.UWSJob(JobOwner, UWSParameters)
public UWSJob(JobOwner owner, UWSParameters params)
Note:
if the parameter PARAM_PHASE
(phase) is given with the
value PHASE_RUN
the job execution starts immediately after the
job has been added to a job list or after
applyPhaseParam(JobOwner)
is called.
owner
- Job.owner (PARAM_OWNER
).params
- UWS standard and non-standard parameters.UWSParameters.init()
public UWSJob(JobOwner owner, UWSParameters params, java.lang.String requestID)
Note:
If the parameter PARAM_PHASE
(phase) is given with the
value PHASE_RUN
the job execution starts immediately after the
job has been added to a job list or after
applyPhaseParam(JobOwner)
is called.
owner
- Job.owner (PARAM_OWNER
).params
- UWS standard and non-standard parameters.requestID
- ID of the HTTP request which has initiated the creation
of this job.
Note: if NULL, empty or already used, a job ID will
be generated thanks to generateJobId()
.UWSParameters.init()
public UWSJob(java.lang.String jobID, long creationTime, JobOwner owner, UWSParameters params, long quote, long startTime, long endTime, java.util.List<Result> results, ErrorSummary error) throws java.lang.NullPointerException
CONSTRUCTOR TO USE TO RESTORE A JOB whatever is its phase.
Builds a job of the given owner with all the given parameter.
Note: The job phase is automatically set in function of the last parameters (startTime, endTime, results and error). Only the following execution phase are possible: PENDING, ABORTED, ERROR and COMPLETED.
jobID
- The ID of this job (NOT NULL).creationTime
- Its creation date/time (SHOULD NOT BE NEGATIVE OR
NULL).owner
- Its owner.params
- UWS standard and non-standard parameters.quote
- Its quote (in seconds).startTime
- Its start time if it has already been started.endTime
- Its end time if it is already finished.results
- Its results (if phase=COMPLETED).error
- Its error (if phase=ERROR).java.lang.NullPointerException
- If the given ID is NULL.protected java.lang.String generateJobId()
By default: System.currentTimeMillis()+UpperCharacter (UpperCharacter: one upper-case character chosen in order to guarantee the unicity of the ID: A, B, C, ....)
Note:
DO NOT USE in this function any of the following functions:
getLogger()
, getFileManager()
and
getFactory()
. All of them will return NULL, because this job
does not yet know its jobs list (which is needed to know the UWS and so,
all of the objects returned by these functions).
public java.lang.Object getParameter(java.lang.String name)
Gets the value of the specified parameter.
Note: No case sensitivity for the UWS parameters ON THE CONTRARY TO the names of the additional parameters (which are case sensitive).
name
- Name of the parameter to get.UWSParameters.get(String)
public void applyPhaseParam(JobOwner user) throws UWSException
RUN
=> remove it from the attribute inputParams
and start the job.ABORT
=> remove it from the attribute inputParams
and abort the job.inputParams
but nothing is done.user
- The user who asks to apply the phase parameter
(start/abort). May be NULL.UWSException
- If it is impossible the state of this job
(into EXECUTING or ABORTED) or if the given user is
not allowed to execute this job.UWSParameters.hasInputPhase()
,
UWSParameters.getInputPhase()
,
start()
,
abort()
public final UWSFileManager getFileManager()
JobList
or if this jobs list is not into a UWS
.JobList.getUWS()
,
UWS.getFileManager()
public UWSLog getLogger()
JobList.getUWS()
,
UWS.getLogger()
,
UWSToolBox.getDefaultLogger()
public final UWSFactory getFactory()
JobThread
.public final java.util.Date getRestorationDate()
public final ExecutionPhase getPhase()
JobPhase.getPhase()
public final void setPhase(ExecutionPhase p) throws UWSException
IMPORTANT:
PENDING
--->
QUEUED
--->
EXECUTING
--->
COMPLETED
.EXECUTING
phase is by sending a POST query with the value
RUN
for the parameter
PHASE
.ABORTED
phase is by sending a POST query with the value
ABORT
for the parameter
PHASE
.EXECUTING
and
COMPLETED
,
ABORTED
or ERROR
p
- The phase to set for this job.UWSException
- If the given phase does not respect the job's
phases order.setPhase(ExecutionPhase, boolean)
public final void setPhase(ExecutionPhase p, boolean force) throws UWSException
IMPORTANT:
PENDING
--->
QUEUED
--->
EXECUTING
--->
COMPLETED
.EXECUTING
phase is by sending a POST query with the value
RUN
for the parameter
PARAM_PHASE
.ABORTED
phase is by sending a POST query with the value
ABORT
for the parameter
PARAM_PHASE
.EXECUTING
and
COMPLETED
,
ABORTED
or ERROR
p
- The phase to set for this job.force
- true to impose the given execution phase,
false to take into account the order of all phases.UWSException
- If the given phase does not respect the job's
phases order.JobPhase.setPhase(ExecutionPhase, boolean)
,
JobPhase.isFinished()
,
ExecutionManager.remove(UWSJob)
,
notifyObservers(ExecutionPhase)
public final JobPhase getPhaseManager()
Note: The phase manager manages all the transitions between all the execution phases.
public final void setPhaseManager(JobPhase jobPhase)
Note: The phase manager manages all the transitions between all the execution phases.
jobPhase
- Its new phase manager (if null this function does
nothing).public final java.util.Date getStartTime()
protected final void setStartTime(java.util.Date newDateTime)
newDateTime
- The start time of the execution of this job.public final java.util.Date getEndTime()
protected final void setEndTime(java.util.Date newDateTime)
newDateTime
- The end time of the execution of this job.public final long getExecutionDuration()
UWSParameters.getExecutionDuration()
public final void setExecutionDuration(long executionDuration)
JobPhase.isJobUpdatable()
).
Note: A duration of 0 (or less) implies unlimited execution duration.
executionDuration
- The execution duration of this job.UWSParameters.set(String, Object)
public final java.util.Date getDestructionTime()
UWSParameters.getDestructionTime()
public final void setDestructionTime(java.util.Date destructionTime)
JobPhase.isJobUpdatable()
). If known the jobs list is notify of
this destruction time update.destructionTime
- The destruction time of this job.
MUST NOT be NULLJobList.updateDestruction(UWSJob)
,
UWSParameters.set(String, Object)
public final ErrorSummary getErrorSummary()
public final void setErrorSummary(ErrorSummary errorSummary) throws UWSException
IMPORTANT:
This function will have no effect if the job is finished, that is to say
if the current phase is ABORTED
,
ERROR
,
COMPLETED
or ARCHIVED
.
errorSummary
- A summary of the error. MUST NOT be NULLUWSException
- If the job execution is finished that is to say if
the phase is ABORTED, ERROR, COMPLETED or ARCHIVED.isFinished()
public final java.lang.String getJobId()
public final java.lang.String getRunId()
WARNING:
This ID may be used by other jobs BUT their job id
(cf getJobId()
) must be different.
UWSParameters.getRunId()
public final void setRunId(java.lang.String name)
JobPhase.isJobUpdatable()
).name
- Its name/label.JobPhase.isJobUpdatable()
,
UWSParameters.set(String, Object)
public final JobOwner getOwner()
public final long getQuote()
public final void setQuote(long nbSeconds)
JobPhase.isFinished()
).
Note:
A negative or NULL value will be considered as 'no quote for this job'.
One could use the constant QUOTE_NOT_KNOWN
(= -1L) for this exact purpose.
nbSeconds
- The estimated duration of the job execution
(in seconds).public final java.util.Set<java.lang.String> getAdditionalParameters()
UWSParameters.getNames()
public final int getNbAdditionalParameters()
public final java.lang.Object getAdditionalParameterValue(java.lang.String paramName)
paramName
- The name of the parameter whose the value is wanted.public final boolean addOrUpdateParameter(java.lang.String paramName, java.lang.Object paramValue) throws UWSException
JobPhase.isJobUpdatable()
).
Important note:
If the given parameter value is an UploadFile
and that it is
impossible to move it close to the job, this parameter will be removed.
No error is thrown, but a warning message is logged.
paramName
- The name of the parameter to add or to update.paramValue
- The (new) value of the specified parameter.UWSException
- If a parameter value is incorrect.JobPhase.isJobUpdatable()
public final boolean addOrUpdateParameter(java.lang.String paramName, java.lang.Object paramValue, JobOwner user) throws UWSException
JobPhase.isJobUpdatable()
).
Important note:
If the given parameter value is an UploadFile
and that it is
impossible to move it close to the job, this parameter will be removed.
No error is thrown, but a warning message is logged.
paramName
- The name of the parameter to add or to update.paramValue
- The (new) value of the specified parameter.user
- The user who asks for this update.UWSException
- If a parameter value is incorrect.JobPhase.isJobUpdatable()
public boolean addOrUpdateParameters(UWSParameters params) throws UWSException
JobPhase.isJobUpdatable()
).
At the end of this function, the method
applyPhaseParam(JobOwner)
is called so that if there is an
additional parameter PARAM_PHASE
with the value:
RUN
then the job is starting and the phase
goes to EXECUTING
.ABORT
then the job is aborting.PARAM_PHASE
is
removed from inputParams
and nothing is
done.Important note:
If a given parameter value is an UploadFile
and that it is
impossible to move it close to the job, this parameter will be removed.
No error is thrown, but a warning message is logged.
params
- A list of parameters to add/update.UWSException
- If a parameter value is incorrect.addOrUpdateParameters(UWSParameters, JobOwner)
public final java.util.Date getCreationTime()
public boolean addOrUpdateParameters(UWSParameters params, JobOwner user) throws UWSException
JobPhase.isJobUpdatable()
).
At the end of this function, the method
applyPhaseParam(JobOwner)
is called so that if there is an
additional parameter PARAM_PHASE
with the value:
RUN
then the job is starting and the phase
goes to EXECUTING
.ABORT
then the job is aborting.PARAM_PHASE
is
removed from inputParams
and nothing is
done.Important note:
If a given parameter value is an UploadFile
and that it is
impossible to move it close to the job, this parameter will be removed.
No error is thrown, but a warning message is logged.
params
- The UWS parameters to update.user
- The user who asks for this update.UWSException
- If a parameter value is incorrect or if the given
user can not update or execute this job.JobPhase.isJobUpdatable()
,
applyPhaseParam(JobOwner)
public final boolean removeAdditionalParameter(java.lang.String paramName)
JobPhase.isJobUpdatable()
).paramName
- The name of the parameter to remove.JobPhase.isJobUpdatable()
,
UWSParameters.remove(String)
public final java.util.Iterator<Result> getResults()
public final Result getResult(java.lang.String resultId)
resultId
- ID of the result to return.public final int getNbResults()
public boolean addResult(Result res) throws UWSException
IMPORTANT: This function will throw an error if the job is finished.
res
- The result to add (not null).UWSException
- If the job execution is finished that is to say if
the phase is ABORTED, ERROR, COMPLETED or ARCHIVED.isFinished()
public final JobInfo getJobInfo()
public void setJobInfo(JobInfo newJobInfo)
Note:
By default, this function replaces the current JobInfo
of this job by the given one (even if NULL). This behavior
can be changed by overwriting this function and by returning the
extended UWSJob
in the used UWSFactory
.
Important note:
When attributing a JobInfo
to a UWSJob
, you
may have to call JobInfo.setJob(UWSJob)
on the former
and the new jobInfo (see the default implementation for an example)
for some implementations of JobInfo
.
newJobInfo
- The new additional info. about this job.
NULL is allowed and should be used to remove a
JobInfo from a job.public final ExecutionManager getExecutionManager()
public final JobList getJobList()
protected final void setJobList(JobList jobList) throws java.lang.IllegalStateException
Note 1: A job can change its jobs list ONLY WHILE PENDING!
Note 2: This job is removed from its previous job list, if there is one.
Note 3:
This job is NOT automatically added into the new jobs list. Indeed, this
function should be called by JobList.addNewJob(UWSJob)
.
jobList
- Its new jobs list.
Note: if NULL, nothing is done!java.lang.IllegalStateException
- If this job is not PENDING.JobList.removeJob(String)
,
JobList.getJob(String)
public final UWSUrl getUrl()
JobList.getUrl()
,
UWSUrl.jobSummary(String, String)
public final long getTimeToWaitForEnd()
public final void setTimeToWaitForEnd(long timeToWait)
timeToWait
- The new time to wait for the end of the thread (a
negative or null value means no wait for the end of
the thread).public final void start() throws UWSException
UWSException
public void start(boolean useManager) throws UWSException
Note: This function does nothing if the job is already running!
useManager
- true to let the execution manager deciding
whether the job starts immediately or whether it
must be put in a queue until enough resources are
available,
false to start the execution immediately.java.lang.NullPointerException
- If this job is not associated with a job
list or the associated job list is not part
of a UWS service or if no thread is created.UWSException
- If there is an error while changing the
execution phase or when starting the
corresponding thread.isRunning()
,
UWSFactory.createJobThread(UWSJob)
,
ExecutionManager.execute(UWSJob)
,
setPhase(ExecutionPhase)
,
isFinished()
,
startTime
public final boolean isRunning()
Note:
This function tests the execution phase (see
JobPhase.isExecuting()
) AND the status of the thread (see
isStopped()
).
JobPhase.isExecuting()
,
isStopped()
public final boolean isFinished()
Note:
This function test the execution phase (see
JobPhase.isFinished()
) AND the status of the thread (see
isStopped()
).
JobPhase.isFinished()
,
isStopped()
public void abort() throws UWSException
ABORTED
and sets its end time.
IMPORTANT:
If the thread does not stop immediately the phase and the end time are
not modified. However it can be done by calling one more time
abort()
. Besides you should check that you test regularly the
interrupted flag of the thread in JobThread.jobWork()
!
UWSException
- If there is an error while changing the execution
phase.stop()
,
isStopped()
,
setPhase(ExecutionPhase)
,
setEndTime(Date)
public void error(ErrorSummary error) throws UWSException
ExecutionPhase.ERROR
and sets its end time.
IMPORTANT:
If the thread does not stop immediately the phase, the error summary and
the end time are not modified. However it can be done by calling one
more time error(ErrorSummary)
. Besides you should check that
you test regularly the interrupted flag of the thread in
JobThread.jobWork()
!
error
- The error that has interrupted this job.UWSException
- If there is an error while setting the error summary
or while changing the phase.stop()
,
isStopped()
,
JobPhase.isFinished()
,
setErrorSummary(ErrorSummary)
,
setPhase(ExecutionPhase)
,
setEndTime(Date)
protected void stop()
protected final boolean isStopped()
JobThread.isFinished()
).
Important note:
Having the interrupted flag set to true
is not enough to
consider the job as stopped. So, if the job has been interrupted but is
still running, it should mean that the JobThread.jobWork()
does
not check the interrupted flag of the thread often enough or not at the
right moments. In such case, the job can not be considered as
stopped/aborted - so the phase stays
EXECUTING
- until the thread is
"unblocked" and the interruption is detected.
public boolean archive()
An archive job can not be executed any more. Threads, results and input
files are destroyed but the description and the error summary of
the job stay unchanged (except the execution phase which will then be
ARCHIVED
).
Note: The current phase is stored as job information (only if no JobInfo is already set) in order to satisfy the user curiosity (i.e. "in what phase was this job before being archived?").
true
if this job has been successfully archived,
false
otherwise.UWSException
- If any error occurs while clearing resources
or changing the phase of this job.public void clearResources()
Besides, ALL files AND ANY other resources (e.g. thread) associated with this job are destroyed.
clearResources(boolean)
public void clearResources(boolean fullClean)
Besides, resources (e.g. thread) associated with this job are freed.
Depending on the given parameter, all (true
) or just input
and result files (false
) are destroyed.
fullClean
- Indicate whether all resources or just some input and
result files must be freed.
true
to stop the job and delete everything
(input files, results, jobInfos and error summary),
or false
to stop the job and delete only
all input files and results but not the jobInfos, the
error summary and the other parameters.public final boolean addObserver(JobObserver observer)
observer
- A new observer of this job.public final int getNbObservers()
public final java.util.Iterator<JobObserver> getObservers()
public final boolean removeObserver(JobObserver observer)
observer
- The object which must not be considered as observer of
this job.public final void removeAllObservers()
public final void notifyObservers(ExecutionPhase oldPhase)
oldPhase
- The former phase of this job.UWSException
- If at least one observer can not have been updated.public final UWSException getWorkError()
Note:
In the case an error summary can not have been published, the job has no
error summary. However the last UWSException
caught during the
execution of a JobThread
is saved and is available thanks to
JobThread.getError()
. In that case, the
getWorkError()
method can be used to get
back the occurred error.
public java.lang.String serialize(UWSSerializer serializer, JobOwner user) throws UWSException, java.lang.Exception
SerializableUWSObject
serialize
in class SerializableUWSObject
serializer
- The serializer to use.user
- The current user.UWSException
- If the owner is not allowed to see the content of the serializable object.java.lang.Exception
- If there is any other error during the serialization.public java.lang.String serialize(java.lang.String[] attributes, UWSSerializer serializer) throws java.lang.Exception
attributes
- All the given attributes.
May be null or empty.serializer
- The serializer to use.java.lang.Exception
- If there is an unexpected error during the
serialization.UWSSerializer.getJob(UWSJob, String[], boolean)
public void serialize(javax.servlet.ServletOutputStream output, java.lang.String[] attributes, UWSSerializer serializer) throws UWSException, java.io.IOException, java.lang.Exception
output
- The output stream in which the job attribute must be
serialized.attributes
- The name of the attribute to serialize (if
null, the whole job will be serialized).serializer
- The serializer to use.java.lang.Exception
- If there is an unexpected error during the
serialization.UWSException
java.io.IOException
serialize(String[], UWSSerializer)
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object anotherJob)
Note: If the given object is not an AbstractJob, FALSE is returned.
equals
in class java.lang.Object
Object.equals(java.lang.Object)