Class Job.Builder

    • Constructor Detail

      • Builder

        public Builder()
    • 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 a JobConfig 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 of JobConfig with following values:

        • title: a short label, e.g. "TRS Repair".
        • description: the purpose of the job and its schedule. The Jobs.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 and schedule 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 return null 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 new Job 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