Class AbstractJobUnit

java.lang.Object
com.polarion.platform.jobs.spi.AbstractJobUnit
All Implemented Interfaces:
IJobUnit

public abstract class AbstractJobUnit extends Object implements IJobUnit
Abstract base for IJobUnits.

Author:
Stepan Roh, Polarion Software
  • Constructor Details

  • Method Details

    • getCreator

      public IJobUnitFactory getCreator()
      Description copied from interface: IJobUnit
      Return factory used for creation of this job unit.

      Job unit can not exist without factory.

      Specified by:
      getCreator in interface IJobUnit
      Returns:
      factory (not null)
    • getName

      public String getName()
      Description copied from interface: IJobUnit
      Job name.
      Specified by:
      getName in interface IJobUnit
      Returns:
      job name (not null)
    • getJob

      public IJob getJob()
      Description copied from interface: IJobUnit
      Associated IJob.

      Will be null until IJobManager.spawnJob(IJobUnit, IJob) is called.

      Specified by:
      getJob in interface IJobUnit
      Returns:
      IJob or null
    • setJob

      public void setJob(IJob job)
      Description copied from interface: IJobUnit
      Set associated IJob.
      Specified by:
      setJob in interface IJobUnit
      Parameters:
      job - associated job
    • activate

      public void activate() throws GenericJobException
      Description copied from interface: IJobUnit
      Activate job.

      Implementation should:

      • call getJob().addResource() for any resources it wants to lock
      • compute work length for getWorkLength()
      • spawn jobs which it depends on

      No resources which need manual destruction should be allocated.

      Throwing exception from this method will stop the scheduling process and no jobs will be run.

      Specified by:
      activate in interface IJobUnit
      Throws:
      GenericJobException - if error occurs
    • getWorkLength

      public int getWorkLength()
      Description copied from interface: IJobUnit
      Return number of ticks IJobUnit.run(IProgressMonitor) is expected to take.

      Allows for precise computation of progress bar.

      Specified by:
      getWorkLength in interface IJobUnit
      Returns:
      number of ticks (greater or equal to zero or IJobUnit.UNKNOWN_WORK_LENGTH)
    • getPriority

      public int getPriority()
      Description copied from interface: IJobUnit
      Return requested priority (is taken as an advise for IJob.getPriority().

      Return zero for "normal" priority.

      Specified by:
      getPriority in interface IJobUnit
      Returns:
      requested priority
    • setWorkDir

      public void setWorkDir(File workDir)
      Description copied from interface: IJobUnit
      System job parameter: working directory.

      May be shared with other jobs with same root job. Working directory of one root job must be different from working directories of other root jobs.

      Set automatically for root job by job manager, must be set manually for jobs with parent.

      Specified by:
      setWorkDir in interface IJobUnit
      Parameters:
      workDir - working directory
    • getWorkDir

      public File getWorkDir()
      Returns associated working directory.
      Returns:
      work dir or null
    • setLogger

      public void setLogger(ILogger logger)
      Description copied from interface: IJobUnit
      System job parameter: logger.

      Set automatically for all jobs by job manager.

      Logger will contain at least all logged events from child jobs when produced (but may contain more).

      It is advised to output logged messages to some file in workdir besides other targets.

      Specified by:
      setLogger in interface IJobUnit
      Parameters:
      logger - logger
      See Also:
    • getLogger

      public ILogger getLogger()
      Description copied from interface: IJobUnit
      System job parameter: logger.
      Specified by:
      getLogger in interface IJobUnit
      Returns:
      logger (not null if running)
      See Also:
    • setScope

      public void setScope(IContext context)
      Description copied from interface: IJobUnit
      Job parameter: job scope.

      Value of null (or if it is missing) means both "global scope" and "I don't care" (depends on invoked job).

      Specified by:
      setScope in interface IJobUnit
      Parameters:
      context - scope of this job (may be null)
      See Also:
    • getScope

      public IContext getScope()
      Description copied from interface: IJobUnit
      Job parameter: job scope.
      Specified by:
      getScope in interface IJobUnit
      Returns:
      scope of this job or null
      See Also:
    • run

      public IJobStatus run(IProgressMonitor progress)
      Description copied from interface: IJobUnit
      Run job.

      Method must not return before the job completes its execution even if it handles some work in separate threads.

      Children spawned during IJobUnit.activate() (if this job was given as their parent) will all finish prior to execution of this method.

      Supplied progress monitor should be prepared for IJobUnit.getWorkLength() ticks. It will ignore totalWork parameter supplied to IProgressMonitor.beginTask(String, int).

      Returned status may (or may not) be multi-status (or otherwise reflect status) of getJob().getChildren().

      If progress monitor is cancelled, IJobStatus.JobStatusType.STATUS_TYPE_CANCELLED must be returned as early as possible.

      Although job manager will catch any exception thrown from this method and interpret it as IJobStatus.JobStatusType.STATUS_TYPE_FAILED it is recommended to wrap any exception (other than those listed here) as returned status.

      Specified by:
      run in interface IJobUnit
      Parameters:
      progress - progress monitor to use
      Returns:
      IJobStatus (not null)