public class TaskScheduler extends DirectoryThread implements AlertGenerator
Thread.State, Thread.UncaughtExceptionHandler
DIRECTORY_THREAD_GROUP
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
TaskScheduler(ServerContext serverContext,
TaskBackend taskBackend)
Creates a new task scheduler that will be used to ensure that tasks are invoked at the appropriate times.
|
Modifier and Type | Method and Description |
---|---|
void |
addCompletedTask(Task completedTask)
Adds the provided task to the set of completed tasks associated with the scheduler.
|
void |
addRecurringTask(RecurringTask recurringTask,
boolean scheduleIteration)
Adds a recurring task to the scheduler, optionally scheduling the first iteration for processing.
|
Task |
cancelTask(String taskID)
Attempts to cancel the task with the given task ID.
|
RecurringTask |
entryToRecurringTask(Entry entry)
Decodes the contents of the provided entry as a recurring task.
|
Task |
entryToScheduledTask(Entry entry,
Operation operation)
Decodes the contents of the provided entry as a scheduled task.
|
Map<String,String> |
getAlerts()
Retrieves information about the set of alerts that this generator may produce.
|
Dn |
getComponentEntryDN()
Retrieves the DN of the configuration entry with which this alert generator is associated.
|
long |
getEntryCount()
Retrieves the total number of entries in the task backend.
|
RecurringTask |
getRecurringTask(Dn recurringTaskEntryDN)
Retrieves the recurring task with the given recurring task ID.
|
long |
getRecurringTaskCount()
Retrieves the number of recurring tasks in the task backend.
|
Entry |
getRecurringTaskEntry(Dn recurringTaskEntryDN)
Retrieves the recurring task entry with the provided DN.
|
Entry |
getRecurringTaskParentEntry()
Retrieves the entry that is the immediate parent for all recurring task entries in the task backend.
|
Task |
getScheduledTask(Dn taskEntryDN)
Retrieves the scheduled task created from the specified entry.
|
long |
getScheduledTaskCount()
Retrieves the number of scheduled tasks in the task backend.
|
Entry |
getScheduledTaskEntry(Dn scheduledTaskEntryDN)
Retrieves the scheduled task entry with the provided DN.
|
Entry |
getScheduledTaskParentEntry()
Retrieves the entry that is the immediate parent for all scheduled task entries in the task backend.
|
TaskBackend |
getTaskBackend()
Retrieves the task backend with which this scheduler is associated.
|
Entry |
getTaskRootEntry()
Retrieves the root entry that is the common ancestor for all entries in the task backend.
|
void |
interruptRunningTasks(TaskState interruptState,
LocalizableMessage interruptReason,
boolean waitForStop)
Attempts to interrupt any tasks that are actively running.
|
Task |
removeCompletedTask(String taskID)
Removes the specified completed task.
|
Task |
removePendingTask(String taskID)
Removes the specified pending task.
|
RecurringTask |
removeRecurringTask(String recurringTaskID)
Removes the recurring task with the given ID.
|
void |
run()
Operates in a loop, launching tasks at the appropriate time and performing any necessary periodic cleanup.
|
protected void |
scheduleNextRecurringTaskIteration(Task completedTask,
GregorianCalendar calendar)
Check if a given task is a recurring task iteration and re-schedule it.
|
void |
scheduleTask(Task task,
boolean writeState)
Schedules the provided task for execution.
|
boolean |
searchRecurringTasks(SearchOperation searchOperation)
Compares the filter in the provided search operation against each of the recurring task entries, returning any
that match.
|
boolean |
searchScheduledTasks(SearchOperation searchOperation)
Compares the filter in the provided search operation against each of the task entries, returning any that match.
|
void |
stopScheduler()
Stops the scheduler so that it will not start any scheduled tasks.
|
boolean |
threadDone(TaskThread taskThread,
Task completedTask,
TaskState taskState)
Indicates that processing has completed on the provided task thread and that it is now available for processing
other tasks.
|
void |
writeState()
Writes state information about all tasks and recurring tasks to disk.
|
getAssociatedTask, getCreationStackTrace, getDebugProperties, getParentThread, initiateShutdown, isShutdownInitiated, isStarted, isStarting, setAssociatedTask, setStarted
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getClassName
public TaskScheduler(ServerContext serverContext, TaskBackend taskBackend) throws InitializationException
serverContext
- The server contexttaskBackend
- The task backend with which this scheduler is associated.InitializationException
- If a problem occurs while initializing the scheduler from the backing file.public void addRecurringTask(RecurringTask recurringTask, boolean scheduleIteration) throws LdapException
recurringTask
- The recurring task to add to the scheduler.scheduleIteration
- Indicates whether to schedule an iteration of the recurring task.LdapException
- If a problem occurs while trying to add the recurring task (e.g., there's already another recurring
task defined with the same ID).public RecurringTask removeRecurringTask(String recurringTaskID) throws LdapException
recurringTaskID
- The ID of the recurring task to remove.null
if there was no such recurring task.LdapException
- If there is currently a pending or running iteration of the associated recurring task.public void scheduleTask(Task task, boolean writeState) throws LdapException
task
- The task to be scheduled.writeState
- Indicates whether the current state information for the scheduler should be persisted to disk once the
task is scheduled.LdapException
- If a problem occurs while trying to schedule the task (e.g., there's already another task defined
with the same ID).public Task cancelTask(String taskID)
taskID
- The task ID of the task to cancel.null
if there is no such task.public Task removePendingTask(String taskID) throws LdapException
taskID
- The task ID of the pending task to remove.LdapException
- If the requested task is not in the pending queue.public Task removeCompletedTask(String taskID) throws LdapException
taskID
- The task ID of the completed task to remove.LdapException
- If the requested task could not be found.public boolean threadDone(TaskThread taskThread, Task completedTask, TaskState taskState)
taskThread
- The thread that has completed processing on its previously-assigned task.completedTask
- The task for which processing has been completed.taskState
- The task state for this completed task.true
if the thread should continue running and wait for the next task to process, or
false
if it should exit immediately.protected void scheduleNextRecurringTaskIteration(Task completedTask, GregorianCalendar calendar)
completedTask
- The task for which processing has been completed.calendar
- The calendar date and time to schedule from.public void addCompletedTask(Task completedTask)
completedTask
- The task for which processing has completed.public void stopScheduler()
public void interruptRunningTasks(TaskState interruptState, LocalizableMessage interruptReason, boolean waitForStop)
interruptState
- The state that should be assigned to the tasks if they are successfully interrupted.interruptReason
- A message indicating the reason that the tasks are to be interrupted.waitForStop
- Indicates whether this method should wait until all active tasks have stopped before returning.public void run()
public void writeState()
public long getEntryCount()
public long getScheduledTaskCount()
public long getRecurringTaskCount()
public TaskBackend getTaskBackend()
public Entry getTaskRootEntry()
public Entry getScheduledTaskParentEntry()
public Entry getRecurringTaskParentEntry()
public Task getScheduledTask(Dn taskEntryDN)
taskEntryDN
- The DN of the task configuration entry associated with the task to retrieve.null
if there is no such task.public Entry getScheduledTaskEntry(Dn scheduledTaskEntryDN)
scheduledTaskEntryDN
- The entry DN that indicates which scheduled task entry to retrieve.null
if no scheduled task has the provided
DN.public boolean searchScheduledTasks(SearchOperation searchOperation) throws LdapException
searchOperation
- The search operation to use when performing the search.true
if processing should continue on the search operation, or false
if it
should not for some reason (e.g., a size or time limit was reached).LdapException
- If a problem occurs while processing the search operation against the scheduled tasks.public RecurringTask getRecurringTask(Dn recurringTaskEntryDN)
recurringTaskEntryDN
- The recurring task ID for the recurring task to retrieve.null
if there is no such recurring task.public Entry getRecurringTaskEntry(Dn recurringTaskEntryDN)
recurringTaskEntryDN
- The entry DN that indicates which recurring task entry to retrieve.null
if no recurring task has the provided
DN.public boolean searchRecurringTasks(SearchOperation searchOperation) throws LdapException
searchOperation
- The search operation to use when performing the search.true
if processing should continue on the search operation, or false
if it
should not for some reason (e.g., a size or time limit was reached).LdapException
- If a problem occurs while processing the search operation against the recurring tasks.public Task entryToScheduledTask(Entry entry, Operation operation) throws LdapException
entry
- The entry to decode as a scheduled task.operation
- The operation used to create this task in the server, or null
if the operation is not
available.LdapException
- If the provided entry cannot be decoded as a scheduled task.public RecurringTask entryToRecurringTask(Entry entry) throws LdapException
entry
- The entry to decode as a recurring task.LdapException
- If the provided entry cannot be decoded as a recurring task.public Dn getComponentEntryDN()
AlertGenerator
getComponentEntryDN
in interface AlertGenerator
public Map<String,String> getAlerts()
AlertGenerator
getAlerts
in interface AlertGenerator
Copyright 2010-2022 ForgeRock AS.