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);
}
}
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;
}
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.");
}
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;
}
Aggregations