Package com.sodius.oslc.server.core.jobs
Class Job.Builder
- java.lang.Object
-
- com.sodius.oslc.server.core.jobs.Job.Builder
-
- Enclosing class:
- Job
public abstract static class Job.Builder extends Object
A builder ofJob
.- Since:
- 3.11.0
- See Also:
JobScheduler.clusterJob(String)
,JobScheduler.localJob(String)
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Job
build()
Builds a newJob
instance.Job.Builder
configProvider(BiFunction<Job,List<Locale>,JobConfig> configProvider)
Registers a function to create aJobConfig
resource describing a given job to administrators.protected abstract Job
createJob()
Creates a job with the information set on this builder.protected String
getId()
Returns the job identifier.protected JobRunner
getRunner()
Returns the job runner.protected boolean
isCluster()
Determines whether the job to build must run on only one node of the cluster each time that it triggers.Job.Builder
runner(JobRunner runner)
Registers the runner to use for executing the job.Job.Builder
scheduleValidator(BiFunction<JobSchedule,List<Locale>,String> validator)
Registers a function to validate a schedule edited by an administrator is appropriate for this job.
-
-
-
Method Detail
-
runner
public final Job.Builder runner(JobRunner runner)
Registers the runner to use for executing the job.- Parameters:
runner
- the job runner- Returns:
- this builder instance
- Throws:
NullPointerException
- if runner is null
-
configProvider
public final Job.Builder configProvider(BiFunction<Job,List<Locale>,JobConfig> configProvider)
Registers a function to create aJobConfig
resource describing a given job to administrators. If no function is set on the builder, a default one will be used.The function is given the
Job
to describe and the locales to use, in decreasing order starting with the preferred locale. It must return an instance ofJobConfig
with following values:title
: a short label, e.g."TRS Repair"
.description
: the purpose of the job and its schedule. TheJobs.getDescription(String, JobSchedule, List)
method is helpful to only provide a short description of the job (e.g."Repairing all TRS feeds"
) and have it complemented with the current schedule.feedback
: if an information or warning is to report to administrators, notably if the schedule information necessitates attention.
The
id
andschedule
are automatically assigned by the framework, the function does not need to handle them.- Parameters:
configProvider
- a function to create a configuration describing a job- Returns:
- this builder instance
-
scheduleValidator
public final Job.Builder scheduleValidator(BiFunction<JobSchedule,List<Locale>,String> validator)
Registers a function to validate a schedule edited by an administrator is appropriate for this job. If no validation function is set, the schedule of the job cannot be edited by administrators.The validation function is given the
JobSchedule
that was edited and the locales to use, in decreasing order starting with the preferred locale. If the schedule is appropriate, the function shall returnnull
or an empty string, which will make the new schedule to be applied. Otherwise it must return an error message detailing why the schedule is rejected.- Parameters:
validator
- a function to validate the given schedule- Returns:
- this builder instance
- See Also:
Jobs.rejectFixedDelaySchedule()
,Jobs.rejectFixedRateSchedule()
-
getId
protected final String getId()
Returns the job identifier.- Returns:
- the job identifier
-
isCluster
protected final boolean isCluster()
Determines whether the job to build must run on only one node of the cluster each time that it triggers.- Returns:
true
if the job must run on only one node of the cluster each time that it triggers
-
getRunner
protected final JobRunner getRunner()
Returns the job runner.- Returns:
- the job runner
-
build
public Job build()
Builds a newJob
instance.- Returns:
- a new Job instance
- Throws:
IllegalStateException
- if no runner was set
-
createJob
protected abstract Job createJob()
Creates a job with the information set on this builder. All settings are known to be valid at this point.- Returns:
- a new job instance
-
-