org.openmrs.scheduler
Class SchedulerUtil

java.lang.Object
  extended by org.openmrs.scheduler.SchedulerUtil

public class SchedulerUtil
extends java.lang.Object


Constructor Summary
SchedulerUtil()
           
 
Method Summary
static java.lang.String getExceptionAsString(java.lang.Throwable t)
           
static java.util.Date getNextExecution(TaskDefinition taskDefinition)
          Gets the next execution time based on the initial start time (possibly years ago, depending on when the task was configured in OpenMRS) and the repeat interval of execution.
static void sendSchedulerError(java.lang.Throwable throwable)
          Sends an email with system information and the given exception
static void shutdown()
          Shutdown the scheduler service that is statically associated with the Context class.
static void startup(java.util.Properties p)
          Start the scheduler given the following start up properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SchedulerUtil

public SchedulerUtil()
Method Detail

startup

public static void startup(java.util.Properties p)
Start the scheduler given the following start up properties.

Parameters:
p - properties used to start the service

shutdown

public static void shutdown()
Shutdown the scheduler service that is statically associated with the Context class.


sendSchedulerError

public static void sendSchedulerError(java.lang.Throwable throwable)
Sends an email with system information and the given exception

Parameters:
error -

getExceptionAsString

public static java.lang.String getExceptionAsString(java.lang.Throwable t)
Parameters:
e -
Returns:
String representation of the given exception

getNextExecution

public static java.util.Date getNextExecution(TaskDefinition taskDefinition)
Gets the next execution time based on the initial start time (possibly years ago, depending on when the task was configured in OpenMRS) and the repeat interval of execution. We need to calculate the "next execution time" because the scheduled time is most likely in the past and the JDK timer will run the task X number of times from the start time until now in order to catch up. The assumption is that this is not the desired behavior -- we just want to execute the task on its next execution time. For instance, say we had a scheduled task that ran every 24 hours at midnight. In the database, the task would likely have a past start date (i.e. 04/01/2006 12:00am). If we scheduled the task using the JDK Timer scheduleAtFixedRate(TimerTask task, Date startDate, int interval) method and passed in the start date above, the JDK Timer would execute this task once for every day between the start date and today, which would lead to hundreds of unnecessary (and likely expensive) executions.

Parameters:
taskDefinition - the task definition to be executed
Returns:
the next "future" execution time for the given task
See Also:
Timer
Expected behavior:
get the correct repeat interval

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change