public class TaskServiceImpl extends Object implements TaskService
| Constructor and Description |
|---|
TaskServiceImpl(RxSession session,
Queries queries,
LeaseService leaseService,
List<TaskType> taskTypes) |
| Modifier and Type | Method and Description |
|---|---|
rx.Observable<org.hawkular.metrics.tasks.impl.TaskContainer> |
findTasks(org.hawkular.metrics.tasks.impl.Lease lease,
TaskType taskType) |
rx.Observable<org.hawkular.metrics.tasks.impl.TaskContainer> |
findTasks(String type,
org.joda.time.DateTime timeSlice,
int segment) |
rx.Observable<Task> |
scheduleTask(org.joda.time.DateTime time,
Task task)
Schedules the task for repeated execution starting in the next time slice after
time. |
void |
setTimeUnit(TimeUnit timeUnit)
The time unit determines a couple things.
|
void |
shutdown()
Shuts down the internal scheduler.
|
void |
start()
Starts the internal scheduler which takes care of running jobs to process the task queue.
|
public TaskServiceImpl(RxSession session, Queries queries, LeaseService leaseService, List<TaskType> taskTypes)
public void setTimeUnit(TimeUnit timeUnit)
The time unit determines a couple things. First, it determines the frequency for scheduling jobs. If
TimeUnit.MINUTES is used for instance, then jobs are scheduled every minute. In this context, a job
refers to finding and executing tasks in the queue for a particular time slice, which brings up the second
thing that timeUnit determines - time slice interval. Time slices are set along fixed intervals,
e.g., 13:00, 13:01, 13:02, etc.
Note: This should only be called prior to calling start().
public void start()
TaskServiceTaskService.scheduleTask(DateTime, Task).start in interface TaskServicepublic void shutdown()
TaskServiceshutdown in interface TaskServicepublic rx.Observable<org.hawkular.metrics.tasks.impl.TaskContainer> findTasks(String type, org.joda.time.DateTime timeSlice, int segment)
public rx.Observable<org.hawkular.metrics.tasks.impl.TaskContainer> findTasks(org.hawkular.metrics.tasks.impl.Lease lease,
TaskType taskType)
public rx.Observable<Task> scheduleTask(org.joda.time.DateTime time, Task task)
TaskService
Schedules the task for repeated execution starting in the next time slice after time. If the task
scheduler runs jobs for executing tasks every minute and if time is 13:01:22, then the earliest
that the task can first get scheduled to execute is at 13:02 and every minute there after. Execution times are
determined by Task.getInterval(). If the task has an interval of 30 minutes, then it would be scheduled
to run at 13:30, 14:00, 14:30, and so on.
The task is guaranteed to execute at its scheduled time or later, and only one instance of the task will be executed at a time for a given time slice. In other words, if there are 5 machines running TaskService, only one of those TaskService instances will execute the task for a particular time slice.
If task execution fails for whatever reason, it will be rescheduled for execution in the next time slice. If the task runs at 13:30 and fails with some unhandled exception, then TaskService will run the task twice at 14:00. It will first run the task for the 13:30 time slice and then for the 14:00 time slice.
scheduleTask in interface TaskServicetime - The starting time from which the initial execution is scheduled. The scheduled execution time depends
on Task.getInterval(). Tasks are scheduled to execute on fixed time boundaries. For example,
if the task has an interval of 15 minutes, then it will get scheduled to run at 14:00, 14:15, 14:30,
14:45, 15:00, and so on.task - The task to schedule for executionscheduled execution time setCopyright © 2014–2015 Red Hat, Inc.. All rights reserved.