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 Jobbuild()Builds a newJobinstance.Job.BuilderconfigProvider(Function<Job,JobConfig> configProvider)Registers a function to create aJobConfigresource describing a given job to administrators.protected abstract JobcreateJob()Creates a job with the information set on this builder.protected StringgetId()Returns the job identifier.protected JobRunnergetRunner()Returns the job runner.protected booleanisCluster()Determines whether the job to build must run on only one node of the cluster each time that it triggers.Job.Builderrunner(JobRunner runner)Registers the runner to use for executing the job.Job.BuilderscheduleValidator(Function<JobSchedule,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(Function<Job,JobConfig> configProvider)
Registers a function to create aJobConfigresource 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
Jobto describe and should useLocalesto determine the preferred locale. It must return an instance ofJobConfigwith following values:title: a short label, e.g."TRS Repair".description: the purpose of the job and its schedule. TheJobs.getDescription(String, JobSchedule)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
idandscheduleare 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
- Since:
- 3.12.0
-
scheduleValidator
public final Job.Builder scheduleValidator(Function<JobSchedule,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
JobSchedulethat was edited and should useLocalesto determine the preferred locale. If the schedule is appropriate, the function shall returnnullor 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
- Since:
- 3.12.0
- 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:
trueif 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 newJobinstance.- 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
-
-