/** * 从队列中删除已运行的作业. * * @param taskContexts 任务上下文集合 */ public void removeLaunchTasksFromQueue(final List<TaskContext> taskContexts) { List<TaskContext> failoverTaskContexts = new ArrayList<>(taskContexts.size()); Collection<String> misfiredJobNames = new HashSet<>(taskContexts.size(), 1); Collection<String> readyJobNames = new HashSet<>(taskContexts.size(), 1); for (TaskContext each : taskContexts) { switch (each.getType()) { case FAILOVER: failoverTaskContexts.add(each); break; case MISFIRED: misfiredJobNames.add(each.getMetaInfo().getJobName()); break; case READY: readyJobNames.add(each.getMetaInfo().getJobName()); break; default: break; } } failoverService.remove( Lists.transform( failoverTaskContexts, new Function<TaskContext, TaskContext.MetaInfo>() { @Override public TaskContext.MetaInfo apply(final TaskContext input) { return input.getMetaInfo(); } })); misfiredService.remove(misfiredJobNames); readyService.remove(readyJobNames); }
/** * 获取有资格运行的作业. * * @return 作业上下文集合 */ public Collection<JobContext> getEligibleJobContext() { Collection<JobContext> failoverJobContexts = failoverService.getAllEligibleJobContexts(); Collection<JobContext> misfiredJobContexts = misfiredService.getAllEligibleJobContexts(failoverJobContexts); Collection<JobContext> ineligibleJobContexts = new ArrayList<>(failoverJobContexts.size() + misfiredJobContexts.size()); ineligibleJobContexts.addAll(failoverJobContexts); ineligibleJobContexts.addAll(misfiredJobContexts); Collection<JobContext> readyJobContexts = readyService.getAllEligibleJobContexts(ineligibleJobContexts); Collection<JobContext> result = new ArrayList<>( failoverJobContexts.size() + misfiredJobContexts.size() + readyJobContexts.size()); result.addAll(failoverJobContexts); result.addAll(misfiredJobContexts); result.addAll(readyJobContexts); return result; }