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
public class TaskScheduler extends DirectoryThread implements 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
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRecurringTask(Entry recurringTask)
Adds a recurring task to the scheduler, optionally scheduling the first iteration for processing.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
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
writeState()
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 Detail
-
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 Detail
-
addRecurringTask
public void addRecurringTask(Entry recurringTask) throws LdapException
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
public void removeRecurringTask(String recurringTaskID) throws LdapException
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
public void scheduleTask(Task task) throws LdapException
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
public void removePendingTask(String taskID) throws LdapException
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
public void removeCompletedTask(String taskID) throws LdapException
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
public TaskBackend getTaskBackend()
Retrieves the task backend with which this scheduler is associated.- Returns:
- The task backend with which this scheduler is associated.
-
getTaskRootEntry
public Entry 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
public Entry 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
public Entry 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
public Task getScheduledTask(Dn taskEntryDN)
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
public Entry getScheduledTaskEntry(Dn scheduledTaskEntryDN)
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
public boolean searchScheduledTasks(SearchOperation searchOperation) throws LdapException
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
public RecurringTask getRecurringTask(Dn recurringTaskEntryDN)
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
public Entry getRecurringTaskEntry(Dn recurringTaskEntryDN)
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
public boolean searchRecurringTasks(SearchOperation searchOperation) throws LdapException
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
public Task entryToScheduledTask(Entry entry, Operation operation) throws LdapException
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
public Dn 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
public Map<String,String> 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.
-
-