| | |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.TreeSet; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.locks.Lock; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | |
| | | try |
| | | { |
| | | RecurringTask recurringTask = recurringTasks.remove(recurringTaskID); |
| | | writeState(); |
| | | |
| | | for (Task t : tasks.values()) |
| | | { |
| | | if ((t.getRecurringTaskID() != null) && |
| | | (t.getRecurringTaskID().equals(recurringTaskID)) && |
| | | (!TaskState.isDone(t.getTaskState()))) |
| | | !TaskState.isDone(t.getTaskState())) |
| | | { |
| | | cancelTask(t.getTaskID()); |
| | | } |
| | | removeCompletedTask(t.getTaskID()); |
| | | } |
| | | |
| | | writeState(); |
| | | return recurringTask; |
| | | } |
| | | finally |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | // See if the task is part of a recurring task. If so, then schedule the |
| | | // next iteration. |
| | | String recurringTaskID = completedTask.getRecurringTaskID(); |
| | | if (recurringTaskID != null) |
| | | { |
| | | RecurringTask recurringTask = recurringTasks.get(recurringTaskID); |
| | | if (recurringTask == null) |
| | | { |
| | | // This shouldn't happen, but handle it anyway. |
| | | Message message = ERR_TASKSCHED_CANNOT_FIND_RECURRING_TASK.get( |
| | | String.valueOf(taskID), String.valueOf(recurringTaskID)); |
| | | logError(message); |
| | | |
| | | DirectoryServer.sendAlertNotification(this, |
| | | ALERT_TYPE_CANNOT_FIND_RECURRING_TASK, |
| | | message); |
| | | } |
| | | else |
| | | if (recurringTask != null) |
| | | { |
| | | Task newIteration = null; |
| | | try { |
| | |
| | | } |
| | | if (newIteration != null) |
| | | { |
| | | // FIXME -- What to do if new iteration is null? |
| | | |
| | | try |
| | | { |
| | | scheduleTask(newIteration, false); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | writeState(); |
| | | |
| | | |
| | | if (isRunning) |
| | | { |
| | | idleThreads.add(taskThread); |
| | |
| | | |
| | | |
| | | // Clean up any completed tasks that have been around long enough. |
| | | long retentionTimeMillis = |
| | | TimeUnit.SECONDS.toMillis(taskBackend.getRetentionTime()); |
| | | long oldestRetainedCompletionTime = |
| | | TimeThread.getTime() - taskBackend.getRetentionTime(); |
| | | TimeThread.getTime() - retentionTimeMillis; |
| | | iterator = completedTasks.iterator(); |
| | | while (iterator.hasNext()) |
| | | { |
| | |
| | | if (t.getCompletionTime() < oldestRetainedCompletionTime) |
| | | { |
| | | iterator.remove(); |
| | | tasks.remove(t.getTaskID()); |
| | | writeState = true; |
| | | } |
| | | |
| | | // FIXME -- If the completed tasks list is sorted, can we break out |
| | | // of the iterator as soon as we hit one that's not old |
| | | // enough to be expired? |
| | | } |
| | | |
| | | |
| | | // FIXME -- Should we check to see if any of the running jobs have |
| | | // logged any messages? |
| | | |
| | | |
| | | // If anything changed, then make sure that the on-disk state gets |
| | | // updated. |
| | | if (writeState) |
| | |
| | | { |
| | | Thread.sleep(sleepTime); |
| | | } |
| | | } catch (InterruptedException ie){} |
| | | |
| | | // Clean up any completed tasks that have been around long enough. |
| | | } catch (InterruptedException ie) {} |
| | | } |
| | | } |
| | | finally |
| | |
| | | { |
| | | LinkedHashMap<String,String> alerts = new LinkedHashMap<String,String>(); |
| | | |
| | | alerts.put(ALERT_TYPE_CANNOT_FIND_RECURRING_TASK, |
| | | ALERT_DESCRIPTION_CANNOT_FIND_RECURRING_TASK); |
| | | alerts.put(ALERT_TYPE_CANNOT_SCHEDULE_RECURRING_ITERATION, |
| | | ALERT_DESCRIPTION_CANNOT_SCHEDULE_RECURRING_ITERATION); |
| | | alerts.put(ALERT_TYPE_CANNOT_RENAME_CURRENT_TASK_FILE, |