本文整理匯總了Java中org.quartz.JobExecutionContext.getJobDetail方法的典型用法代碼示例。如果您正苦於以下問題:Java JobExecutionContext.getJobDetail方法的具體用法?Java JobExecutionContext.getJobDetail怎麽用?Java JobExecutionContext.getJobDetail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.quartz.JobExecutionContext
的用法示例。
在下文中一共展示了JobExecutionContext.getJobDetail方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRunningJob
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
/**
* 所有正在運行的job
*
* @return
* @throws SchedulerException
*/
public List<ScheduleJob> getRunningJob() throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
List<JobExecutionContext> executingJobs = scheduler.getCurrentlyExecutingJobs();
List<ScheduleJob> jobList = new ArrayList<ScheduleJob>(executingJobs.size());
for (JobExecutionContext executingJob : executingJobs) {
ScheduleJob job = new ScheduleJob();
JobDetail jobDetail = executingJob.getJobDetail();
JobKey jobKey = jobDetail.getKey();
Trigger trigger = executingJob.getTrigger();
job.setName(jobKey.getName());
job.setGroup(jobKey.getGroup());
job.setDescription("觸發器:" + trigger.getKey());
Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
job.setStatus(triggerState.name());
if (trigger instanceof CronTrigger) {
CronTrigger cronTrigger = (CronTrigger) trigger;
String cronExpression = cronTrigger.getCronExpression();
job.setCron(cronExpression);
}
jobList.add(job);
}
return jobList;
}
示例2: getRunningJobList
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
@Override
public List<ScheduleJobEntity> getRunningJobList() {
List<ScheduleJobEntity> jobList = null;
Scheduler scheduler = schedulerFactoryBean.getScheduler();
try {
List<JobExecutionContext> executingJobList = scheduler.getCurrentlyExecutingJobs();
jobList = new ArrayList<>(executingJobList.size());
for (JobExecutionContext executingJob : executingJobList) {
ScheduleJobEntity scheduleJob = new ScheduleJobEntity();
JobDetail jobDetail = executingJob.getJobDetail();
JobKey jobKey = jobDetail.getKey();
Trigger trigger = executingJob.getTrigger();
this.wrapScheduleJob(scheduleJob, scheduler, jobKey, trigger);
jobList.add(scheduleJob);
}
} catch (Exception e) {
logger.error("獲取計劃任務列表失敗", e);
throw new ServiceException("獲取計劃任務列表失敗", e);
}
return jobList;
}
示例3: execute
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
JobDetail jobDetail = jobExecutionContext.getJobDetail();
_logger.info("Cron triggered for {0}", jobDetail.getDescription());
JobDataMap dataMap = jobDetail.getJobDataMap();
try {
//Creating entry in redis to avoid duplicate job scheduling
MemcacheService cache = AppFactory.get().getMemcacheService();
String jobKey = "SJOB_" + DigestUtils.md5Hex(dataMap.getString("url"));
if (cache.get(jobKey) == null) {
HttpUtil
.connectMulti(HttpUtil.GET, ConfigUtil.get("task.url") + dataMap.getString("url"), null,
null, null, null);
cache.put(jobKey, true, 1800);
} else {
_logger.warn("Job with url {0} is already scheduled. Doing nothing!!",
dataMap.getString("url"));
}
} catch (Exception e) {
_logger.warn("Scheduled job failed for url {0} with exception {1}", dataMap.getString("url"),
e.getMessage(), e);
}
}
示例4: jobWasExecuted
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
public void jobWasExecuted(final JobExecutionContext context, JobExecutionException exp) {
JobDetail jobDetail = context.getJobDetail();
if(jobDetail instanceof JobDetailImpl){
JobDetailImpl job = (JobDetailImpl)jobDetail;
SchedulerLog log = new SchedulerLog();
log.setJobName(job.getName());
log.setGroupName(job.getGroup());
log.setTriggerName(context.getTrigger().getKey().getName());
log.setFireTime(context.getFireTime());
log.setScheduledFireTime(context.getScheduledFireTime());
log.setRefireCount(context.getRefireCount());
log.setPreviousFireTime(context.getPreviousFireTime());
log.setNextFireTime(context.getNextFireTime());
log.setCreateTime(new Date());
logMapper.insert(log);
}
}
示例5: execute
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
public void execute(JobExecutionContext context) throws JobExecutionException {
DetectionJobDetail jobDetail=(DetectionJobDetail)context.getJobDetail();
Session session=jobDetail.getSessionFactory().openSession();
try {
String currentInstanceName=jobDetail.getCurrentInstanceName();
Operation operation=detection(session,jobDetail.getJobInstanceNames(),currentInstanceName);
if(operation.equals(Operation.reset)){
ISchedulerService service=jobDetail.getSchedulerService();
System.out.println("Current instance scheduler starting...");
service.resetScheduer();
System.out.println("Start successful...");
}
} catch (Exception e) {
throw new JobExecutionException(e);
}finally{
session.flush();
session.close();
}
}
示例6: execute
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
public void execute(JobExecutionContext context) throws JobExecutionException {
DetectionJobDetail jobDetail=(DetectionJobDetail)context.getJobDetail();
try {
ISchedulerService service=jobDetail.getSchedulerService();
if(!service.isRunJobInCurrentInstance()){
log.warn("Current instance not allowed run scheduler!");
return;
}
Scheduler scheduler=service.getCurrentScheduler();
if(scheduler==null || scheduler.isShutdown()){
System.out.println("Current instance scheduler was shutdown,start reset...");
service.resetScheduer();
System.out.println("Reset successful...");
}
} catch (Exception e) {
throw new JobExecutionException(e);
}
}
示例7: execute
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
ScanReminderJobDetail detail=(ScanReminderJobDetail)context.getJobDetail();
TaskService taskService=detail.getTaskService();
List<Long> reminderTaskList=detail.getReminderTaskList();
List<TaskReminder> reminders=taskService.getAllTaskReminders();
SchedulerService schedulerService=detail.getSchedulerService();
for(TaskReminder reminder:reminders){
long taskId=reminder.getTaskId();
if(reminderTaskList.contains(taskId)){
continue;
}
schedulerService.addReminderJob(reminder,null,null);
reminderTaskList.add(taskId);
}
}
示例8: getRunningScheduledJobs
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public SortedSet<ScheduledJob> getRunningScheduledJobs() {
SortedSet<ScheduledJob> ss = new TreeSet<ScheduledJob>();
try {
for (JobExecutionContext ctx : (List<JobExecutionContext>) sched.getCurrentlyExecutingJobs()) {
JobDetail jd = ctx.getJobDetail();
if (jd.getJobDataMap().containsKey("running")) {
ss.add((ScheduledJob) jd.getJobDataMap().get("scheduledJob"));
}
}
} catch (SchedulerException e) { }
return ss;
}
示例9: execute
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDetail jd = context.getJobDetail();
ScheduledJob scheduledJob = (ScheduledJob) jd.getJobDataMap().get("scheduledJob");
SchedulerManager schedulerManager = (SchedulerManager) jd.getJobDataMap().get("schedulerManager");
AbstractJob job = scheduledJob.getJob();
if (job != null) {
if (schedulerManager.getRunningScheduledJobs().contains(scheduledJob)) {
Engine.logScheduler.warn("No start " + jd.getName() + " because another still running.");
} else {
jd.getJobDataMap().put("running", true);
executeJob(job, jd.getName());
}
}
}
示例10: interrupt
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
/**
* 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;
}
示例11: getRunningJobList
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
public List<ScheduleJob> getRunningJobList() throws SchedulerException{
List<JobExecutionContext> executingJobList = scheduler.getCurrentlyExecutingJobs();
List<ScheduleJob> jobList = new ArrayList<>(executingJobList.size());
for(JobExecutionContext executingJob : executingJobList){
ScheduleJob scheduleJob = new ScheduleJob();
JobDetail jobDetail = executingJob.getJobDetail();
JobKey jobKey = jobDetail.getKey();
Trigger trigger = executingJob.getTrigger();
this.wrapScheduleJob(scheduleJob,scheduler,jobKey,trigger);
jobList.add(scheduleJob);
}
return jobList;
}
示例12: execute
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
public void execute(JobExecutionContext context) throws JobExecutionException {
HeartJobDetail detail=(HeartJobDetail)context.getJobDetail();
String instanceName=detail.getCurrentInstanceName();
Session session=detail.getSessionFactory().openSession();
try{
String applicationName=Configure.getString(ISchedulerService.JOB_APPLICATION_NAME);
String hql="from "+Heartbeat.class.getName()+" b where b.instanceName=:instanceName and b.applicationName=:applicationName";
Query query=session.createQuery(hql).setString("instanceName",instanceName).setString("applicationName",applicationName);
@SuppressWarnings("unchecked")
List<Heartbeat> beats=query.list();
Date now=new Date();
Heartbeat beat=null;
if(beats.size()>0){
beat=beats.get(0);
}else{
beat=new Heartbeat();
beat.setId(UUID.randomUUID().toString());
beat.setApplicationName(applicationName);
}
beat.setDate(now);
beat.setInstanceName(instanceName);
session.saveOrUpdate(beat);
}catch(Exception ex){
throw new JobExecutionException(ex);
}finally{
session.flush();
session.close();
}
}
示例13: jobWasExecuted
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
public void jobWasExecuted(JobExecutionContext context,
JobExecutionException jobException) {
JobDetail jobDetail = context.getJobDetail();
if (!(jobDetail instanceof SpringBeanJobExecutorDetail)) {
return;
}
JobDataMap map = jobDetail.getJobDataMap();
if (!map.containsKey(IJobDefinitionService.JOB_DEFINITION_ID)) {
return;
}
Date end = new Date();
String exception = getExceptionStackMessage(jobException);
JobHistory history = new JobHistory();
history.setSuccessful(exception == null ? true : false);
if (exception != null) {
history.setExceptionMessage(exception.length() > 1500 ? exception
.substring(0, 1500) : exception);
}
history.setEndDate(end);
history.setStartDate((Date)map.get(START_DATE_KEY));
history.setId(UUID.randomUUID().toString());
history.setJobId(map.getString(IJobDefinitionService.JOB_DEFINITION_ID));
Session session = getSessionFactory().openSession();
try {
session.save(history);
} finally {
session.flush();
session.close();
}
}
示例14: execute
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
public void execute(JobExecutionContext context) throws JobExecutionException {
DetectionJobDetail jobDetail=(DetectionJobDetail)context.getJobDetail();
Session session=jobDetail.getSessionFactory().openSession();
try {
String currentInstanceName=jobDetail.getCurrentInstanceName();
Operation operation=detection(session,jobDetail.getJobInstanceNames(),currentInstanceName);
if(operation.equals(Operation.reset)){
SchedulerService service=jobDetail.getSchedulerService();
service.resetScheduer();
Heartbeat beat=new Heartbeat();
Calendar c=Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.SECOND, 1);
beat.setDate(c.getTime());
beat.setId(UUID.randomUUID().toString());
beat.setInstanceName(currentInstanceName);
session.save(beat);
initHeartJob(currentInstanceName, service.getScheduler());
}
} catch (Exception e) {
throw new JobExecutionException(e);
}finally{
session.flush();
session.close();
}
}
示例15: execute
import org.quartz.JobExecutionContext; //導入方法依賴的package包/類
public void execute(JobExecutionContext context) throws JobExecutionException {
HeartJobDetail detail=(HeartJobDetail)context.getJobDetail();
String instanceName=detail.getCurrentInstanceName();
Session session=detail.getSessionFactory().openSession();
try{
String hql="from "+Heartbeat.class.getName()+" b where b.instanceName=:instanceName order by b.date desc";
Query query=session.createQuery(hql).setString("instanceName",instanceName);
@SuppressWarnings("unchecked")
List<Heartbeat> beats=query.list();
Date now=new Date();
Heartbeat beat=null;
if(beats.size()>0){
beat=beats.get(0);
}else{
beat=new Heartbeat();
beat.setId(UUID.randomUUID().toString());
beat.setInstanceName(instanceName);
}
beat.setDate(now);
session.saveOrUpdate(beat);
}catch(Exception ex){
throw new JobExecutionException(ex);
}finally{
session.flush();
session.close();
}
}