Java 类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";
}
项目: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, 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(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;
}
项目: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());
}