Search in sources :

Example 1 with InterruptableJob

use of org.quartz.InterruptableJob in project kernel by exoplatform.

the class JobSchedulerServiceImpl method stop.

public void stop() {
    try {
        List<JobExecutionContext> jobs = getAllExcutingJobs();
        for (JobExecutionContext ctx : jobs) {
            Job job = ctx.getJobInstance();
            if (job instanceof InterruptableJob) {
                ((InterruptableJob) job).interrupt();
            }
        }
        scheduler_.shutdown(true);
    } catch (Exception ex) {
        LOG.warn("Could not interrupt all the current jobs properly", ex);
    }
}
Also used : InterruptableJob(org.quartz.InterruptableJob) JobExecutionContext(org.quartz.JobExecutionContext) Job(org.quartz.Job) InterruptableJob(org.quartz.InterruptableJob) PeriodJob(org.exoplatform.services.scheduler.PeriodJob) CronJob(org.exoplatform.services.scheduler.CronJob) SchedulerException(org.quartz.SchedulerException) ObjectAlreadyExistsException(org.quartz.ObjectAlreadyExistsException)

Example 2 with InterruptableJob

use of org.quartz.InterruptableJob in project weicoder by wdcode.

the class ExecutingJobsManager method interrupt.

/**
 * 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;
}
Also used : UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) JobDetail(org.quartz.JobDetail) InterruptableJob(org.quartz.InterruptableJob) JobExecutionContext(org.quartz.JobExecutionContext) Job(org.quartz.Job) InterruptableJob(org.quartz.InterruptableJob)

Example 3 with InterruptableJob

use of org.quartz.InterruptableJob in project weicoder by wdcode.

the class ExecutingJobsManager method shutdown.

/**
 * <p>
 * Halts the <code>QuartzScheduler</code>'s firing of <code>{@link org.quartz.Trigger}s</code>,
 * and cleans up all resources associated with the QuartzScheduler.
 * </p>
 *
 * <p>
 * The scheduler cannot be re-started.
 * </p>
 *
 * @param waitForJobsToComplete
 *          if <code>true</code> the scheduler will not allow this method
 *          to return until all currently executing jobs have completed.
 */
public void shutdown(boolean waitForJobsToComplete) {
    if (shuttingDown || closed) {
        return;
    }
    shuttingDown = true;
    getLog().info("Scheduler " + resources.getUniqueIdentifier() + " shutting down.");
    // boolean removeMgmtSvr = false;
    // if (registeredManagementServerBind != null) {
    // ManagementServer standaloneRestServer =
    // MGMT_SVR_BY_BIND.get(registeredManagementServerBind);
    // 
    // try {
    // standaloneRestServer.unregister(this);
    // 
    // if (!standaloneRestServer.hasRegistered()) {
    // removeMgmtSvr = true;
    // standaloneRestServer.stop();
    // }
    // } catch (Exception e) {
    // getLog().warn("Failed to shutdown the ManagementRESTService", e);
    // } finally {
    // if (removeMgmtSvr) {
    // MGMT_SVR_BY_BIND.remove(registeredManagementServerBind);
    // }
    // 
    // registeredManagementServerBind = null;
    // }
    // }
    standby();
    schedThread.halt(waitForJobsToComplete);
    notifySchedulerListenersShuttingdown();
    if ((resources.isInterruptJobsOnShutdown() && !waitForJobsToComplete) || (resources.isInterruptJobsOnShutdownWithWait() && waitForJobsToComplete)) {
        List<JobExecutionContext> jobs = getCurrentlyExecutingJobs();
        for (JobExecutionContext job : jobs) {
            if (job.getJobInstance() instanceof InterruptableJob)
                try {
                    ((InterruptableJob) job.getJobInstance()).interrupt();
                } catch (Throwable e) {
                    // do nothing, this was just a courtesy effort
                    getLog().warn("Encountered error when interrupting job {} during shutdown: {}", job.getJobDetail().getKey(), e);
                }
        }
    }
    resources.getThreadPool().shutdown(waitForJobsToComplete);
    closed = true;
    if (resources.getJMXExport()) {
        try {
            unregisterJMX();
        } catch (Exception e) {
        }
    }
    if (boundRemotely) {
        try {
            unBind();
        } catch (RemoteException re) {
        }
    }
    shutdownPlugins();
    resources.getJobStore().shutdown();
    notifySchedulerListenersShutdown();
    SchedulerRepository.getInstance().remove(resources.getName());
    holdToPreventGC.clear();
    getLog().info("Scheduler " + resources.getUniqueIdentifier() + " shutdown complete.");
}
Also used : InterruptableJob(org.quartz.InterruptableJob) JobExecutionContext(org.quartz.JobExecutionContext) RemoteException(java.rmi.RemoteException) ObjectAlreadyExistsException(org.quartz.ObjectAlreadyExistsException) RemoteException(java.rmi.RemoteException) JobExecutionException(org.quartz.JobExecutionException) UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) SchedulerException(org.quartz.SchedulerException)

Example 4 with InterruptableJob

use of org.quartz.InterruptableJob in project weicoder by wdcode.

the class ExecutingJobsManager method interrupt.

/**
 * 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;
}
Also used : UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) InterruptableJob(org.quartz.InterruptableJob) JobExecutionContext(org.quartz.JobExecutionContext) Job(org.quartz.Job) InterruptableJob(org.quartz.InterruptableJob)

Aggregations

InterruptableJob (org.quartz.InterruptableJob)4 JobExecutionContext (org.quartz.JobExecutionContext)4 Job (org.quartz.Job)3 UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)3 ObjectAlreadyExistsException (org.quartz.ObjectAlreadyExistsException)2 SchedulerException (org.quartz.SchedulerException)2 RemoteException (java.rmi.RemoteException)1 CronJob (org.exoplatform.services.scheduler.CronJob)1 PeriodJob (org.exoplatform.services.scheduler.PeriodJob)1 JobDetail (org.quartz.JobDetail)1 JobExecutionException (org.quartz.JobExecutionException)1