org.openmrs.scheduler.timer
Class TimerSchedulerServiceImpl

java.lang.Object
  extended by org.openmrs.api.impl.BaseOpenmrsService
      extended by org.openmrs.scheduler.timer.TimerSchedulerServiceImpl
All Implemented Interfaces:
OpenmrsService, SchedulerService

public class TimerSchedulerServiceImpl
extends BaseOpenmrsService
implements SchedulerService

Simple scheduler service that uses JDK timer to trigger and execute scheduled tasks.


Constructor Summary
TimerSchedulerServiceImpl()
           
 
Method Summary
 void deleteTask(java.lang.Integer id)
          Delete the task with the given identifier.
 java.util.Collection<TaskDefinition> getRegisteredTasks()
          Get all registered tasks.
 java.util.Collection<TaskDefinition> getScheduledTasks()
          Get all scheduled tasks.
 SchedulerDAO getSchedulerDAO()
          Gets the scheduler data access object.
 java.lang.String getStatus(java.lang.Integer id)
          Checks the status of a scheduled task.
 java.util.SortedMap<java.lang.String,java.lang.String> getSystemVariables()
          Get system variables.
 TaskDefinition getTask(java.lang.Integer id)
          Get the task with the given identifier.
 TaskDefinition getTaskByName(java.lang.String name)
          Get the task with the given name.
 void onShutdown()
          Shutdown hook for the scheduler and all of its scheduled tasks.
 void onStartup()
          Start up hook for the scheduler and all of its scheduled tasks.
 void registerTask(TaskDefinition definition)
          Register a new task by adding it to our task map with an empty schedule map.
 void rescheduleAllTasks()
          Loop over all currently started tasks and cycle them.
 Task rescheduleTask(TaskDefinition taskDefinition)
          Stop and start a scheduled task.
 void restoreFromMemento(OpenmrsMemento memento)
          Restore the scheduler service to state defined by Memento
 void saveTask(TaskDefinition task)
          Save a task in the database.
 OpenmrsMemento saveToMemento()
          Saves and stops all active tasks
 Task scheduleTask(TaskDefinition taskDefinition)
          Schedule the given task according to the given schedule.
 void setSchedulerDAO(SchedulerDAO dao)
          Sets the scheduler data access object.
 void shutdownAllTasks()
          Shutdown all running tasks.
 void shutdownTask(TaskDefinition taskDefinition)
          Stops a running task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimerSchedulerServiceImpl

public TimerSchedulerServiceImpl()
Method Detail

getSchedulerDAO

public SchedulerDAO getSchedulerDAO()
Gets the scheduler data access object.


setSchedulerDAO

public void setSchedulerDAO(SchedulerDAO dao)
Sets the scheduler data access object.


onStartup

public void onStartup()
Start up hook for the scheduler and all of its scheduled tasks.

Specified by:
onStartup in interface OpenmrsService
Specified by:
onStartup in interface SchedulerService
Overrides:
onStartup in class BaseOpenmrsService
See Also:
OpenmrsService.onStartup()

onShutdown

public void onShutdown()
Shutdown hook for the scheduler and all of its scheduled tasks.

Specified by:
onShutdown in interface OpenmrsService
Specified by:
onShutdown in interface SchedulerService
Overrides:
onShutdown in class BaseOpenmrsService
See Also:
OpenmrsService.onShutdown()

shutdownAllTasks

public void shutdownAllTasks()
Shutdown all running tasks.


scheduleTask

public Task scheduleTask(TaskDefinition taskDefinition)
                  throws SchedulerException
Schedule the given task according to the given schedule.

Specified by:
scheduleTask in interface SchedulerService
Parameters:
taskDefinition - the task to be scheduled
Returns:
the started Task, or null if there was a problem instantiating or scheduling the task
Throws:
SchedulerException

shutdownTask

public void shutdownTask(TaskDefinition taskDefinition)
                  throws SchedulerException
Stops a running task.

Specified by:
shutdownTask in interface SchedulerService
Parameters:
taskDefinition - the task to be stopped
Throws:
SchedulerException
See Also:
SchedulerService.shutdownTask(TaskDefinition)

rescheduleAllTasks

public void rescheduleAllTasks()
                        throws SchedulerException
Loop over all currently started tasks and cycle them. This should be done after the classloader has been changed (e.g. during module start/stop)

Specified by:
rescheduleAllTasks in interface SchedulerService
Throws:
SchedulerException

rescheduleTask

public Task rescheduleTask(TaskDefinition taskDefinition)
                    throws SchedulerException
Description copied from interface: SchedulerService
Stop and start a scheduled task.

Specified by:
rescheduleTask in interface SchedulerService
Parameters:
taskDefinition - the TaskDefinition to reschedule
Throws:
SchedulerException
See Also:
SchedulerService.rescheduleTask(org.openmrs.scheduler.TaskDefinition)

registerTask

public void registerTask(TaskDefinition definition)
Register a new task by adding it to our task map with an empty schedule map.

Parameters:
definition - task to register

getScheduledTasks

public java.util.Collection<TaskDefinition> getScheduledTasks()
Get all scheduled tasks.

Specified by:
getScheduledTasks in interface SchedulerService
Returns:
all scheduled tasks

getRegisteredTasks

public java.util.Collection<TaskDefinition> getRegisteredTasks()
Get all registered tasks.

Specified by:
getRegisteredTasks in interface SchedulerService
Returns:
all registerd tasks

getTask

public TaskDefinition getTask(java.lang.Integer id)
Get the task with the given identifier.

Specified by:
getTask in interface SchedulerService
Parameters:
id - the identifier of the task

getTaskByName

public TaskDefinition getTaskByName(java.lang.String name)
Get the task with the given name.

Specified by:
getTaskByName in interface SchedulerService
Parameters:
name - name of the task

saveTask

public void saveTask(TaskDefinition task)
Save a task in the database.

Specified by:
saveTask in interface SchedulerService
Parameters:
task - the TaskDefinition to save

deleteTask

public void deleteTask(java.lang.Integer id)
Delete the task with the given identifier.

Specified by:
deleteTask in interface SchedulerService
Parameters:
id - the identifier of the task

getSystemVariables

public java.util.SortedMap<java.lang.String,java.lang.String> getSystemVariables()
Get system variables.

Specified by:
getSystemVariables in interface SchedulerService
Returns:
SortedMap

saveToMemento

public OpenmrsMemento saveToMemento()
Saves and stops all active tasks

Specified by:
saveToMemento in interface SchedulerService
Returns:
OpenmrsMemento

restoreFromMemento

public void restoreFromMemento(OpenmrsMemento memento)
Description copied from interface: SchedulerService
Restore the scheduler service to state defined by Memento

Specified by:
restoreFromMemento in interface SchedulerService

getStatus

public java.lang.String getStatus(java.lang.Integer id)
Description copied from interface: SchedulerService
Checks the status of a scheduled task.

Specified by:
getStatus in interface SchedulerService
Returns:
the String status of the task with the given identifier
See Also:
TODO internationalization of string status messages

OpenMRS-1.7.x

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