Interface IJobUnit
- All Known Subinterfaces:
IBranchDocumentsJob
,ICleanJobUnit
,ICleanupJobUnit
,IExecuteCommandJobUnit
,ILogsCleanupJobUnit
,IMasterBuildJobUnit
,IMultiJobUnit
,IProjectManagementJobUnit
,ISyncUserGroupsJobUnit
,ISyncUsersJobUnit
,ITestResultsImportJobUnit
- All Known Implementing Classes:
AbstractJobUnit
This represents the user-implemented portion of IJob
encapsulating the work done on
behalf of the job.
None of the methods on this interface are intended to be called by clients.
Job unit is one-time class, once run, it is thrown away.
WARNING: If this interface is used on a cluster node other than that on which the job runs,
clients can call only methods that return serializable results and take only serializable (or no) arguments.
This holds also for methods on all interfaces that the custom job unit may implement.
The only exception is method getLogger()
which can be used remotely, but the only methods
that can be used on the returned logger are ILogger.getLogFile()
and ILogger.getLogFiles()
.
- Author:
- Stepan Roh, Polarion Software
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Value forgetWorkLength()
indicating unknown work length. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Activate job.Return factory used for creation of this job unit.getJob()
AssociatedIJob
.System job parameter: logger.getName()
Job name.int
Return requested priority (is taken as an advise forIJob.getPriority()
.getScope()
Job parameter: job scope.int
Return number of ticksrun(IProgressMonitor)
is expected to take.run
(IProgressMonitor progress) Run job.void
Set associatedIJob
.void
System job parameter: logger.void
Job parameter: job scope.void
setWorkDir
(File workDir) System job parameter: working directory.
-
Field Details
-
UNKNOWN_WORK_LENGTH
static final int UNKNOWN_WORK_LENGTHValue forgetWorkLength()
indicating unknown work length.- Since:
- 3.3.0
- See Also:
-
-
Method Details
-
getCreator
IJobUnitFactory getCreator()Return factory used for creation of this job unit.Job unit can not exist without factory.
- Returns:
- factory (not
null
)
-
getName
String getName()Job name.- Returns:
- job name (not
null
)
-
getJob
IJob getJob()AssociatedIJob
.Will be
null
untilIJobManager.spawnJob(IJobUnit, IJob)
is called.- Returns:
IJob
ornull
-
setJob
Set associatedIJob
.- Parameters:
job
- associated job- Throws:
IllegalArgumentException
- if job isnull
IllegalStateException
- if job was already associated
-
activate
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.
- Throws:
IllegalStateException
- if already calledIllegalStateException
- if no job is associated (getJob()
isnull
)GenericJobException
- if error occurs
-
run
Run job.Method must not return before the job completes its execution even if it handles some work in separate threads.
Children spawned during
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
getWorkLength()
ticks. It will ignoretotalWork
parameter supplied toIProgressMonitor.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.- Parameters:
progress
- progress monitor to use- Returns:
IJobStatus
(not null)- Throws:
IllegalArgumentException
- if progress isnull
IllegalStateException
- if called beforeactivate()
IllegalStateException
- if already calledIllegalStateException
- if no job is associated (getJob()
isnull
)
-
getWorkLength
int getWorkLength()Return number of ticksrun(IProgressMonitor)
is expected to take.Allows for precise computation of progress bar.
- Returns:
- number of ticks (greater or equal to zero or
UNKNOWN_WORK_LENGTH
) - Throws:
IllegalStateException
- if called beforeactivate()
-
getPriority
int getPriority()Return requested priority (is taken as an advise forIJob.getPriority()
.Return zero for "normal" priority.
- Returns:
- requested priority
-
setWorkDir
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.
- Parameters:
workDir
- working directory- Throws:
IllegalArgumentException
- if workDir isnull
-
setLogger
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.
- Parameters:
logger
- logger- Throws:
IllegalArgumentException
- if logger isnull
- See Also:
-
getLogger
ILogger getLogger()System job parameter: logger.- Returns:
- logger (not
null
if running) - See Also:
-
setScope
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).- Parameters:
context
- scope of this job (may benull
)- See Also:
-
getScope
IContext getScope()Job parameter: job scope.- Returns:
- scope of this job or
null
- See Also:
-