Package org.opends.server.backends.task
Class TaskScheduler
java.lang.Object
java.lang.Thread
org.opends.server.api.DirectoryThread
org.opends.server.backends.task.TaskScheduler
- All Implemented Interfaces:
Runnable
,AlertGenerator
This class defines a task scheduler for the Directory Server that will control the execution of scheduled tasks and
other administrative functions that need to occur on a regular basis.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorDescriptionTaskScheduler
(ServerContext serverContext, TaskBackend taskBackend) Creates a new task scheduler that will be used to ensure that tasks are invoked at the appropriate times. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRecurringTask
(Entry recurringTask) Adds a recurring task to the scheduler, optionally scheduling the first iteration for processing.entryToScheduledTask
(Entry entry, Operation operation) Decodes the contents of the provided entry as a scheduled task.Retrieves information about the set of alerts that this generator may produce.Retrieves the DN of the configuration entry with which this alert generator is associated.long
Retrieves the total number of entries in the task backend.getRecurringTask
(Dn recurringTaskEntryDN) Retrieves the recurring task with the given recurring task ID.long
Retrieves the number of recurring tasks in the task backend.getRecurringTaskEntry
(Dn recurringTaskEntryDN) Retrieves the recurring task entry with the provided DN.Retrieves the entry that is the immediate parent for all recurring task entries in the task backend.getScheduledTask
(Dn taskEntryDN) Retrieves the scheduled task created from the specified entry.long
Retrieves the number of scheduled tasks in the task backend.getScheduledTaskEntry
(Dn scheduledTaskEntryDN) Retrieves the scheduled task entry with the provided DN.Retrieves the entry that is the immediate parent for all scheduled task entries in the task backend.Retrieves the task backend with which this scheduler is associated.Retrieves the root entry that is the common ancestor for all entries in the task backend.void
removeCompletedTask
(String taskID) Removes the specified completed task.void
removePendingTask
(String taskID) Removes the specified pending task.void
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, Instant dateAndTimeToSchedule) Check if a given task is a recurring task iteration and re-schedule it.void
scheduleTask
(Task task) 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.boolean
threadDone
(org.opends.server.backends.task.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
Writes state information about all tasks and recurring tasks to disk.Methods inherited from class org.opends.server.api.DirectoryThread
checkForShutdownOrWait, checkForShutdownOrWait, getAssociatedTask, getServerContext, initiateShutdown, interrupt, isShutdownInitiated, isStarted, isStarting, setAssociatedTask, wakeup
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opends.server.api.AlertGenerator
getClassName
-
Constructor Details
-
TaskScheduler
public TaskScheduler(ServerContext serverContext, TaskBackend taskBackend) throws InitializationException Creates a new task scheduler that will be used to ensure that tasks are invoked at the appropriate times.- Parameters:
serverContext
- The server contexttaskBackend
- The task backend with which this scheduler is associated.- Throws:
InitializationException
- If a problem occurs while initializing the scheduler from the backing file.
-
-
Method Details
-
addRecurringTask
Adds a recurring task to the scheduler, optionally scheduling the first iteration for processing.- Parameters:
recurringTask
- The recurring task to add to the scheduler.- Throws:
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).
-
removeRecurringTask
Removes the recurring task with the given ID.- Parameters:
recurringTaskID
- The ID of the recurring task to remove.- Throws:
LdapException
- If there is currently a pending or running iteration of the associated recurring task.
-
scheduleTask
Schedules the provided task for execution. If the scheduler is active and the start time has arrived, then the task will begin execution immediately. Otherwise, it will be placed in the pending queue to be started at the appropriate time.- Parameters:
task
- The task to be scheduled.- Throws:
LdapException
- If a problem occurs while trying to schedule the task (e.g., there's already another task defined with the same ID).
-
removePendingTask
Removes the specified pending task. It will be completely removed rather than moving it to the set of completed tasks.- Parameters:
taskID
- The task ID of the pending task to remove.- Throws:
LdapException
- If the requested task is not in the pending queue.
-
removeCompletedTask
Removes the specified completed task.- Parameters:
taskID
- The task ID of the completed task to remove.- Throws:
LdapException
- If the requested task could not be found.
-
threadDone
public boolean threadDone(org.opends.server.backends.task.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. The thread may be immediately used for processing another task if appropriate.- Parameters:
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.- Returns:
true
if the thread should continue running and wait for the next task to process, orfalse
if it should exit immediately.
-
scheduleNextRecurringTaskIteration
protected void scheduleNextRecurringTaskIteration(Task completedTask, Instant dateAndTimeToSchedule) Check if a given task is a recurring task iteration and re-schedule it.- Parameters:
completedTask
- The task for which processing has been completed.dateAndTimeToSchedule
- The date and time to schedule from.
-
run
public void run()Operates in a loop, launching tasks at the appropriate time and performing any necessary periodic cleanup. -
writeState
public void writeState()Writes state information about all tasks and recurring tasks to disk. -
getEntryCount
public long getEntryCount()Retrieves the total number of entries in the task backend.- Returns:
- The total number of entries in the task backend.
-
getScheduledTaskCount
public long getScheduledTaskCount()Retrieves the number of scheduled tasks in the task backend.- Returns:
- The total number of entries in the task backend.
-
getRecurringTaskCount
public long getRecurringTaskCount()Retrieves the number of recurring tasks in the task backend.- Returns:
- The total number of entries in the task backend.
-
getTaskBackend
Retrieves the task backend with which this scheduler is associated.- Returns:
- The task backend with which this scheduler is associated.
-
getTaskRootEntry
Retrieves the root entry that is the common ancestor for all entries in the task backend.- Returns:
- The root entry that is the common ancestor for all entries in the task backend.
-
getScheduledTaskParentEntry
Retrieves the entry that is the immediate parent for all scheduled task entries in the task backend.- Returns:
- The entry that is the immediate parent for all scheduled task entries in the task backend.
-
getRecurringTaskParentEntry
Retrieves the entry that is the immediate parent for all recurring task entries in the task backend.- Returns:
- The entry that is the immediate parent for all recurring task entries in the task backend.
-
getScheduledTask
Retrieves the scheduled task created from the specified entry.- Parameters:
taskEntryDN
- The DN of the task configuration entry associated with the task to retrieve.- Returns:
- The requested scheduled task, or
null
if there is no such task.
-
getScheduledTaskEntry
Retrieves the scheduled task entry with the provided DN. The caller should hold a read lock on the target entry.- Parameters:
scheduledTaskEntryDN
- The entry DN that indicates which scheduled task entry to retrieve.- Returns:
- The scheduled task entry with the provided DN, or
null
if no scheduled task has the provided DN.
-
searchScheduledTasks
Compares the filter in the provided search operation against each of the task entries, returning any that match. Note that only the search filter will be used -- the base and scope will be ignored, so the caller must ensure that they are correct for scheduled tasks.- Parameters:
searchOperation
- The search operation to use when performing the search.- Returns:
true
if processing should continue on the search operation, orfalse
if it should not for some reason (e.g., a size or time limit was reached).- Throws:
LdapException
- If a problem occurs while processing the search operation against the scheduled tasks.
-
getRecurringTask
Retrieves the recurring task with the given recurring task ID.- Parameters:
recurringTaskEntryDN
- The recurring task ID for the recurring task to retrieve.- Returns:
- The requested recurring task, or
null
if there is no such recurring task.
-
getRecurringTaskEntry
Retrieves the recurring task entry with the provided DN. The caller should hold a read lock on the target entry.- Parameters:
recurringTaskEntryDN
- The entry DN that indicates which recurring task entry to retrieve.- Returns:
- The recurring task entry with the provided DN, or
null
if no recurring task has the provided DN.
-
searchRecurringTasks
Compares the filter in the provided search operation against each of the recurring task entries, returning any that match. Note that only the search filter will be used -- the base and scope will be ignored, so the caller must ensure that they are correct for recurring tasks.- Parameters:
searchOperation
- The search operation to use when performing the search.- Returns:
true
if processing should continue on the search operation, orfalse
if it should not for some reason (e.g., a size or time limit was reached).- Throws:
LdapException
- If a problem occurs while processing the search operation against the recurring tasks.
-
entryToScheduledTask
Decodes the contents of the provided entry as a scheduled task. The resulting task will not actually be scheduled for processing.- Parameters:
entry
- The entry to decode as a scheduled task.operation
- The operation used to create this task in the server, ornull
if the operation is not available.- Returns:
- The scheduled task decoded from the provided entry.
- Throws:
LdapException
- If the provided entry cannot be decoded as a scheduled task.
-
getComponentEntryDN
Description copied from interface:AlertGenerator
Retrieves the DN of the configuration entry with which this alert generator is associated.- Specified by:
getComponentEntryDN
in interfaceAlertGenerator
- Returns:
- The DN of the configuration entry with which this alert generator is associated.
-
getAlerts
Description copied from interface:AlertGenerator
Retrieves information about the set of alerts that this generator may produce. The map returned should be between the notification type for a particular notification and the human-readable description for that notification. This alert generator must not generate any alerts with types that are not contained in this list.- Specified by:
getAlerts
in interfaceAlertGenerator
- Returns:
- Information about the set of alerts that this generator may produce.
-