|
| 1 | +/* |
| 2 | + * Copyright 2006-2022 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.batch.core.job; |
| 18 | + |
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.LinkedHashSet; |
| 21 | +import java.util.List; |
| 22 | +import java.util.Set; |
| 23 | + |
| 24 | +import io.micrometer.core.instrument.MeterRegistry; |
| 25 | +import io.micrometer.observation.ObservationRegistry; |
| 26 | + |
| 27 | +import org.springframework.batch.core.Job; |
| 28 | +import org.springframework.batch.core.JobExecutionListener; |
| 29 | +import org.springframework.batch.core.JobParametersIncrementer; |
| 30 | +import org.springframework.batch.core.JobParametersValidator; |
| 31 | +import org.springframework.batch.core.repository.JobRepository; |
| 32 | + |
| 33 | +/** |
| 34 | + * A common properties for {@link Job}. |
| 35 | + * |
| 36 | + * @author Taeik Lim |
| 37 | + */ |
| 38 | +public class CommonJobProperties { |
| 39 | + |
| 40 | + private String name; |
| 41 | + |
| 42 | + private boolean restartable = true; |
| 43 | + |
| 44 | + private JobRepository jobRepository; |
| 45 | + |
| 46 | + private ObservationRegistry observationRegistry; |
| 47 | + |
| 48 | + private MeterRegistry meterRegistry; |
| 49 | + |
| 50 | + private JobParametersIncrementer jobParametersIncrementer; |
| 51 | + |
| 52 | + private JobParametersValidator jobParametersValidator; |
| 53 | + |
| 54 | + private Set<JobExecutionListener> jobExecutionListeners = new LinkedHashSet<>(); |
| 55 | + |
| 56 | + public CommonJobProperties() { |
| 57 | + } |
| 58 | + |
| 59 | + public CommonJobProperties(CommonJobProperties properties) { |
| 60 | + this.name = properties.name; |
| 61 | + this.restartable = properties.restartable; |
| 62 | + this.jobRepository = properties.jobRepository; |
| 63 | + this.observationRegistry = properties.observationRegistry; |
| 64 | + this.meterRegistry = properties.meterRegistry; |
| 65 | + this.jobParametersIncrementer = properties.jobParametersIncrementer; |
| 66 | + this.jobParametersValidator = properties.jobParametersValidator; |
| 67 | + this.jobExecutionListeners = new LinkedHashSet<>(properties.jobExecutionListeners); |
| 68 | + } |
| 69 | + |
| 70 | + public String getName() { |
| 71 | + return name; |
| 72 | + } |
| 73 | + |
| 74 | + public void setName(String name) { |
| 75 | + this.name = name; |
| 76 | + } |
| 77 | + |
| 78 | + public boolean getRestartable() { |
| 79 | + return restartable; |
| 80 | + } |
| 81 | + |
| 82 | + public void setRestartable(boolean restartable) { |
| 83 | + this.restartable = restartable; |
| 84 | + } |
| 85 | + |
| 86 | + public JobRepository getJobRepository() { |
| 87 | + return jobRepository; |
| 88 | + } |
| 89 | + |
| 90 | + public void setJobRepository(JobRepository jobRepository) { |
| 91 | + this.jobRepository = jobRepository; |
| 92 | + } |
| 93 | + |
| 94 | + public ObservationRegistry getObservationRegistry() { |
| 95 | + return observationRegistry; |
| 96 | + } |
| 97 | + |
| 98 | + public void setObservationRegistry(ObservationRegistry observationRegistry) { |
| 99 | + this.observationRegistry = observationRegistry; |
| 100 | + } |
| 101 | + |
| 102 | + public MeterRegistry getMeterRegistry() { |
| 103 | + return meterRegistry; |
| 104 | + } |
| 105 | + |
| 106 | + public void setMeterRegistry(MeterRegistry meterRegistry) { |
| 107 | + this.meterRegistry = meterRegistry; |
| 108 | + } |
| 109 | + |
| 110 | + public JobParametersIncrementer getJobParametersIncrementer() { |
| 111 | + return jobParametersIncrementer; |
| 112 | + } |
| 113 | + |
| 114 | + public void setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer) { |
| 115 | + this.jobParametersIncrementer = jobParametersIncrementer; |
| 116 | + } |
| 117 | + |
| 118 | + public JobParametersValidator getJobParametersValidator() { |
| 119 | + return jobParametersValidator; |
| 120 | + } |
| 121 | + |
| 122 | + public void setJobParametersValidator(JobParametersValidator jobParametersValidator) { |
| 123 | + this.jobParametersValidator = jobParametersValidator; |
| 124 | + } |
| 125 | + |
| 126 | + public List<JobExecutionListener> getJobExecutionListeners() { |
| 127 | + return new ArrayList<>(jobExecutionListeners); |
| 128 | + } |
| 129 | + |
| 130 | + public void addJobExecutionListener(JobExecutionListener jobExecutionListener) { |
| 131 | + this.jobExecutionListeners.add(jobExecutionListener); |
| 132 | + } |
| 133 | + |
| 134 | +} |
0 commit comments