org.quartz
Class JobExecutionContext

java.lang.Object
  extended by org.quartz.JobExecutionContext
All Implemented Interfaces:
java.io.Serializable

public class JobExecutionContext
extends java.lang.Object
implements java.io.Serializable

A context bundle containing handles to various environment information, that is given to a JobDetail instance as it is executed, and to a Trigger instance after the execution completes.

The JobDataMap found on this object (via the getMergedJobDataMap() method) serves as a convenience - it is a merge of the JobDataMap found on the JobDetail and the one found on the Trigger, 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 StatefulJob's own JobDataMap.

JobExecutionContext s are also returned from the Scheduler.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 the JobExecutionContexts, and their references to the Scheduler and Job instances have been lost (a clone of the JobDetail is still available - just not a handle to the job instance that is running).

Author:
James House
See Also:
getJobDetail(), getScheduler(), getMergedJobDataMap(), Job, Trigger, JobDataMap, Serialized Form

Constructor Summary
JobExecutionContext(Scheduler scheduler, TriggerFiredBundle firedBundle, Job job)
           Create a JobExcecutionContext with the given context data.
 
Method Summary
 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 the Calendar referenced by the Trigger instance that fired the Job.
 java.util.Date getFireTime()
          The actual time the trigger fired.
 JobDetail getJobDetail()
           Get the JobDetail associated with the Job.
 Job getJobInstance()
           Get the instance of the Job that was created for this execution.
 long getJobRunTime()
          The amount of time the job ran for (in milliseconds).
 JobDataMap getMergedJobDataMap()
           Get the convenience JobDataMap of this execution context.
 java.util.Date getNextFireTime()
           
 java.util.Date getPreviousFireTime()
           
 int getRefireCount()
           
 java.lang.Object getResult()
          Returns the result (if any) that the Job 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 the Scheduler instance that fired the Job.
 Trigger getTrigger()
           Get a handle to the Trigger instance that fired the Job.
 void incrementRefireCount()
           
 boolean isRecovering()
           If the Job is being re-executed because of a 'recovery' situation, this method will return true.
 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 the Job's execution (the type of object set as the result is entirely up to the particular job).
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JobExecutionContext

public JobExecutionContext(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 the Job.


getTrigger

public Trigger getTrigger()

Get a handle to the Trigger instance that fired the Job.


getCalendar

public Calendar getCalendar()

Get a handle to the Calendar referenced by the Trigger instance that fired the Job.


isRecovering

public boolean isRecovering()

If the Job is being re-executed because of a 'recovery' situation, this method will return true.


incrementRefireCount

public void incrementRefireCount()

getRefireCount

public int getRefireCount()

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 the JobDataMap found on the JobDetail and the one found on the Trigger, 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 StatefulJob's own JobDataMap.

Attempts to change the contents of this map typically result in an IllegalStateException.


getJobDetail

public JobDetail getJobDetail()

Get the JobDetail associated with the Job.


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.


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.

Returns:
Returns the fireTime.
See Also:
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.

Returns:
Returns the scheduledFireTime.
See Also:
getFireTime()

getPreviousFireTime

public java.util.Date getPreviousFireTime()

getNextFireTime

public java.util.Date getNextFireTime()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getResult

public java.lang.Object getResult()
Returns the result (if any) that the Job 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 JobListeners or TriggerListeners that are watching the job's execution.

Returns:
Returns the result.

setResult

public void setResult(java.lang.Object result)
Set the result (if any) of the Job'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 JobListeners or TriggerListeners that are watching the job's execution.


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 to JobListeners and TriggerListeners.

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.

Parameters:
key -
value -

get

public java.lang.Object get(java.lang.Object key)
Get the value with the given key from the context's data map.

Parameters:
key -


Copyright 2001-2019, Terracotta, Inc.