com.alibaba.dts.client.executor.grid.GridJobManager Maven / Gradle / Ivy
package com.alibaba.dts.client.executor.grid;
import com.alibaba.dts.client.executor.grid.timer.JobInstanceMapCleaner;
import com.alibaba.dts.client.executor.job.context.ClientContextImpl;
import com.alibaba.dts.common.logger.SchedulerXLoggerFactory;
import com.alibaba.dts.common.logger.innerlog.Logger;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Ronan Zhan
* @date 2018/2/5
*/
public class GridJobManager {
private static final Logger logger = SchedulerXLoggerFactory.getLogger(GridJobManager.class);
private volatile ConcurrentHashMap interruptedJobInstanceMap = new ConcurrentHashMap();
private JobInstanceMapCleaner jobInstanceMapCleaner;
private ClientContextImpl clientContext;
public GridJobManager(ClientContextImpl clientContext) {
this.clientContext = clientContext;
}
public ConcurrentHashMap getInterruptedJobInstanceMap() {
return interruptedJobInstanceMap;
}
public boolean addInterruptedJobInstance(long jobInstanceId) {
interruptedJobInstanceMap.putIfAbsent(jobInstanceId, System.currentTimeMillis());
logger.info("[GridJobManager]: addInterruptedInstance instanceId:" + jobInstanceId);
return true;
}
public boolean containsInterruptedJobInstance(long jobInstanceId) {
return interruptedJobInstanceMap.containsKey(jobInstanceId);
}
public boolean removeInterruptedJobInstance(long jobInstanceId) {
interruptedJobInstanceMap.remove(jobInstanceId);
logger.info("[GridJobManager]: removeInterceptInstance instanceId=" + jobInstanceId);
return true;
}
public void init() {
jobInstanceMapCleaner = new JobInstanceMapCleaner(clientContext);
jobInstanceMapCleaner.init();
}
}