![JAR search and dependency download from the Maven repository](/logo.png)
indi.atlantis.framework.chaconne.cluster.ProducerModeJobExecutor Maven / Gradle / Ivy
/**
* Copyright 2017-2021 Fred Feng ([email protected])
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package indi.atlantis.framework.chaconne.cluster;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.paganini2008.devtools.StringUtils;
import indi.atlantis.framework.chaconne.Job;
import indi.atlantis.framework.chaconne.JobException;
import indi.atlantis.framework.chaconne.JobExecutor;
import indi.atlantis.framework.chaconne.JobKey;
import indi.atlantis.framework.chaconne.JobManager;
import indi.atlantis.framework.chaconne.JobListenerContainer;
import indi.atlantis.framework.chaconne.JobState;
import indi.atlantis.framework.chaconne.JobTemplate;
import indi.atlantis.framework.chaconne.RunningState;
import indi.atlantis.framework.chaconne.ScheduleManager;
import indi.atlantis.framework.chaconne.StopWatch;
import indi.atlantis.framework.chaconne.TraceIdGenerator;
/**
*
* ProducerModeJobExecutor
*
* @author Fred Feng
*
* @since 2.0.1
*/
public class ProducerModeJobExecutor extends JobTemplate implements JobExecutor {
@Autowired
private ScheduleManager scheduleManager;
@Autowired
private JobManager jobManager;
@Autowired
private StopWatch stopWatch;
@Autowired
private TraceIdGenerator idGenerator;
@Autowired
private JobListenerContainer jobListenerContainer;
@Override
protected long getTraceId(JobKey jobKey) {
return idGenerator.generateTraceId(jobKey);
}
@Override
public void execute(Job job, Object attachment, int retries) {
runJob(job, attachment, retries);
}
@Override
protected void beforeRun(long traceId, JobKey jobKey, Job job, Object attachment, Date startDate) {
super.beforeRun(traceId, jobKey, job, attachment, startDate);
jobListenerContainer.beforeRun(traceId, jobKey, job, attachment, startDate);
stopWatch.onJobBegin(traceId, jobKey, startDate);
}
@Override
protected boolean isScheduling(JobKey jobKey, Job job) {
try {
return jobManager.hasJobState(jobKey, JobState.SCHEDULING);
} catch (Exception e) {
throw new JobException(e.getMessage(), e);
}
}
@Override
protected void cancel(JobKey jobKey, Job job, RunningState runningState, String msg, Throwable reason) {
try {
scheduleManager.unscheduleJob(jobKey);
jobManager.finishJob(jobKey);
} catch (Exception e) {
throw new JobException(e.getMessage(), e);
}
if (StringUtils.isNotBlank(msg)) {
log.info(msg);
}
if (reason != null) {
log.error(reason.getMessage(), reason);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy