Java Code Examples for org.quartz.JobExecutionContext#getTrigger()
The following examples show how to use
org.quartz.JobExecutionContext#getTrigger() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoggingJobHistoryPlugin.java From lams with GNU General Public License v2.0 | 6 votes |
/** * @see org.quartz.JobListener#jobToBeExecuted(JobExecutionContext) */ public void jobToBeExecuted(JobExecutionContext context) { if (!getLog().isInfoEnabled()) { return; } Trigger trigger = context.getTrigger(); Object[] args = { context.getJobDetail().getKey().getName(), context.getJobDetail().getKey().getGroup(), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), Integer.valueOf(context.getRefireCount()) }; getLog().info(MessageFormat.format(getJobToBeFiredMessage(), args)); }
Example 2
Source File: LoggingJobHistoryPlugin.java From lams with GNU General Public License v2.0 | 6 votes |
/** * @see org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext) */ public void jobExecutionVetoed(JobExecutionContext context) { if (!getLog().isInfoEnabled()) { return; } Trigger trigger = context.getTrigger(); Object[] args = { context.getJobDetail().getKey().getName(), context.getJobDetail().getKey().getGroup(), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), Integer.valueOf(context.getRefireCount()) }; getLog().info(MessageFormat.format(getJobWasVetoedMessage(), args)); }
Example 3
Source File: XExecuteBIDocumentJob.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
private boolean isTriggerPaused(JobExecutionContext jobExecutionContext) { Trigger trigger = jobExecutionContext.getTrigger(); String triggerGroup = trigger.getGroup(); String triggerName = trigger.getName(); String jobName = trigger.getJobName(); String jobGroupOriginal = jobExecutionContext.getJobDetail().getGroup(); String[] bits = jobGroupOriginal.split("/"); String jobGroup = bits[bits.length - 1]; boolean result = false; ISchedulerDAO schedulerDAO = DAOFactory.getSchedulerDAO(); result = schedulerDAO.isTriggerPaused(triggerGroup, triggerName, jobGroup, jobName); return result; }
Example 4
Source File: LoggingJobHistoryPlugin.java From AsuraFramework with Apache License 2.0 | 6 votes |
/** * @see org.quartz.JobListener#jobToBeExecuted(JobExecutionContext) */ public void jobToBeExecuted(JobExecutionContext context) { if (!getLog().isInfoEnabled()) { return; } Trigger trigger = context.getTrigger(); Object[] args = { context.getJobDetail().getName(), context.getJobDetail().getGroup(), new java.util.Date(), trigger.getName(), trigger.getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), new Integer(context.getRefireCount()) }; getLog().info(MessageFormat.format(getJobToBeFiredMessage(), args)); }
Example 5
Source File: LoggingJobHistoryPlugin.java From AsuraFramework with Apache License 2.0 | 6 votes |
/** * @see org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext) */ public void jobExecutionVetoed(JobExecutionContext context) { if (!getLog().isInfoEnabled()) { return; } Trigger trigger = context.getTrigger(); Object[] args = { context.getJobDetail().getName(), context.getJobDetail().getGroup(), new java.util.Date(), trigger.getName(), trigger.getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), new Integer(context.getRefireCount()) }; getLog().info(MessageFormat.format(getJobWasVetoedMessage(), args)); }
Example 6
Source File: SparkSubmitJob.java From griffin with Apache License 2.0 | 5 votes |
private void updateJobInstanceState(JobExecutionContext context) throws IOException { SimpleTrigger simpleTrigger = (SimpleTrigger) context.getTrigger(); int repeatCount = simpleTrigger.getRepeatCount(); int fireCount = simpleTrigger.getTimesTriggered(); if (fireCount > repeatCount) { saveJobInstance(null, NOT_FOUND); } }
Example 7
Source File: AbstractSuspendableJob.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
private boolean isTriggerPaused(JobExecutionContext jobExecutionContext) { Trigger trigger = jobExecutionContext.getTrigger(); String triggerGroup = trigger.getGroup(); String triggerName = trigger.getName(); String jobName = trigger.getJobName(); String jobGroupOriginal = jobExecutionContext.getJobDetail().getGroup(); String[] bits = jobGroupOriginal.split("/"); String jobGroup = bits[bits.length - 1]; ISchedulerDAO schedulerDAO = DAOFactory.getSchedulerDAO(); return schedulerDAO.isTriggerPaused(triggerGroup, triggerName, jobGroup, jobName); }
Example 8
Source File: ScheduleJobService.java From springboot-quartz with MIT License | 5 votes |
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; }
Example 9
Source File: FeedNotifierJob.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Calls the feed notifier to do its work */ public void execute(JobExecutionContext context) throws JobExecutionException { JobDataMap jobData = context.getJobDetail().getJobDataMap(); final FeedNotifier feedNotifier = (FeedNotifier)jobData.get(KEY_FEED_NOTIFIER); final TenantAdminService tenantAdminService = (TenantAdminService)jobData.get(KEY_TENANT_ADMIN_SERVICE); Long repeatInterval = null; Trigger trigger = context.getTrigger(); if (trigger instanceof SimpleTrigger) { repeatInterval = ((SimpleTrigger)trigger).getRepeatInterval(); } final int repeatIntervalMins = new Long(repeatInterval == null ? 0L : repeatInterval / 1000 / 60).intValue(); AuthenticationUtil.runAs(new RunAsWork<Object>() { public Object doWork() throws Exception { feedNotifier.execute(repeatIntervalMins); return null; } }, AuthenticationUtil.getSystemUserName()); if ((tenantAdminService != null) && tenantAdminService.isEnabled()) { List<Tenant> tenants = tenantAdminService.getAllTenants(); for (Tenant tenant : tenants) { TenantUtil.runAsSystemTenant(new TenantRunAsWork<Object>() { public Object doWork() throws Exception { feedNotifier.execute(repeatIntervalMins); return null; } }, tenant.getTenantDomain()); } } }
Example 10
Source File: LoggingJobHistoryPlugin.java From lams with GNU General Public License v2.0 | 4 votes |
/** * @see org.quartz.JobListener#jobWasExecuted(JobExecutionContext, JobExecutionException) */ public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) { Trigger trigger = context.getTrigger(); Object[] args = null; if (jobException != null) { if (!getLog().isWarnEnabled()) { return; } String errMsg = jobException.getMessage(); args = new Object[] { context.getJobDetail().getKey().getName(), context.getJobDetail().getKey().getGroup(), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), Integer.valueOf(context.getRefireCount()), errMsg }; getLog().warn(MessageFormat.format(getJobFailedMessage(), args), jobException); } else { if (!getLog().isInfoEnabled()) { return; } String result = String.valueOf(context.getResult()); args = new Object[] { context.getJobDetail().getKey().getName(), context.getJobDetail().getKey().getGroup(), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), Integer.valueOf(context.getRefireCount()), result }; getLog().info(MessageFormat.format(getJobSuccessMessage(), args)); } }
Example 11
Source File: LoggingJobHistoryPlugin.java From AsuraFramework with Apache License 2.0 | 4 votes |
/** * @see org.quartz.JobListener#jobWasExecuted(JobExecutionContext, JobExecutionException) */ public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) { Trigger trigger = context.getTrigger(); Object[] args = null; if (jobException != null) { if (!getLog().isWarnEnabled()) { return; } String errMsg = jobException.getMessage(); args = new Object[] { context.getJobDetail().getName(), context.getJobDetail().getGroup(), new java.util.Date(), trigger.getName(), trigger.getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), new Integer(context.getRefireCount()), errMsg }; getLog().warn(MessageFormat.format(getJobFailedMessage(), args), jobException); } else { if (!getLog().isInfoEnabled()) { return; } String result = String.valueOf(context.getResult()); args = new Object[] { context.getJobDetail().getName(), context.getJobDetail().getGroup(), new java.util.Date(), trigger.getName(), trigger.getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), new Integer(context.getRefireCount()), result }; getLog().info(MessageFormat.format(getJobSuccessMessage(), args)); } }
Example 12
Source File: SchedulerNotificationManager.java From SO with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void execute(JobExecutionContext context) throws JobExecutionException { // long time = System.currentTimeMillis(); SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String timeStr = timeFormat.format(new Date(time)); String profileId = context.getJobDetail().getKey().getName(); String groupName = context.getJobDetail().getKey().getGroup(); log.debug("### Checking Time by schedule({}) :{}",profileId, timeStr); SimpleTrigger st = (SimpleTrigger ) context.getTrigger(); int checkRate = (int)st.getRepeatInterval()/1000; //ServiceProcessor 의 ProfileInjector 에 주기에 따라 profile Id 전송 // ProfileInjector profileInJector = new ProfileIntjector(); // profileInJector.sendProfile(profileId); //JobDataMap dataMap = context.getMergedJobDataMap(); JobDataMap dataMap = context.getJobDetail().getJobDataMap(); //JobDataMap dataMap = context.getTrigger().getJobDataMap(); ProfileForDB profileForDB = (ProfileForDB)dataMap.get("profile"); //log.debug("profileForDB.getPeriod()={}", profileForDB.getPeriod()); int period = profileForDB.getPeriod(); //int checkRate = dataMap.getInt("checkRate"); boolean happened = dataMap.getBoolean("happened"); //초기값=미발생 long lastTimeExecutedCm = dataMap.getLong("lastTimeExecutedCm"); //마지막 CM 발생 일시 //context.getJobDetail().getJobDataMap().put("lastTimeExecutedCm", lastTimeExecutedCm); long currentTime = (new Date().getTime())/1000; //to sec boolean result; log.debug("## past={}, {} - {}", (currentTime - lastTimeExecutedCm), currentTime, lastTimeExecutedCm); if (happened) { //이미 CM을 처리했으면 if (lastTimeExecutedCm==0 || (lastTimeExecutedCm + period) <= currentTime){ //시간이 경과 했으면 result = checkCm(profileId, CHECK_AND_RUN); //CM조사해서 발생했으면 실행후 발생(실행) 여부 리턴 lastTimeExecutedCm = currentTime; //마지막 실행시간 저장 dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm); } else { result = checkCm(profileId, CHECK_ONLY); //CM조사해서발생여부만 리턴 } if (result == false) {//발생하지 않으면 happened = false; // 실행 여부 초기화 dataMap.put("happened", happened); } } else { //CM이 실행하지 않았으면 result = checkCm(profileId, CHECK_AND_RUN); //CM실행후 발생(실행) 여부 리턴 if (result == true) {//처리되었으면 happened = true; // 실행했음 lastTimeExecutedCm = currentTime; dataMap.put("happened", happened); dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm); } } dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm); dataMap.put("profile", profileForDB); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS"); String ctime = sdf.format(new Date()); log.debug("{} - result={}, happened={}, lastTimeExecutedCm={}\n", ctime, result, happened, lastTimeExecutedCm); }
Example 13
Source File: SchedulerNotificationManager.java From SO with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void execute(JobExecutionContext context) throws JobExecutionException { // long time = System.currentTimeMillis(); SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String timeStr = timeFormat.format(new Date(time)); String profileId = context.getJobDetail().getKey().getName(); String groupName = context.getJobDetail().getKey().getGroup(); log.debug("### Checking Time by schedule({}) :{}",profileId, timeStr); SimpleTrigger st = (SimpleTrigger ) context.getTrigger(); int checkRate = (int)st.getRepeatInterval()/1000; //ServiceProcessor 의 ProfileInjector 에 주기에 따라 profile Id 전송 // ProfileInjector profileInJector = new ProfileIntjector(); // profileInJector.sendProfile(profileId); //JobDataMap dataMap = context.getMergedJobDataMap(); JobDataMap dataMap = context.getJobDetail().getJobDataMap(); //JobDataMap dataMap = context.getTrigger().getJobDataMap(); ProfileForDB profileForDB = (ProfileForDB)dataMap.get("profile"); //log.debug("profileForDB.getPeriod()={}", profileForDB.getPeriod()); int period = profileForDB.getPeriod(); //int checkRate = dataMap.getInt("checkRate"); boolean happened = dataMap.getBoolean("happened"); //초기값=미발생 long lastTimeExecutedCm = dataMap.getLong("lastTimeExecutedCm"); //마지막 CM 발생 일시 //context.getJobDetail().getJobDataMap().put("lastTimeExecutedCm", lastTimeExecutedCm); long currentTime = (new Date().getTime())/1000; //to sec boolean result; log.debug("## past={}, {} - {}", (currentTime - lastTimeExecutedCm), currentTime, lastTimeExecutedCm); if (happened) { //이미 CM을 처리했으면 if (lastTimeExecutedCm==0 || (lastTimeExecutedCm + period) <= currentTime){ //시간이 경과 했으면 result = checkCm(profileId, CHECK_AND_RUN); //CM조사해서 발생했으면 실행후 발생(실행) 여부 리턴 lastTimeExecutedCm = currentTime; //마지막 실행시간 저장 dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm); } else { result = checkCm(profileId, CHECK_ONLY); //CM조사해서발생여부만 리턴 } if (result == false) {//발생하지 않으면 happened = false; // 실행 여부 초기화 dataMap.put("happened", happened); } } else { //CM이 실행하지 않았으면 result = checkCm(profileId, CHECK_AND_RUN); //CM실행후 발생(실행) 여부 리턴 if (result == true) {//처리되었으면 happened = true; // 실행했음 lastTimeExecutedCm = currentTime; dataMap.put("happened", happened); dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm); } } dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm); dataMap.put("profile", profileForDB); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS"); String ctime = sdf.format(new Date()); log.debug("{} - result={}, happened={}, lastTimeExecutedCm={}\n", ctime, result, happened, lastTimeExecutedCm); }
Example 14
Source File: NavigableEventLogListener.java From sakai with Educational Community License v2.0 | 4 votes |
private void info (EVENTTYPE eventType, Trigger trig, JobExecutionContext context, JobExecutionException exception, CompletedExecutionInstruction instructionCode) { JobDetail detail = (context != null)?context.getJobDetail():null; final JobDataMap dataMap = (context != null)?context.getMergedJobDataMap():null; final String jobName = (detail != null)?detail.getKey().getName():null, jobDesc = (detail != null)?detail.getDescription():null; final Class jobClass = (detail != null)?detail.getJobClass():null; final Trigger trigger = (trig != null)?trig:((context != null)?context.getTrigger():null); final String trigName = (trigger != null)?trigger.getKey().getName():null, trigDesc = (trigger != null)?trigger.getDescription():null; final Date trigStart = (trigger != null)?trigger.getStartTime():null, trigEnd = (trigger != null)?trigger.getEndTime():null; StringBuilder sb = new StringBuilder(); switch (eventType) { case JOB_EXECUTING: { sb.append("Job Executing: ["); sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"") .append(", class: ").append(jobClass.getName()); sb.append("]"); break; } case JOB_VETOED: { sb.append("Job Vetoed: ["); sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"") .append(", class: ").append(jobClass.getName()); break; } case JOB_EXECUTED: { sb.append("Job Executed: ["); sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"") .append(", class: ").append(jobClass.getName()); if (exception != null) { sb.append (", exception: ").append(exception.getMessage()); if (exception.getCause() != null) { sb.append(", exception cause: ").append(exception.getCause().getClass().getName()); } } sb.append("]"); break; } case TRIGGER_FIRED: { sb.append("Trigger Fired: ["); sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"") .append(", start: ").append((trigStart != null)?trigStart.toString():null) .append(", end: ").append((trigEnd != null)?trigEnd.toString():null); sb.append(", job: ").append(jobName).append(", job description: ").append((jobDesc != null)?jobDesc:"") .append(", class: ").append(jobClass.getName()); sb.append("]"); break; } case TRIGGER_MISFIRED: { sb.append("Trigger Misfired: ["); sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"") .append(", start: ").append((trigStart!=null)?trigStart.toString():null) .append(", end: ").append((trigEnd!=null)?trigEnd.toString():null); sb.append("]"); break; } case TRIGGER_COMPLETED: { sb.append("Trigger Completed: ["); sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"") .append(", start: ").append((trigStart!=null)?trigStart.toString():null) .append(", end: ").append((trigEnd!=null)?trigEnd.toString():null); sb.append(", job: ").append(jobName).append(", job description: ").append((jobDesc != null)?jobDesc:"") .append(", class: ").append(jobClass.getName()) .append(", execution result: ").append(instructionCode); sb.append("]"); break; } } if (log.isDebugEnabled()) { log.debug(sb.toString()); } }
Example 15
Source File: NavigableEventLogListener.java From sakai with Educational Community License v2.0 | 4 votes |
private void info (EVENTTYPE eventType, Trigger trig, JobExecutionContext context, JobExecutionException exception, CompletedExecutionInstruction instructionCode) { JobDetail detail = (context != null)?context.getJobDetail():null; final JobDataMap dataMap = (context != null)?context.getMergedJobDataMap():null; final String jobName = (detail != null)?detail.getKey().getName():null, jobDesc = (detail != null)?detail.getDescription():null; final Class jobClass = (detail != null)?detail.getJobClass():null; final Trigger trigger = (trig != null)?trig:((context != null)?context.getTrigger():null); final String trigName = (trigger != null)?trigger.getKey().getName():null, trigDesc = (trigger != null)?trigger.getDescription():null; final Date trigStart = (trigger != null)?trigger.getStartTime():null, trigEnd = (trigger != null)?trigger.getEndTime():null; StringBuilder sb = new StringBuilder(); switch (eventType) { case JOB_EXECUTING: { sb.append("Job Executing: ["); sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"") .append(", class: ").append(jobClass.getName()); sb.append("]"); break; } case JOB_VETOED: { sb.append("Job Vetoed: ["); sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"") .append(", class: ").append(jobClass.getName()); break; } case JOB_EXECUTED: { sb.append("Job Executed: ["); sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"") .append(", class: ").append(jobClass.getName()); if (exception != null) { sb.append (", exception: ").append(exception.getMessage()); if (exception.getCause() != null) { sb.append(", exception cause: ").append(exception.getCause().getClass().getName()); } } sb.append("]"); break; } case TRIGGER_FIRED: { sb.append("Trigger Fired: ["); sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"") .append(", start: ").append((trigStart != null)?trigStart.toString():null) .append(", end: ").append((trigEnd != null)?trigEnd.toString():null); sb.append(", job: ").append(jobName).append(", job description: ").append((jobDesc != null)?jobDesc:"") .append(", class: ").append(jobClass.getName()); sb.append("]"); break; } case TRIGGER_MISFIRED: { sb.append("Trigger Misfired: ["); sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"") .append(", start: ").append((trigStart!=null)?trigStart.toString():null) .append(", end: ").append((trigEnd!=null)?trigEnd.toString():null); sb.append("]"); break; } case TRIGGER_COMPLETED: { sb.append("Trigger Completed: ["); sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"") .append(", start: ").append((trigStart!=null)?trigStart.toString():null) .append(", end: ").append((trigEnd!=null)?trigEnd.toString():null); sb.append(", job: ").append(jobName).append(", job description: ").append((jobDesc != null)?jobDesc:"") .append(", class: ").append(jobClass.getName()) .append(", execution result: ").append(instructionCode); sb.append("]"); break; } } if (log.isDebugEnabled()) { log.debug(sb.toString()); } }
Example 16
Source File: QuartzTaskUtils.java From nexus-public with Eclipse Public License 1.0 | 2 votes |
/** * Returns the current trigger for currently executing NX Task. * * That is either its associated trigger loaded up by key using {@link #getJobTrigger(JobExecutionContext)}, * or if not found (can happen when invoked from * {@link JobListener#jobWasExecuted(JobExecutionContext, JobExecutionException)} * method for a canceled/removed job, the "current" trigger from context is returned. * * Never returns {@code null}, as Quartz context always contains a trigger. */ public static Trigger getCurrentTrigger(final JobExecutionContext context) { final Trigger jobTrigger = getJobTrigger(context); return jobTrigger != null ? jobTrigger : context.getTrigger(); }