Interface JobExecutionContext
-
- All Known Implementing Classes:
JobExecutionContextImpl
public interface JobExecutionContextA context bundle containing handles to various environment information, that is given to ainstance as it is executed, and to aJobDetailinstance after the execution completes.TriggerThe
JobDataMapfound on this object (via thegetMergedJobDataMap()method) serves as a convenience - it is a merge of theJobDataMapfound on theJobDetailand the one found on theTrigger, with the value in the latter overriding any same-named values in the former. It is thus considered a 'best practice' that the execute code of a Job retrieve data from the JobDataMap found on this object NOTE: Do not expect value 'set' into this JobDataMap to somehow be set back onto a job's own JobDataMap - even if it has the@PersistJobDataAfterExecutionannotation.JobExecutionContexts are also returned from theScheduler.getCurrentlyExecutingJobs()method. These are the same instances as those passed into the jobs that are currently executing within the scheduler. The exception to this is when your application is using Quartz remotely (i.e. via RMI) - in which case you get a clone of theJobExecutionContexts, and their references to theSchedulerandJobinstances have been lost (a clone of theJobDetailis still available - just not a handle to the job instance that is running).- Author:
- James House
- See Also:
getScheduler(),getMergedJobDataMap(),getJobDetail(),Job,Trigger,JobDataMap
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Objectget(java.lang.Object key)Get the value with the given key from the context's data map.CalendargetCalendar()Get a handle to theCalendarreferenced by theTriggerinstance that fired theJob.java.lang.StringgetFireInstanceId()Get the unique Id that identifies this particular firing instance of the trigger that triggered this job execution.java.util.DategetFireTime()The actual time the trigger fired.JobDetailgetJobDetail()Get theJobDetailassociated with theJob.JobgetJobInstance()Get the instance of theJobthat was created for this execution.longgetJobRunTime()The amount of time the job ran for (in milliseconds).JobDataMapgetMergedJobDataMap()Get the convenienceJobDataMapof this execution context.java.util.DategetNextFireTime()java.util.DategetPreviousFireTime()TriggerKeygetRecoveringTriggerKey()Return theTriggerKeyof the originally scheduled and now recovering job.intgetRefireCount()java.lang.ObjectgetResult()Returns the result (if any) that theJobset before its execution completed (the type of object set as the result is entirely up to the particular job).java.util.DategetScheduledFireTime()The scheduled time the trigger fired for.SchedulergetScheduler()Get a handle to theSchedulerinstance that fired theJob.TriggergetTrigger()Get a handle to theTriggerinstance that fired theJob.booleanisRecovering()If theJobis being re-executed because of a 'recovery' situation, this method will returntrue.voidput(java.lang.Object key, java.lang.Object value)Put the specified value into the context's data map with the given key.voidsetResult(java.lang.Object result)Set the result (if any) of theJob's execution (the type of object set as the result is entirely up to the particular job).
-
-
-
Method Detail
-
getScheduler
Scheduler getScheduler()
Get a handle to the
Schedulerinstance that fired theJob.
-
getTrigger
Trigger getTrigger()
Get a handle to the
Triggerinstance that fired theJob.
-
getCalendar
Calendar getCalendar()
Get a handle to the
Calendarreferenced by theTriggerinstance that fired theJob.
-
isRecovering
boolean isRecovering()
If the
Jobis being re-executed because of a 'recovery' situation, this method will returntrue.
-
getRecoveringTriggerKey
TriggerKey getRecoveringTriggerKey() throws java.lang.IllegalStateException
Return theTriggerKeyof the originally scheduled and now recovering job.When recovering a previously failed job execution this method returns the identity of the originally firing trigger. This recovering job will have been scheduled for the same firing time as the original job, and so is available via the
getScheduledFireTime()method. The original firing time of the job can be accessed via theScheduler.FAILED_JOB_ORIGINAL_TRIGGER_FIRETIME_IN_MILLISECONDSelement of this job'sJobDataMap.- Returns:
- the recovering trigger details
- Throws:
java.lang.IllegalStateException- if this is not a recovering job.
-
getRefireCount
int getRefireCount()
-
getMergedJobDataMap
JobDataMap getMergedJobDataMap()
Get the convenience
JobDataMapof this execution context.The
JobDataMapfound on this object serves as a convenience - it is a merge of theJobDataMapfound on theJobDetailand the one found on theTrigger, with the value in the latter overriding any same-named values in the former. It is thus considered a 'best practice' that the execute code of a Job retrieve data from the JobDataMap found on this object.NOTE: Do not expect value 'set' into this JobDataMap to somehow be set or persisted back onto a job's own JobDataMap - even if it has the
@PersistJobDataAfterExecutionannotation.Attempts to change the contents of this map typically result in an
IllegalStateException.
-
getJobDetail
JobDetail getJobDetail()
Get the
JobDetailassociated with theJob.
-
getJobInstance
Job getJobInstance()
Get the instance of the
Jobthat was created for this execution.Note: The Job instance is not available through remote scheduler interfaces.
-
getFireTime
java.util.Date getFireTime()
The actual time the trigger fired. For instance the scheduled time may have been 10:00:00 but the actual fire time may have been 10:00:03 if the scheduler was too busy.- Returns:
- Returns the fireTime.
- See Also:
getScheduledFireTime()
-
getScheduledFireTime
java.util.Date getScheduledFireTime()
The scheduled time the trigger fired for. For instance the scheduled time may have been 10:00:00 but the actual fire time may have been 10:00:03 if the scheduler was too busy.- Returns:
- Returns the scheduledFireTime.
- See Also:
getFireTime()
-
getPreviousFireTime
java.util.Date getPreviousFireTime()
-
getNextFireTime
java.util.Date getNextFireTime()
-
getFireInstanceId
java.lang.String getFireInstanceId()
Get the unique Id that identifies this particular firing instance of the trigger that triggered this job execution. It is unique to this JobExecutionContext instance as well.- Returns:
- the unique fire instance id
- See Also:
Scheduler.interrupt(String)
-
getResult
java.lang.Object getResult()
Returns the result (if any) that theJobset before its execution completed (the type of object set as the result is entirely up to the particular job).The result itself is meaningless to Quartz, but may be informative to
orJobListenersthat are watching the job's execution.TriggerListeners- Returns:
- Returns the result.
-
setResult
void setResult(java.lang.Object result)
Set the result (if any) of theJob's execution (the type of object set as the result is entirely up to the particular job).The result itself is meaningless to Quartz, but may be informative to
orJobListenersthat are watching the job's execution.TriggerListeners
-
getJobRunTime
long getJobRunTime()
The amount of time the job ran for (in milliseconds). The returned value will be -1 until the job has actually completed (or thrown an exception), and is therefore generally only useful toJobListeners andTriggerListeners.- Returns:
- Returns the jobRunTime.
-
put
void put(java.lang.Object key, java.lang.Object value)Put the specified value into the context's data map with the given key. Possibly useful for sharing data between listeners and jobs.NOTE: this data is volatile - it is lost after the job execution completes, and all TriggerListeners and JobListeners have been notified.
- Parameters:
key- the key for the associated valuevalue- the value to store
-
get
java.lang.Object get(java.lang.Object key)
Get the value with the given key from the context's data map.- Parameters:
key- the key for the desired value
-
-