微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.quartz.InterruptableJob的实例源码

项目:lams    文件QuartzScheduler.java   
/**
 * Interrupt the identified InterruptableJob executing in this Scheduler instance.
 *  
 * <p>
 * This method is not cluster aware.  That is,it will only interrupt 
 * instances of the identified InterruptableJob currently executing in this 
 * Scheduler instance,not across the entire cluster.
 * </p>
 * 
 * @see org.quartz.core.RemotableQuartzScheduler#interrupt(JobKey)
 */
public boolean interrupt(String fireInstanceId) throws UnabletoInterruptJobException {
    List<JobExecutionContext> jobs = getCurrentlyExecutingJobs();

    Job job = null;

    for(JobExecutionContext jec : jobs) {
        if (jec.getFireInstanceId().equals(fireInstanceId)) {
            job = jec.getJobInstance();
            if (job instanceof InterruptableJob) {
                ((InterruptableJob)job).interrupt();
                return true;
            } else {
                throw new UnabletoInterruptJobException(
                    "Job " + jec.getJobDetail().getKey() +
                    " can not be interrupted,since it does not implement " +                        
                    InterruptableJob.class.getName());
            }
        }                        
    }

    return false;
}
项目:citrine-scheduler    文件TaskRunManagerImpl.java   
@Override
public boolean stop(long taskRunId) {
  TaskRun taskRun = taskRunDAO.get(taskRunId);
  long taskId = taskRun.getTaskId();

  JobExecutionContext context = runningTasks.get(taskId);
  if (context == null) { // there is no task run
    return false;
  }
  Job runningJob = context.getJobInstance();
  if (runningJob instanceof InterruptableJob) {
    try {
      log.info("Interrupting TaskRun " + taskRunId + " for Task " + taskId);
      setStatus(taskRun,Status.CANCELLING);
      taskRunDAO.save(taskRun);

      ((InterruptableJob) runningJob).interrupt();
      runningTasks.remove(taskId);

      return true;
    } catch (UnabletoInterruptJobException e) {
      log.error("Unable to interrupt TaskRun " + taskRunId + " for Task " + taskId,e);
    }
  }
  return false;
}
项目:sakai    文件JobExecutionContextwrapperBean.java   
public String processActionKill() {
    if (getIsKillable()) {
        InterruptableJob job = (InterruptableJob)jec.getJobInstance();
        try {
            job.interrupt();
        } catch (UnabletoInterruptJobException e) {
            log.error(e.getMessage(),e);
        }
        FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO,parentTool.rb.getFormattedMessage("kill_message",new String[] {jec.getJobDetail().getKey().getName()}),null));
    }

    return "runningJobs";
}
项目:lams    文件QuartzScheduler.java   
/**
 * Interrupt all instances of the identified InterruptableJob executing in 
 * this Scheduler instance.
 *  
 * <p>
 * This method is not cluster aware.  That is,not across the entire cluster.
 * </p>
 * 
 * @see org.quartz.core.RemotableQuartzScheduler#interrupt(JobKey)
 */
public boolean interrupt(JobKey jobKey) throws UnabletoInterruptJobException {

    List<JobExecutionContext> jobs = getCurrentlyExecutingJobs();

    JobDetail jobDetail = null;
    Job job = null;

    boolean interrupted = false;

    for(JobExecutionContext jec : jobs) {
        jobDetail = jec.getJobDetail();
        if (jobKey.equals(jobDetail.getKey())) {
            job = jec.getJobInstance();
            if (job instanceof InterruptableJob) {
                ((InterruptableJob)job).interrupt();
                interrupted = true;
            } else {
                throw new UnabletoInterruptJobException(
                        "Job " + jobDetail.getKey() +
                        " can not be interrupted,since it does not implement " +                        
                        InterruptableJob.class.getName());
            }
        }                        
    }

    return interrupted;
}
项目:awplab-core    文件RunningCommand.java   
@Override
public Object execute() throws Exception {

    ObjectMapper objectMapper = new ObjectMapper();

    for (Scheduler scheduler : schedulerManager.getSchedulers()) {

        if (schedulerName != null && !scheduler.getSchedulerName().equals(schedulerName)) continue;

        for (JobExecutionContext context : scheduler.getCurrentlyExecutingJobs()) {
            String line = scheduler.getSchedulerName() + " - " + context.getJobInstance().getClass().getName();
            System.out.println(line);
            System.out.println(new String(new char[line.length()]).replace("\0","-"));
            System.out.println("Job Key Name: " + context.getJobDetail().getKey().getName());
            System.out.println("Job Key Group: " + context.getJobDetail().getKey().getGroup());
            System.out.println("Interruptable: " + (context.getJobInstance() instanceof InterruptableJob ? "Yes" : "No"));
            //System.out.println("Thread State: " + (context.getJobInstance() instanceof StatusJob ? ((StatusJob) context.getJobInstance()).getExecuteThread().getState().toString() : "N/A"));
            line = "Job Data";
            System.out.println(line);
            System.out.println(new String(new char[line.length()]).replace("\0","-"));
            System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsstring(context.getJobDetail().getJobDataMap()));
            if (context.getJobInstance() instanceof StatusJob) {
                line = "Job Status";
                System.out.println(line);
                System.out.println(new String(new char[line.length()]).replace("\0","-"));
                System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsstring(((StatusJob) context.getJobInstance()).getJobStatus()));
            }
            System.out.println();
        }
    }
    return null;

}
项目:citrine-scheduler    文件BeanJob.java   
@Override
public void interrupt() throws UnabletoInterruptJobException {
  if (jobBean != null && jobBean instanceof InterruptableJob) {
    ((InterruptableJob) jobBean).interrupt();
  }
}
项目:sakai    文件SchedulerTool.java   
public boolean isJobKillable(JobDetail detail) {
 if (InterruptableJob.class.isAssignableFrom(detail.getJobClass())) {
  return true;
 }
 return false;
}
项目:quartz-glass    文件UtilsTool.java   
public boolean isInterruptible(JobDetail job) {
    return InterruptableJob.class.isAssignableFrom(job.getJobClass());
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。