/** * Returns a copy of this job config that will use the specified schedule * instead of what it currently uses. * * @param schedule the new schedule; may be {@code null}, in which case the default * {@link Schedule#runOnce(Date) runOnce(new Date())} is used * @return the new job configuration; the original is left unchanged */ public JobConfig withSchedule(Schedule schedule) { return new JobConfig(jobRunnerKey, runMode, schedule, parameters); }
/** * Returns a copy of this job config that will use the specified run mode * instead of what it currently uses. * * @param runMode the new run mode; may be {@code null}, in which case the default * {@link RunMode#RUN_ONCE_PER_CLUSTER} is used * @return the new job configuration; the original is left unchanged */ public JobConfig withRunMode(RunMode runMode) { return new JobConfig(jobRunnerKey, runMode, schedule, parameters); }
/** * Returns a copy of this job config that will use the specified parameters * instead of what it currently uses. * <p> * <strong>WARNING</strong>: The parameters map must be serializable, so all of its * contents must be as well. Using objects that are not serializable, even as data * members of objects that are themselves serializable, will usually fail. Developers * are encouraged to limit the information stored here to a few simple keys for * accessing the runtime data that is needed instead of storing large objects, * injectable components, etc. in the {@code parameters} map. * </p> * <p> * <strong>WARNING</strong>: The scheduler service assumes that the objects within the * {@code parameters} map are immutable. Modifying objects after they have been added * to the parameters map may have unpredictable results. * </p> * * @param parameters the new parameters; may be {@code null}, in which case the * {@link JobRunner} is provided with an empty map at run time. The map * should contain only immutable, serializable data * @return the new job configuration; the original is left unchanged */ public JobConfig withParameters(@Nullable Map<String, Serializable> parameters) { return new JobConfig(jobRunnerKey, runMode, schedule, copy(parameters)); }
/** * Creates a new job configuration for the specified job runner key. * <p> * By default, the job configuration will assume: * </p> * <ul> * <li><code>{@link #withRunMode(RunMode) withRunMode}({@link RunMode#RUN_ONCE_PER_CLUSTER})</code></li> * <li><code>{@link #withSchedule(Schedule) withSchedule}({@link Schedule#runOnce(Date) Schedule.runOnce}(new Date()))</code></li> * <li><code>{@link #withParameters(Map) withParameters}(null)</code></li> * </ul> * <p> * Any of which may be overridden by calling the appropriate method. Note that chaining the * methods is recommended, as these methods return an altered copy rather than modifiying the * original {@code JobConfig} in place. For example, use: * </p> * <pre><code> * JobConfig config = JobConfig.forJobRunnerKey("myJobToDoImportantThings") * .withSchedule(Schedule.forInterval(Date, long)) * .withRunMode(RunMode.RUN_LOCALLY); * </code></pre> * * @param jobRunnerKey the unique identifier used to * {@link SchedulerService#registerJobRunner(JobRunnerKey, JobRunner) register} * the {@link JobRunner} * @return a job configuration for the specified job runner key that will use the default settings */ public static JobConfig forJobRunnerKey(JobRunnerKey jobRunnerKey) { requireNonNull(jobRunnerKey, "jobRunnerKey"); return new JobConfig(jobRunnerKey, RUN_ONCE_PER_CLUSTER, Schedule.runOnce(null), NO_PARAMETERS); }