Package eu.woolplatform.utils.schedule
Interface ScheduledTask
-
- All Known Implementing Classes:
AbstractScheduledTask
public interface ScheduledTaskThis class defines a scheduled task that can be run with theTaskScheduler.In some cases the
TaskSchedulerneeds to build a copy of an instance that was passed earlier. This is done using a data string (seegetTaskData()andsetTaskData()). See the discussion atTaskSchedulerfor the cases when this is done.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcancel(Object context)Cancels the task.StringgetId()Returns the task ID.StringgetName()Returns the name of this task.TaskSchedulegetSchedule()Returns the schedule at which the task should be run.StringgetTaskData()Returns the task data that is needed to build a copy of this task instance.booleanisRunOnWorkerThread()Returns whether the task should run on a worker thread or on the UI thread in Android.voidrun(Object context, String taskId, org.joda.time.DateTime now, ScheduleParams scheduleParams)Runs the task.voidsetId(String id)Sets the task ID.voidsetTaskData(String taskData)TheTaskSchedulermay call this method when it needs to build a copy of an instance that was passed earlier.
-
-
-
Method Detail
-
getId
String getId()
Returns the task ID. This is set by theTaskSchedulerwhen the task is scheduled.- Returns:
- the task ID
-
setId
void setId(String id)
Sets the task ID. This is set by theTaskSchedulerwhen the task is scheduled.- Parameters:
id- the task ID
-
getName
String getName()
Returns the name of this task. This is used for logging. It could be the simple name of the task class.- Returns:
- the name
-
getTaskData
String getTaskData()
Returns the task data that is needed to build a copy of this task instance. It could be a JSON string and it could also be null. See the discussion atTaskSchedulerfor the cases when this data string is used.- Returns:
- the task data
-
setTaskData
void setTaskData(String taskData) throws ParseException
TheTaskSchedulermay call this method when it needs to build a copy of an instance that was passed earlier. In that case it will construct an instance with the default constructor and then call this method. The specified data string was obtained fromgetTaskData(). It could be a JSON string and it could also be null. See the discussion atTaskSchedulerfor the cases when this is used.- Parameters:
taskData- the task data- Throws:
ParseException- if the data string can't be parsed
-
getSchedule
TaskSchedule getSchedule()
Returns the schedule at which the task should be run.- Returns:
- the schedule at which the task should be run
-
run
void run(Object context, String taskId, org.joda.time.DateTime now, ScheduleParams scheduleParams) throws TaskException
Runs the task. This method is called by theTaskSchedulerat the scheduled times according to the schedule returned bygetSchedule(). With repeating tasks this method is called sequentially. IfisRunOnWorkerThread()returns true, it will run on a worker thread. Otherwise it will run on the scheduling thread (the UI thread in Android).- Parameters:
context- the context (only set in Android)taskId- the task IDnow- the current timescheduleParams- the scheduled time parameters- Throws:
TaskException- if an error occurs that should be logged
-
isRunOnWorkerThread
boolean isRunOnWorkerThread()
Returns whether the task should run on a worker thread or on the UI thread in Android. In standard Java this is ignored and a task is always run on a worker thread.- Returns:
- true if the task should run on a worker thread, false if it should run on the UI thread
-
cancel
void cancel(Object context)
Cancels the task. This is called by theTaskSchedulerif the task was started and should be cancelled. In Android this method is called on the UI thread.- Parameters:
context- the context (only set in Android)
-
-