Package com.sodius.oslc.server.core.jobs
Class Job.Builder
java.lang.Object
com.sodius.oslc.server.core.jobs.Job.Builder
- Enclosing class:
Job
A builder of
Job.- Since:
- 3.11.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds a newJobinstance.final Job.BuilderconfigProvider(Function<Job, JobConfig> configProvider) Registers a function to create aJobConfigresource describing a given job to administrators.protected abstract JobCreates a job with the information set on this builder.protected final StringgetId()Returns the job identifier.protected final JobRunnerReturns the job runner.protected final booleanDetermines whether the job to build must run on only one node of the cluster each time that it triggers.final Job.BuilderRegisters the runner to use for executing the job.final Job.BuilderscheduleValidator(Function<JobSchedule, String> validator) Registers a function to validate a schedule edited by an administrator is appropriate for this job.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
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
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
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:
-
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
Returns the job runner.- Returns:
- the job runner
-
build
Builds a newJobinstance.- Returns:
- a new Job instance
- Throws:
IllegalStateException- if no runner was set
-
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
-