Class JobExecutionContextImpl
- java.lang.Object
-
- org.quartz.impl.JobExecutionContextImpl
-
- All Implemented Interfaces:
java.io.Serializable
,JobExecutionContext
public class JobExecutionContextImpl extends java.lang.Object implements java.io.Serializable, JobExecutionContext
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description JobExecutionContextImpl(Scheduler scheduler, TriggerFiredBundle firedBundle, Job job)
Create a JobExcecutionContext with the given context data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
get(java.lang.Object key)
Get the value with the given key from the context's data map.Calendar
getCalendar()
Get a handle to theCalendar
referenced by theTrigger
instance that fired theJob
.java.lang.String
getFireInstanceId()
Get the unique Id that identifies this particular firing instance of the trigger that triggered this job execution.java.util.Date
getFireTime()
The actual time the trigger fired.JobDetail
getJobDetail()
Get theJobDetail
associated with theJob
.Job
getJobInstance()
Get the instance of theJob
that was created for this execution.long
getJobRunTime()
The amount of time the job ran for (in milliseconds).JobDataMap
getMergedJobDataMap()
Get the convenienceJobDataMap
of this execution context.java.util.Date
getNextFireTime()
java.util.Date
getPreviousFireTime()
TriggerKey
getRecoveringTriggerKey()
Return theTriggerKey
of the originally scheduled and now recovering job.int
getRefireCount()
java.lang.Object
getResult()
Returns the result (if any) that theJob
set before its execution completed (the type of object set as the result is entirely up to the particular job).java.util.Date
getScheduledFireTime()
The scheduled time the trigger fired for.Scheduler
getScheduler()
Get a handle to theScheduler
instance that fired theJob
.Trigger
getTrigger()
Get a handle to theTrigger
instance that fired theJob
.void
incrementRefireCount()
boolean
isRecovering()
If theJob
is being re-executed because of a 'recovery' situation, this method will returntrue
.void
put(java.lang.Object key, java.lang.Object value)
Put the specified value into the context's data map with the given key.void
setJobRunTime(long jobRunTime)
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).java.lang.String
toString()
-
-
-
Constructor Detail
-
JobExecutionContextImpl
public JobExecutionContextImpl(Scheduler scheduler, TriggerFiredBundle firedBundle, Job job)
Create a JobExcecutionContext with the given context data.
-
-
Method Detail
-
getScheduler
public Scheduler getScheduler()
Get a handle to the
Scheduler
instance that fired theJob
.- Specified by:
getScheduler
in interfaceJobExecutionContext
-
getTrigger
public Trigger getTrigger()
Get a handle to the
Trigger
instance that fired theJob
.- Specified by:
getTrigger
in interfaceJobExecutionContext
-
getCalendar
public Calendar getCalendar()
Get a handle to the
Calendar
referenced by theTrigger
instance that fired theJob
.- Specified by:
getCalendar
in interfaceJobExecutionContext
-
isRecovering
public boolean isRecovering()
If the
Job
is being re-executed because of a 'recovery' situation, this method will returntrue
.- Specified by:
isRecovering
in interfaceJobExecutionContext
-
getRecoveringTriggerKey
public TriggerKey getRecoveringTriggerKey()
Description copied from interface:JobExecutionContext
Return theTriggerKey
of 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
JobExecutionContext.getScheduledFireTime()
method. The original firing time of the job can be accessed via theScheduler.FAILED_JOB_ORIGINAL_TRIGGER_FIRETIME_IN_MILLISECONDS
element of this job'sJobDataMap
.- Specified by:
getRecoveringTriggerKey
in interfaceJobExecutionContext
- Returns:
- the recovering trigger details
-
incrementRefireCount
public void incrementRefireCount()
-
getRefireCount
public int getRefireCount()
- Specified by:
getRefireCount
in interfaceJobExecutionContext
-
getMergedJobDataMap
public JobDataMap getMergedJobDataMap()
Get the convenience
JobDataMap
of this execution context.The
JobDataMap
found on this object serves as a convenience - it is a merge of theJobDataMap
found on theJobDetail
and 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
@PersistJobDataAfterExecution
annotation.Attempts to change the contents of this map typically result in an
IllegalStateException
.- Specified by:
getMergedJobDataMap
in interfaceJobExecutionContext
-
getJobDetail
public JobDetail getJobDetail()
Get the
JobDetail
associated with theJob
.- Specified by:
getJobDetail
in interfaceJobExecutionContext
-
getJobInstance
public Job getJobInstance()
Get the instance of the
Job
that was created for this execution.Note: The Job instance is not available through remote scheduler interfaces.
- Specified by:
getJobInstance
in interfaceJobExecutionContext
-
getFireTime
public 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.- Specified by:
getFireTime
in interfaceJobExecutionContext
- Returns:
- Returns the fireTime.
- See Also:
JobExecutionContext.getScheduledFireTime()
-
getScheduledFireTime
public 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.- Specified by:
getScheduledFireTime
in interfaceJobExecutionContext
- Returns:
- Returns the scheduledFireTime.
- See Also:
JobExecutionContext.getFireTime()
-
getPreviousFireTime
public java.util.Date getPreviousFireTime()
- Specified by:
getPreviousFireTime
in interfaceJobExecutionContext
-
getNextFireTime
public java.util.Date getNextFireTime()
- Specified by:
getNextFireTime
in interfaceJobExecutionContext
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getResult
public java.lang.Object getResult()
Returns the result (if any) that theJob
set 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
orJobListener
s
that are watching the job's execution.TriggerListener
s- Specified by:
getResult
in interfaceJobExecutionContext
- Returns:
- Returns the result.
-
setResult
public 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
orJobListener
s
that are watching the job's execution.TriggerListener
s- Specified by:
setResult
in interfaceJobExecutionContext
-
getJobRunTime
public 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 toJobListener
s andTriggerListener
s.- Specified by:
getJobRunTime
in interfaceJobExecutionContext
- Returns:
- Returns the jobRunTime.
-
setJobRunTime
public void setJobRunTime(long jobRunTime)
- Parameters:
jobRunTime
- The jobRunTime to set.
-
put
public 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.
- Specified by:
put
in interfaceJobExecutionContext
- Parameters:
key
- the key for the associated valuevalue
- the value to store
-
get
public java.lang.Object get(java.lang.Object key)
Get the value with the given key from the context's data map.- Specified by:
get
in interfaceJobExecutionContext
- Parameters:
key
- the key for the desired value
-
getFireInstanceId
public 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.- Specified by:
getFireInstanceId
in interfaceJobExecutionContext
- Returns:
- the unique fire instance id
- See Also:
Scheduler.interrupt(String)
-
-