Package eu.woolplatform.utils.schedule
Class AbstractScheduledTask
- java.lang.Object
-
- eu.woolplatform.utils.schedule.AbstractScheduledTask
-
- All Implemented Interfaces:
ScheduledTask
public abstract class AbstractScheduledTask extends Object implements ScheduledTask
Base scheduled task class with default implementations.
-
-
Constructor Summary
Constructors Constructor Description AbstractScheduledTask()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel(Object context)Cancels the task.StringgetId()Returns the task ID.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.voidsetId(String id)Sets the task ID.voidsetRunOnWorkerThread(boolean runOnWorkerThread)Sets whether the task should run on a worker thread or on the scheduling thread (the UI thread in Android).voidsetSchedule(TaskSchedule schedule)Sets the schedule at which the task should be run.voidsetTaskData(String taskData)TheTaskSchedulermay call this method when it needs to build a copy of an instance that was passed earlier.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface eu.woolplatform.utils.schedule.ScheduledTask
getName, run
-
-
-
-
Method Detail
-
getId
public String getId()
Description copied from interface:ScheduledTaskReturns the task ID. This is set by theTaskSchedulerwhen the task is scheduled.- Specified by:
getIdin interfaceScheduledTask- Returns:
- the task ID
-
setId
public void setId(String id)
Description copied from interface:ScheduledTaskSets the task ID. This is set by theTaskSchedulerwhen the task is scheduled.- Specified by:
setIdin interfaceScheduledTask- Parameters:
id- the task ID
-
getTaskData
public String getTaskData()
Description copied from interface:ScheduledTaskReturns 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.- Specified by:
getTaskDatain interfaceScheduledTask- Returns:
- the task data
-
setTaskData
public void setTaskData(String taskData) throws ParseException
Description copied from interface:ScheduledTaskTheTaskSchedulermay 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.- Specified by:
setTaskDatain interfaceScheduledTask- Parameters:
taskData- the task data- Throws:
ParseException- if the data string can't be parsed
-
getSchedule
public TaskSchedule getSchedule()
Description copied from interface:ScheduledTaskReturns the schedule at which the task should be run.- Specified by:
getSchedulein interfaceScheduledTask- Returns:
- the schedule at which the task should be run
-
setSchedule
public void setSchedule(TaskSchedule schedule)
Sets the schedule at which the task should be run. The default isTaskSchedule.Immediate.- Parameters:
schedule- the schedule at which the task should be run
-
isRunOnWorkerThread
public boolean isRunOnWorkerThread()
Description copied from interface:ScheduledTaskReturns 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.- Specified by:
isRunOnWorkerThreadin interfaceScheduledTask- Returns:
- true if the task should run on a worker thread, false if it should run on the UI thread
-
setRunOnWorkerThread
public void setRunOnWorkerThread(boolean runOnWorkerThread)
Sets whether the task should run on a worker thread or on the scheduling thread (the UI thread in Android). The default is false.- Parameters:
runOnWorkerThread- true if the task should run on a worker thread, false if it should run on the scheduling thread
-
cancel
public void cancel(Object context)
Description copied from interface:ScheduledTaskCancels 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.- Specified by:
cancelin interfaceScheduledTask- Parameters:
context- the context (only set in Android)
-
-