diff --git a/src/uws/job/UWSJob.java b/src/uws/job/UWSJob.java index 885bb40e91d343b7b94a8a789dd701af61939dbb..9c6dae4a82a65634540208c7518ea0b6c5d19e89 100644 --- a/src/uws/job/UWSJob.java +++ b/src/uws/job/UWSJob.java @@ -2,20 +2,20 @@ package uws.job; /* * This file is part of UWSLibrary. - * + * * UWSLibrary is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * UWSLibrary is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. - * + * * Copyright 2012-2017 - UDS/Centre de DonnĂ©es astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ @@ -52,11 +52,11 @@ import uws.service.request.UploadFile; /** * <h3>Brief description</h3> - * + * * <p>Default implementation of a job of the UWS pattern.</p> - * + * * <h3>Some attributes comments</h3> - * + * * <ul> * <li> * The job attributes <i>startTime</i> and <i>endTime</i> are automatically managed by {@link UWSJob}. You don't have to do anything ! @@ -82,9 +82,9 @@ import uws.service.request.UploadFile; * indicates the quote is not known ; {@link #QUOTE_NOT_KNOWN} is the default value). * </li> * </ul> - * + * * <h3>More details</h3> - * + * * <ul> * <li> * <b>{@link #generateJobId()}:</b> @@ -113,9 +113,9 @@ import uws.service.request.UploadFile; * Observers are notified at any change of the execution phase. * </li> * </ul> - * + * * @author Grégory Mantelet (CDS;ARI) - * @version 4.2 (06/2017) + * @version 4.2 (09/2017) */ public class UWSJob extends SerializableUWSObject { private static final long serialVersionUID = 1L; @@ -275,12 +275,12 @@ public class UWSJob extends SerializableUWSObject { /* ************ */ /** * <p>Builds a job with no owner from a map of all parameters (UWS and additional parameters).</p> - * + * * <p><i><u>Note:</u> if the parameter {@link UWSJob#PARAM_PHASE} (</i>phase<i>) is given with the value {@link UWSJob#PHASE_RUN} * the job execution starts immediately after the job has been added to a job list or after {@link #applyPhaseParam(JobOwner)} is called.</i></p> - * + * * @param params UWS standard and non-standard parameters. - * + * * @see UWSJob#UWSJob(JobOwner, UWSParameters) */ public UWSJob(final UWSParameters params){ @@ -289,13 +289,13 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Builds a job of the given owner and from a map of all parameters (UWS and additional parameters).</p> - * + * * <p><i><u>Note:</u> if the parameter {@link #PARAM_PHASE} (</i>phase<i>) is given with the value {@link #PHASE_RUN} * the job execution starts immediately after the job has been added to a job list or after {@link #applyPhaseParam(JobOwner)} is called.</i></p> - * + * * @param owner Job.owner ({@link #PARAM_OWNER}). * @param params UWS standard and non-standard parameters. - * + * * @see UWSParameters#init() */ public UWSJob(JobOwner owner, final UWSParameters params){ @@ -323,17 +323,17 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Builds a job of the given owner and from a map of all parameters (UWS and additional parameters). * The given HTTP request ID will be used as Job ID if not already used by another job.</p> - * + * * <p><i><u>Note:</u> if the parameter {@link #PARAM_PHASE} (</i>phase<i>) is given with the value {@link #PHASE_RUN} * the job execution starts immediately after the job has been added to a job list or after {@link #applyPhaseParam(JobOwner)} is called.</i></p> - * + * * @param owner Job.owner ({@link #PARAM_OWNER}). * @param params UWS standard and non-standard parameters. * @param requestID ID of the HTTP request which has initiated the creation of this job. * <i>Note: if NULL, empty or already used, a job ID will be generated thanks to {@link #generateJobId()}.</i> - * + * * @see UWSParameters#init() - * + * * @since 4.2 */ public UWSJob(JobOwner owner, final UWSParameters params, final String requestID){ @@ -368,14 +368,14 @@ public class UWSJob extends SerializableUWSObject { /** * <p><b>CONSTRUCTOR TO USE TO RESTORE A JOB whatever is its phase.</b></p> - * + * * <p>Builds a job of the given owner with all the given parameter.</p> - * + * * <p><i> * <u>Note:</u> 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. * </i></p> - * + * * @param jobID The ID of this job (NOT NULL). * @param owner Its owner. * @param params UWS standard and non-standard parameters. @@ -384,7 +384,7 @@ public class UWSJob extends SerializableUWSObject { * @param endTime Its end time if it is already finished. * @param results Its results (if phase=COMPLETED). * @param error Its error (if phase=ERROR). - * + * * @throws NullPointerException If the given ID is NULL. */ public UWSJob(final String jobID, final JobOwner owner, final UWSParameters params, final long quote, final long startTime, final long endTime, final List<Result> results, final ErrorSummary error) throws NullPointerException{ @@ -438,13 +438,13 @@ public class UWSJob extends SerializableUWSObject { /** * <p>This function lets generating a unique ID.</p> - * + * * <p><i><b>By default:</b> System.currentTimeMillis()+UpperCharacter (UpperCharacter: one upper-case character chosen in order to guarantee the unicity of the ID: A, B, C, ....)</i></p> - * + * * <p><i><u>note: </u> DO NOT USE in this function any of the following functions: {@link #getLogger()}, * {@link #getFileManager()} and {@link #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).</i></p> - * + * * @return A unique job identifier. */ protected String generateJobId(){ @@ -461,13 +461,13 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Gets the value of the specified parameter.</p> - * + * * <p><i><u>note:</u> No case sensitivity for the UWS parameters ON THE CONTRARY TO the names of the additional parameters (which are case sensitive).</i></p> - * + * * @param name Name of the parameter to get. - * + * * @return Its value or <i>null</i> if there is no parameter with the given name or if the value is <i>null</i>. - * + * * @see UWSParameters#get(String) */ public Object getParameter(String name){ @@ -498,12 +498,12 @@ public class UWSJob extends SerializableUWSObject { * <li> is equals to {@link UWSJob#PHASE_ABORT ABORT} => remove it from the attribute {@link #inputParams} and abort the job.</li> * <li> is another value => the attribute is though removed from the attribute {@link #inputParams} but nothing is done.</li> * </ul> - * + * * @param user The user who asks to apply the phase parameter (start/abort). (may be NULL) - * + * * @throws 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. - * + * * @see UWSParameters#hasInputPhase() * @see UWSParameters#getInputPhase() * @see #start() @@ -533,9 +533,9 @@ public class UWSJob extends SerializableUWSObject { /* ***************** */ /** * Gets the file manager used in this job. - * + * * @return Its file manager or <i>null</i> if this job is not into a {@link JobList} or if this jobs list is not into a {@link UWS}. - * + * * @see JobList#getUWS() * @see uws.service.UWS#getFileManager() */ @@ -548,9 +548,9 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the logger of its UWS or a default one if the job list or the UWS is unknown. - * + * * @return A logger. - * + * * @see JobList#getUWS() * @see uws.service.UWS#getLogger() * @see UWSToolBox#getDefaultLogger() @@ -564,7 +564,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the factory to use to create the thread to execute when this job starts. - * + * * @return The factory to use to create a {@link JobThread}. */ public final UWSFactory getFactory(){ @@ -576,7 +576,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the date of the restoration of this job. - * + * * @return Date of its restoration. */ public final Date getRestorationDate(){ @@ -585,9 +585,9 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the phase in which this job is now. - * + * * @return The current phase of this job. - * + * * @see JobPhase#getPhase() */ public final ExecutionPhase getPhase(){ @@ -596,18 +596,18 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Sets the current phase of this job.</p> - * + * * <p><b><u>IMPORTANT:</u></b> * <ul><li>The order of all phases must be respected:<i> BY DEFAULT</i> <BR /> {@link ExecutionPhase#PENDING PENDING} ---> {@link ExecutionPhase#QUEUED QUEUED} ---> {@link ExecutionPhase#EXECUTING EXECUTING} ---> {@link ExecutionPhase#COMPLETED COMPLETED}.</li> * <li>The only way to go to the {@link ExecutionPhase#EXECUTING EXECUTING} phase is by sending a POST query with the value {@link UWSJob#PHASE_RUN RUN} for the parameter {@link UWSJob#PARAM_PHASE PHASE}.</li> * <li>The only way to go to the {@link ExecutionPhase#ABORTED ABORTED} phase is by sending a POST query with the value {@link UWSJob#PHASE_ABORT ABORT} for the parameter {@link UWSJob#PARAM_PHASE PHASE}.</li> * <li>The start time and the end time are set automatically when the phase is set to {@link ExecutionPhase#EXECUTING EXECUTING} and {@link ExecutionPhase#COMPLETED COMPLETED}, {@link ExecutionPhase#ABORTED ABORTED} or {@link ExecutionPhase#ERROR ERROR}</li> *</ul></p> - * + * * @param p The phase to set for this job. - * + * * @throws UWSException If the given phase does not respect the job's phases order. - * + * * @see #setPhase(ExecutionPhase, boolean) */ public final void setPhase(ExecutionPhase p) throws UWSException{ @@ -616,19 +616,19 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Sets the current phase of this job, respecting or not the imposed order.</p> - * + * * <p><b><u>IMPORTANT:</u></b> * <ul><li><b><u>If the parameter <i>force</i> is <i>false</i></u></b>, the order of all phases must be respected:<BR /> {@link ExecutionPhase#PENDING PENDING} ---> {@link ExecutionPhase#QUEUED QUEUED} ---> {@link ExecutionPhase#EXECUTING EXECUTING} ---> {@link ExecutionPhase#COMPLETED COMPLETED}.</li> * <li>The only way to go to the {@link ExecutionPhase#EXECUTING EXECUTING} phase is by sending a POST query with the value {@link UWSJob#PHASE_RUN RUN} for the parameter {@link UWSJob#PARAM_PHASE PARAM_PHASE}.</li> * <li>The only way to go to the {@link ExecutionPhase#ABORTED ABORTED} phase is by sending a POST query with the value {@link UWSJob#PHASE_ABORT ABORT} for the parameter {@link UWSJob#PARAM_PHASE PARAM_PHASE}.</li> * <li>The start time and the end time are set automatically when the phase is set to {@link ExecutionPhase#EXECUTING EXECUTING} and {@link ExecutionPhase#COMPLETED COMPLETED}, {@link ExecutionPhase#ABORTED ABORTED} or {@link ExecutionPhase#ERROR ERROR}</li> *</ul></p> - * + * * @param p The phase to set for this job. * @param force <i>true</i> to impose the given execution phase, <i>false</i> to take into account the order of all phases. - * + * * @throws UWSException If the given phase does not respect the job's phases order. - * + * * @see JobPhase#setPhase(ExecutionPhase, boolean) * @see JobPhase#isFinished() * @see ExecutionManager#remove(UWSJob) @@ -653,9 +653,9 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Gets the phase manager of this job.</p> - * + * * <p><i><u>Note:</u> The phase manager manages all the transitions between all the execution phases.</i></p> - * + * * @return Its phase manager. */ public final JobPhase getPhaseManager(){ @@ -664,9 +664,9 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Sets the phase manager of this job.</p> - * + * * <p><i><u>Note:</u> The phase manager manages all the transitions between all the execution phases.</i></p> - * + * * @param jobPhase Its new phase manager (if <i>null</i> this function does nothing). */ public final void setPhaseManager(JobPhase jobPhase){ @@ -679,7 +679,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the time at which the job execution has started. - * + * * @return The start time of the execution of this job. */ public final Date getStartTime(){ @@ -688,7 +688,7 @@ public class UWSJob extends SerializableUWSObject { /** * Sets the time at which the job execution has started. - * + * * @param newDateTime The start time of the execution of this job. */ protected final void setStartTime(Date newDateTime){ @@ -697,7 +697,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the time at which the job execution has finished. - * + * * @return The end time of the execution of this job. */ public final Date getEndTime(){ @@ -706,7 +706,7 @@ public class UWSJob extends SerializableUWSObject { /** * Sets the time at which the job execution has finished. - * + * * @param newDateTime The end time of the execution of this job. */ protected final void setEndTime(Date newDateTime){ @@ -722,9 +722,9 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the duration (in seconds) for which this job shall run. - * + * * @return The execution duration of this job. - * + * * @see UWSParameters#getExecutionDuration() */ public final long getExecutionDuration(){ @@ -733,11 +733,11 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Sets the duration (in seconds) for which this job shall run ONLY IF the job can updated (considering its current execution phase, see {@link JobPhase#isJobUpdatable()}).</p> - * + * * <p><i><u>Note:</u> A duration of 0 (or less) implies unlimited execution duration.</i></p> - * + * * @param executionDuration The execution duration of this job. - * + * * @see UWSParameters#set(String, Object) */ public final void setExecutionDuration(long executionDuration){ @@ -752,9 +752,9 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the instant when the job shall be destroyed. - * + * * @return The destruction time of this job. - * + * * @see UWSParameters#getDestructionTime() */ public final Date getDestructionTime(){ @@ -766,9 +766,9 @@ public class UWSJob extends SerializableUWSObject { * Sets the instant when the job shall be destroyed ONLY IF the job can updated (considering its current execution phase, see {@link JobPhase#isJobUpdatable()}). * If known the jobs list is notify of this destruction time update. * </p> - * + * * @param destructionTime The destruction time of this job. <i>MUST NOT be NULL</i> - * + * * @see JobList#updateDestruction(UWSJob) * @see UWSParameters#set(String, Object) */ @@ -786,7 +786,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the error that occurs during the execution of this job. - * + * * @return A summary of the error. */ public final ErrorSummary getErrorSummary(){ @@ -795,14 +795,14 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Sets the error that occurs during the execution of this job.</p> - * + * * <p><b><u>IMPORTANT:</u> This function will have no effect if the job is finished, that is to say if the current phase is * {@link ExecutionPhase#ABORTED ABORTED}, {@link ExecutionPhase#ERROR ERROR} or {@link ExecutionPhase#COMPLETED COMPLETED}.</i>.</b></p> - * + * * @param errorSummary A summary of the error. <i>MUST NOT be NULL</i> - * + * * @throws UWSException If the job execution is finished that is to say if the phase is ABORTED, ERROR or COMPLETED. - * + * * @see #isFinished() */ public final void setErrorSummary(ErrorSummary errorSummary) throws UWSException{ @@ -818,7 +818,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the ID of this job (this ID <b>MUST</b> be unique). - * + * * @return The job ID (unique). */ public final String getJobId(){ @@ -828,11 +828,11 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Gets the RunID of this job given by the UWS user (presumed to be the owner of this job). * This ID isn't the one used to access to this job thanks to the jobs list: it is more likely a label/name than an ID => it is not unique.</p> - * + * * <p><b><u>Warning:</u> This ID may be used by other jobs BUT their job id (cf {@link UWSJob#getJobId()}) must be different.</b></p> - * + * * @return The Run ID (a kind of job name/label). - * + * * @see UWSParameters#getRunId() */ public final String getRunId(){ @@ -841,11 +841,11 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Sets the RunID of this job ONLY IF the job can updated (considering its current execution phase, see {@link JobPhase#isJobUpdatable()}).</p> - * + * * @param name Its name/label. - * + * * @see JobPhase#isJobUpdatable() - * + * * @see UWSParameters#set(String, Object) */ public final void setRunId(String name){ @@ -860,7 +860,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the owner of this job. - * + * * @return The owner. */ public final JobOwner getOwner(){ @@ -878,9 +878,9 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Sets the quote attribute of this job ONLY IF the job can updated (considering its current execution phase, see {@link JobPhase#isJobUpdatable()}).</p> - * + * * @param nbSeconds The estimated duration of the job execution (in seconds). - * + * * @see JobPhase#isJobUpdatable() */ public final void setQuote(long nbSeconds){ @@ -890,9 +890,9 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the list of parameters' name. - * + * * @return The additional parameters of this job. - * + * * @see UWSParameters#getNames() */ public final Set<String> getAdditionalParameters(){ @@ -901,7 +901,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the number of additional parameters. - * + * * @return Number of additional parameters. */ public final int getNbAdditionalParameters(){ @@ -910,7 +910,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the value of the specified additional parameter. - * + * * @param paramName The name of the parameter whose the value is wanted. * @return The value of the specified parameter or <i>null</i> if it doesn't exist. */ @@ -920,15 +920,15 @@ public class UWSJob extends SerializableUWSObject { /** * Adds or updates the specified parameter with the given value ONLY IF the job can be updated (considering its current execution phase, see {@link JobPhase#isJobUpdatable()}). - * + * * @param paramName The name of the parameter to add or to update. * @param paramValue The (new) value of the specified parameter. - * + * * @return <ul><li><i>true</i> if the parameter has been successfully added/updated,</li> * <li><i>false</i> otherwise <i>(particularly if paramName=null or paramName="" or paramValue=null)</i>.</li></ul> - * + * * @throws UWSException If a parameter value is incorrect. - * + * * @see JobPhase#isJobUpdatable() */ public final boolean addOrUpdateParameter(String paramName, Object paramValue) throws UWSException{ @@ -937,18 +937,18 @@ public class UWSJob extends SerializableUWSObject { /** * Adds or updates the specified parameter with the given value ONLY IF the job can be updated (considering its current execution phase, see {@link JobPhase#isJobUpdatable()}). - * + * * @param paramName The name of the parameter to add or to update. * @param paramValue The (new) value of the specified parameter. * @param user The user who asks for this update. - * + * * @return <ul><li><i>true</i> if the parameter has been successfully added/updated,</li> * <li><i>false</i> otherwise <i>(particularly if paramName=null or paramName="" or paramValue=null)</i>.</li></ul> - * + * * @throws UWSException If a parameter value is incorrect. - * + * * @since 4.1 - * + * * @see JobPhase#isJobUpdatable() */ public final boolean addOrUpdateParameter(String paramName, Object paramValue, final JobOwner user) throws UWSException{ @@ -982,20 +982,20 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Adds or updates the given parameters ONLY IF the job can be updated (considering its current execution phase, see {@link JobPhase#isJobUpdatable()}).</p> - * + * * <p>At the end of this function, the method {@link #applyPhaseParam(JobOwner)} is called so that if there is an additional parameter {@link #PARAM_PHASE} with the value: * <ul> * <li>{@link UWSJob#PHASE_RUN RUN} then the job is starting and the phase goes to {@link ExecutionPhase#EXECUTING EXECUTING}.</li> * <li>{@link UWSJob#PHASE_ABORT ABORT} then the job is aborting.</li> * <li>otherwise the parameter {@link UWSJob#PARAM_PHASE PARAM_PHASE} is removed from {@link UWSJob#inputParams inputParams} and nothing is done.</li> * </ul></p> - * + * * @param params A list of parameters to add/update. * @return <ul><li><i>true</i> if all the given parameters have been successfully added/updated,</li> * <li><i>false</i> if some parameters have not been managed.</li></ul> - * + * * @throws UWSException If a parameter value is incorrect. - * + * * @see #addOrUpdateParameters(UWSParameters, JobOwner) */ public boolean addOrUpdateParameters(UWSParameters params) throws UWSException{ @@ -1004,22 +1004,22 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Adds or updates the given parameters ONLY IF the job can be updated (considering its current execution phase, see {@link JobPhase#isJobUpdatable()}).</p> - * + * * <p>At the end of this function, the method {@link #applyPhaseParam(JobOwner)} is called so that if there is an additional parameter {@link #PARAM_PHASE} with the value: * <ul> * <li>{@link UWSJob#PHASE_RUN RUN} then the job is starting and the phase goes to {@link ExecutionPhase#EXECUTING EXECUTING}.</li> * <li>{@link UWSJob#PHASE_ABORT ABORT} then the job is aborting.</li> * <li>otherwise the parameter {@link UWSJob#PARAM_PHASE PARAM_PHASE} is removed from {@link UWSJob#inputParams inputParams} and nothing is done.</li> * </ul></p> - * + * * @param params The UWS parameters to update. * @param user The user who asks for this update. - * + * * @return <ul><li><i>true</i> if all the given parameters have been successfully added/updated,</li> * <li><i>false</i> if some parameters have not been managed.</li></ul> - * + * * @throws UWSException If a parameter value is incorrect or if the given user can not update or execute this job. - * + * * @see JobPhase#isJobUpdatable() * @see #applyPhaseParam(JobOwner) */ @@ -1065,11 +1065,11 @@ public class UWSJob extends SerializableUWSObject { /** * Removes the specified additional parameter ONLY IF the job can be updated (considering its current execution phase, see {@link JobPhase#isJobUpdatable()}). - * + * * @param paramName The name of the parameter to remove. - * + * * @return <i>true</i> if the parameter has been successfully removed, <i>false</i> otherwise. - * + * * @see JobPhase#isJobUpdatable() * @see UWSParameters#remove(String) */ @@ -1093,7 +1093,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the results list of this job. - * + * * @return An iterator on the results list. */ public final Iterator<Result> getResults(){ @@ -1102,9 +1102,9 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the specified result. - * + * * @param resultId ID of the result to return. - * + * * @return The corresponding result. */ public final Result getResult(String resultId){ @@ -1113,7 +1113,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the total number of results. - * + * * @return The number of results. */ public final int getNbResults(){ @@ -1122,15 +1122,15 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Adds the given result in the results list of this job.</p> - * + * * <p><b><u>IMPORTANT:</u> This function will throw an error if the job is finished.</b></p> - * + * * @param res The result to add (<b>not null</b>). - * + * * @return <i>true</i> if the result has been successfully added, <i>false</i> otherwise (for instance, if a result has the same ID). - * + * * @throws UWSException If the job execution is finished that is to say if the phase is ABORTED, ERROR or COMPLETED. - * + * * @see #isFinished() */ public boolean addResult(Result res) throws UWSException{ @@ -1154,10 +1154,10 @@ public class UWSJob extends SerializableUWSObject { /** * Get the additional information about this job. - * + * * @return Additional info. about this job, * or NULL if there is none. - * + * * @since 4.2 */ public final JobInfo getJobInfo(){ @@ -1166,25 +1166,25 @@ public class UWSJob extends SerializableUWSObject { /** * Set the additional information about this job. - * + * * <p><i>Note: * By default, this function replaces the current {@link 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 {@link UWSJob} in the used {@link UWSFactory}. * </i></p> - * + * * <p><b>Important note:</b> * When attributing a {@link JobInfo} to a {@link UWSJob}, you * may have to call {@link JobInfo#setJob(UWSJob)} on the former * and the new jobInfo (see the default implementation for an example) * for some implementations of {@link JobInfo}. * </p> - * + * * @param newJobInfo The new additional info. about this job. * <i>NULL is allowed and should be used to remove a * JobInfo from a job.</i> - * + * * @since 4.2 */ public void setJobInfo(final JobInfo newJobInfo){ @@ -1202,7 +1202,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the execution manager of this job, if any. - * + * * @return Its execution manager (may be <i>null</i>). */ public final ExecutionManager getExecutionManager(){ @@ -1211,7 +1211,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets its jobs list, if known. - * + * * @return Its jobs list (may be <i>null</i>). */ public final JobList getJobList(){ @@ -1220,15 +1220,15 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Sets its jobs list.</p> - * + * * <p><i><u>note 1:</u> a job can change its jobs list ONLY WHILE PENDING !</i></p> * <p><i><u>note 2:</u> this job is removed from its previous job list, if there is one.</i></p> * <p><i><u>note 3:</u> this job is NOT automatically added into the new jobs list. Indeed, this function should be called by {@link JobList#addNewJob(UWSJob)}.</i></p> - * + * * @param jobList Its new jobs list. <i><u>note:</u> if NULL, nothing is done !</i> - * + * * @throws IllegalStateException If this job is not PENDING. - * + * * @see JobList#removeJob(String) * @see JobList#getJob(String) */ @@ -1247,9 +1247,9 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the UWS URL of this job in function of its jobs list. - * + * * @return Its corresponding UWSUrl. - * + * * @see JobList#getUrl() * @see UWSUrl#jobSummary(String, String) */ @@ -1267,7 +1267,7 @@ public class UWSJob extends SerializableUWSObject { /* ******************** */ /** * Gets the time to wait for the end of the thread after an interruption. - * + * * @return The 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 long getTimeToWaitForEnd(){ @@ -1276,7 +1276,7 @@ public class UWSJob extends SerializableUWSObject { /** * Sets the time to wait for the end of the thread after an interruption. - * + * * @param 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 setTimeToWaitForEnd(long timeToWait){ @@ -1285,7 +1285,7 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Starts the job by using the execution manager if any.</p> - * + * * @throws UWSException */ public final void start() throws UWSException{ @@ -1294,14 +1294,14 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Starts the job.</p> - * + * * <p><i><u>Note:</u> This function does nothing if the job is already running !</i></p> - * + * * @param useManager <i>true</i> 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, <i>false</i> to start the execution immediately. - * + * * @throws 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. * @throws UWSException If there is an error while changing the execution phase or when starting the corresponding thread. - * + * * @see #isRunning() * @see UWSFactory#createJobThread(UWSJob) * @see ExecutionManager#execute(UWSJob) @@ -1346,7 +1346,7 @@ public class UWSJob extends SerializableUWSObject { /** * Stop/Cancel this job when its maximum execution duration has been reached. - * + * * @author Grégory Mantelet (CDS;ARI) * @version 4.1 (09/2014) */ @@ -1374,11 +1374,11 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Tells whether the job is still running.</p> - * + * * <p><i><u>Note:</u> This function tests the execution phase (see {@link JobPhase#isExecuting()}) AND the status of the thread (see {@link #isStopped()}).</i></p> - * + * * @return <i>true</i> if the job is still running, <i>false</i> otherwise. - * + * * @see JobPhase#isExecuting() * @see #isStopped() */ @@ -1388,11 +1388,11 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Tells whether the job is already finished (completed, aborted, error, ...).</p> - * + * * <p><i><u>Note:</u> This function test the execution phase (see {@link JobPhase#isFinished()}) AND the status of the thread (see {@link #isStopped()})</i></p> - * + * * @return <i>true</i> if the job is finished, <i>false</i> otherwise. - * + * * @see JobPhase#isFinished() * @see #isStopped() */ @@ -1402,12 +1402,12 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Stops immediately the job, sets its phase to {@link ExecutionPhase#ABORTED ABORTED} and sets its end time.</p> - * + * * <p><b><u>IMPORTANT:</u> 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 {@link #abort()}. * Besides you should check that you test regularly the interrupted flag of the thread in {@link JobThread#jobWork()} !</b></p> - * + * * @throws UWSException If there is an error while changing the execution phase. - * + * * @see #stop() * @see #isStopped() * @see #setPhase(ExecutionPhase) @@ -1432,15 +1432,15 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Stops immediately the job, sets its error summary, sets its phase to {@link ExecutionPhase#ERROR} and sets its end time.</p> - * + * * <p><b><u>IMPORTANT:</u> 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 {@link #error(ErrorSummary)}. * Besides you should check that you test regularly the interrupted flag of the thread in {@link JobThread#jobWork()} !</b></p> - * + * * @param error The error that has interrupted this job. - * + * * @throws UWSException If there is an error while setting the error summary or while changing the phase. - * + * * @see #stop() * @see #isStopped() * @see JobPhase#isFinished() @@ -1496,7 +1496,7 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Tells whether the thread is different from <i>null</i>, is not alive or is finished (see {@link JobThread#isFinished()}).</p> - * + * * <p><i><b>Important note:</b> * Having the interrupted flag set to <code>true</code> 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 {@link JobThread#jobWork()} does not @@ -1504,7 +1504,7 @@ public class UWSJob extends SerializableUWSObject { * considered as stopped/aborted - so the phase stays {@link ExecutionPhase#EXECUTING EXECUTING} - until the thread is "unblocked" * and the interruption is detected. * </i></p> - * + * * @return <i>true</i> if the thread is not still running, <i>false</i> otherwise. */ protected final boolean isStopped(){ @@ -1514,7 +1514,7 @@ public class UWSJob extends SerializableUWSObject { /** * <p>Stops the job if running, removes the job from the execution manager, stops the timer for the execution duration * and may clear all files or any other resources associated to this job.</p> - * + * * <p><i>By default the job is aborted, the {@link UWSJob#thread} attribute is set to null, the timers are stopped and uploaded files, results and the error summary are deleted and the jobInfo is destroyed.</i></p> */ public void clearResources(){ @@ -1581,9 +1581,9 @@ public class UWSJob extends SerializableUWSObject { /* ******************* */ /** * Lets adding an observer of this job. The observer will be notified each time the execution phase changes. - * + * * @param observer A new observer of this job. - * + * * @return <i>true</i> if the given object has been successfully added as observer of this job, <i>false</i> otherwise. */ public final boolean addObserver(JobObserver observer){ @@ -1596,7 +1596,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the total number of observers this job has. - * + * * @return Number of its observers. */ public final int getNbObservers(){ @@ -1605,7 +1605,7 @@ public class UWSJob extends SerializableUWSObject { /** * Gets the observers of this job. - * + * * @return An iterator on the list of its observers. */ public final Iterator<JobObserver> getObservers(){ @@ -1614,9 +1614,9 @@ public class UWSJob extends SerializableUWSObject { /** * Lets removing the given object from the list of observers of this job. - * + * * @param observer The object which must not be considered as observer of this job. - * + * * @return <i>true</i> if the given object is not any more an observer of this job, <i>false</i> otherwise. */ public final boolean removeObserver(JobObserver observer){ @@ -1632,26 +1632,14 @@ public class UWSJob extends SerializableUWSObject { /** * Notifies all the observer of this job that its phase has changed. - * + * * @param oldPhase The former phase of this job. * @throws UWSException If at least one observer can not have been updated. */ public final void notifyObservers(ExecutionPhase oldPhase){ - int i = 0; - JobObserver observer = null; String errors = null; - while(i < observers.size()){ - // Gets the observer: - if (i == 0 && observer == null) - observer = observers.get(i); - else if (observer.equals(observers.get(i))){ - i++; - if (i < observers.size()) - observer = observers.get(i); - else - return; - } + for(JobObserver observer : observers){ // Update this observer: try{ observer.update(this, oldPhase, getPhase()); @@ -1672,11 +1660,11 @@ public class UWSJob extends SerializableUWSObject { /* **************** */ /** * <p>Gets the error (if any) which has occurred during the job execution.</p> - * + * * <p><i><u>Note:</u> In the case an error summary can not have been published, the job has no error summary. * However the last {@link UWSException} caught during the execution of a {@link JobThread} is saved and is available thanks to {@link JobThread#getError()}. * In that case, the {@link UWSJob#getWorkError() getWorkError()} method can be used to get back the occurred error.</i></p> - * + * * @return The error which interrupts the thread or <i>null</i> if there was no error or if the job is still running. */ public final UWSException getWorkError(){ @@ -1696,14 +1684,14 @@ public class UWSJob extends SerializableUWSObject { /** * Serializes the specified attribute of this job by using the given serializer. - * + * * @param attributes All the given attributes (may be <i>null</i> or empty). * @param serializer The serializer to use. - * + * * @return The serialized job attribute (or the whole job if <i>attributes</i> is an empty array or is <i>null</i>). - * + * * @throws Exception If there is an unexpected error during the serialization. - * + * * @see UWSSerializer#getJob(UWSJob, String[], boolean) */ public String serialize(String[] attributes, UWSSerializer serializer) throws Exception{ @@ -1712,13 +1700,13 @@ public class UWSJob extends SerializableUWSObject { /** * Serializes the specified attribute of this job in the given output stream by using the given serializer. - * + * * @param output The output stream in which the job attribute must be serialized. * @param attributes The name of the attribute to serialize (if <i>null</i>, the whole job will be serialized). * @param serializer The serializer to use. - * + * * @throws Exception If there is an unexpected error during the serialization. - * + * * @see #serialize(String[], UWSSerializer) */ public void serialize(ServletOutputStream output, String[] attributes, UWSSerializer serializer) throws UWSException, IOException, Exception{ @@ -1753,9 +1741,9 @@ public class UWSJob extends SerializableUWSObject { /** * <p>2 instances of AbstractJob are equals ONLY IF their ID are equals.</p> - * + * * <p><i><u>Note:</u> If the given object is not an AbstractJob, FALSE is returned.</i></p> - * + * * @see java.lang.Object#equals(java.lang.Object) */ @Override