Package org.opends.server.backends.task
Class Task
java.lang.Object
org.opends.server.backends.task.Task
- All Implemented Interfaces:
Comparable<Task>
- Direct Known Subclasses:
AddSchemaFileTask
,BackupPurgeTask
,BackupTask
,DisconnectClientTask
,EnterLockdownModeTask
,ExportTask
,ImportTask
,InitializeTargetTask
,InitializeTask
,LeaveLockdownModeTask
,PurgeConflictsHistoricalTask
,RebuildTask
,ResetChangeNumberTask
,RestoreTask
,SetGenerationIdTask
,ShutdownTask
This class defines a task that may be executed by the task backend within the Directory Server.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Data holder for work counters. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addLogMessage
(String category, Severity severity, LocalizableMessage message) Adds a log message to the set of messages logged by this task.final int
Compares this task with the provided task for the purposes of ordering in a sorted list.final TaskState
execute()
Begins execution for this task.Given an attribute type name returns and locale sensitive representation.final long
Retrieves the time that this task completed all of its associated processing (regardless of whether it was successful), if it has completed.Retrieves the set of task IDs for any tasks on which this task is dependent.Gets a message that identifies this type of task suitable for presentation to humans in monitoring tools.final FailedDependencyAction
Retrieves the action that should be taken if any of the dependencies for this task do not complete successfully.protected TaskState
Returns a state for this task after processing has completed.final List<LocalizableMessage>
Retrieves the set of messages that were logged by this task.final Operation
Retrieves the operation used to create this task in the server.final String
Retrieves the unique identifier assigned to the recurring task that is associated with this task, if there is one.final long
Retrieves the scheduled start time for this task, if there is one.protected ServerContext
Returns the server context.final String
Retrieves the unique identifier assigned to this task.final Dn
Retrieves the name of the task entry.final TaskState
Retrieves the current state for this task.final void
Performs any task-specific initialization that may be required before processing can start.protected void
initializeTask
(Entry taskEntry) Performs any task-specific initialization that may be required before processing can start.final void
initializeTaskInternal
(ServerContext serverContext, TaskScheduler taskScheduler, Entry taskEntry) Performs generic initialization for this task based on the information in the provided task entry.void
interruptTask
(TaskState interruptState, LocalizableMessage interruptReason) Performs any necessary processing to prematurely interrupt the execution of this task.boolean
Indicates whether this task is interruptible or not.boolean
Indicates whether this task is an iteration of some recurring task.protected void
replaceAttributes
(Attribute... replacements) Replaces attributes in the task entry.protected abstract TaskState
runTask()
Performs the actual core processing for this task.protected void
If appropriate, send an e-mail message with information about the completed task.protected void
setCompletionTime
(long completionTime) Sets the completion time for this task and updates the associated task entry as necessary.protected final void
setEntriesLeftAndDone
(Task.WorkCounters workCounters) Updates progress status.final void
setOperation
(Operation operation) Specifies the operation used to create this task in the server.protected void
setTaskInterruptState
(TaskState state) Sets a state for this task that is the result of a call tointerruptTask(TaskState, LocalizableMessage)
.toString()
-
Constructor Details
-
Task
public Task()
-
-
Method Details
-
getServerContext
Returns the server context.- Returns:
- the server context.
-
getDisplayName
Gets a message that identifies this type of task suitable for presentation to humans in monitoring tools.- Returns:
- name of task
-
getAttributeDisplayName
Given an attribute type name returns and locale sensitive representation.- Parameters:
name
- of an attribute type associated with the object class that represents this entry in the directory- Returns:
- LocalizableMessage display name
-
initializeTaskInternal
public final void initializeTaskInternal(ServerContext serverContext, TaskScheduler taskScheduler, Entry taskEntry) throws InitializationException Performs generic initialization for this task based on the information in the provided task entry.- Parameters:
serverContext
- The server context.taskScheduler
- The scheduler with which this task is associated.taskEntry
- The entry containing the task configuration.- Throws:
InitializationException
- If a problem occurs while performing the initialization.
-
getTaskName
Retrieves the name of the task entry.- Returns:
- the name of the task entry.
-
getOperation
Retrieves the operation used to create this task in the server. Note that this will only be available when the task is first added to the scheduler, and it should only be accessed from within theinitializeTask
method (and even that method should not depend on it always being available, since it will not be available if the server is restarted and the task needs to be reinitialized).- Returns:
- The operation used to create this task in the server, or
null
if it is not available.
-
setOperation
Specifies the operation used to create this task in the server.- Parameters:
operation
- The operation used to create this task in the server.
-
getTaskID
Retrieves the unique identifier assigned to this task.- Returns:
- The unique identifier assigned to this task.
-
getRecurringTaskID
Retrieves the unique identifier assigned to the recurring task that is associated with this task, if there is one.- Returns:
- The unique identifier assigned to the recurring task that is associated with this task, or
null
if it is not associated with any recurring task.
-
getTaskState
Retrieves the current state for this task.- Returns:
- The current state for this task.
-
isRecurring
public boolean isRecurring()Indicates whether this task is an iteration of some recurring task.- Returns:
- boolean where true indicates that this task is recurring, false otherwise.
-
setTaskInterruptState
Sets a state for this task that is the result of a call tointerruptTask(TaskState, LocalizableMessage)
. It may take this task some time to actually cancel to that actual state may differ until quiescence.- Parameters:
state
- for this task once it has canceled whatever it is doing
-
getFinalTaskState
Returns a state for this task after processing has completed. If the task was interrupted with a call tointerruptTask(TaskState, LocalizableMessage)
then that method's interruptState is returned here. Otherwise this method returnsTaskState.COMPLETED_SUCCESSFULLY
. It is assumed that if there were errors during task processing that task state will have been derived in some other way.- Returns:
- state for this task after processing has completed
-
replaceAttributes
Replaces attributes in the task entry.- Parameters:
replacements
- The attributes to replace in the task entry.
-
getScheduledStartTime
public final long getScheduledStartTime()Retrieves the scheduled start time for this task, if there is one. The value returned will be in the same format as the return value forSystem.currentTimeMillis()
. Any value representing a time in the past, or any negative value, should be taken to mean that the task should be considered eligible for immediate execution.- Returns:
- The scheduled start time for this task.
-
getCompletionTime
public final long getCompletionTime()Retrieves the time that this task completed all of its associated processing (regardless of whether it was successful), if it has completed. The value returned will be in the same format as the return value forSystem.currentTimeMillis()
.- Returns:
- The time that this task actually completed running, or -1 if it has not yet completed.
-
setCompletionTime
protected void setCompletionTime(long completionTime) Sets the completion time for this task and updates the associated task entry as necessary. It does not automatically persist the updated task information to disk.- Parameters:
completionTime
- The completion time to use for this task.
-
getDependencyIDs
Retrieves the set of task IDs for any tasks on which this task is dependent. This list must not be directly modified by the caller.- Returns:
- The set of task IDs for any tasks on which this task is dependent.
-
getFailedDependencyAction
Retrieves the action that should be taken if any of the dependencies for this task do not complete successfully.- Returns:
- The action that should be taken if any of the dependencies for this task do not complete successfully.
-
getLogMessages
Retrieves the set of messages that were logged by this task. This list must not be directly modified by the caller.- Returns:
- The set of messages that were logged by this task.
-
addLogMessage
Adds a log message to the set of messages logged by this task. This method should not be called directly by tasks, but rather will be called indirectly through theErrorLog.logError
methods. It does not automatically persist the updated task information to disk.- Parameters:
category
- the category of the message.severity
- the severity of message.message
- the log message.
-
compareTo
Compares this task with the provided task for the purposes of ordering in a sorted list. Any completed task will always be ordered before an uncompleted task. If both tasks are completed, then they will be ordered by completion time. If both tasks are uncompleted, then a running task will always be ordered before one that has not started. If both are running, then they will be ordered by actual start time. If neither have started, then they will be ordered by scheduled start time. If all else fails, they will be ordered lexicographically by task ID.- Specified by:
compareTo
in interfaceComparable<Task>
- Parameters:
task
- The task to compare with this task.- Returns:
- A negative value if the provided task should come before this task, a positive value if the provided task should come after this task, or zero if there is no difference with regard to their order.
-
execute
Begins execution for this task. This is a wrapper around therunTask
method that performs the appropriate set-up and tear-down. It should only be invoked by a task thread.- Returns:
- The final state to use for the task.
-
sendNotificationEMailMessage
protected void sendNotificationEMailMessage()If appropriate, send an e-mail message with information about the completed task. -
initializeTask
Performs any task-specific initialization that may be required before processing can start.- Throws:
LdapException
- If a problem occurs during initialization that should be returned to the client.
-
initializeTask
Performs any task-specific initialization that may be required before processing can start. This default implementation does not do anything, but subclasses may override it as necessary. This method will be called at the time the task is scheduled, and therefore any failure in this method will be returned to the client.- Parameters:
taskEntry
- the task entry- Throws:
LdapException
- If a problem occurs during initialization that should be returned to the client.
-
runTask
Performs the actual core processing for this task. This method should not return until all processing associated with this task has completed.- Returns:
- The final state to use for the task.
-
setEntriesLeftAndDone
Updates progress status.- Parameters:
workCounters
- Counters on number of entries which 1) have yet to be processed and 2) have been processed.
-
interruptTask
Performs any necessary processing to prematurely interrupt the execution of this task. By default no action is performed, but if it is feasible to gracefully interrupt a task, then subclasses should override this method to do so. Implementations of this method are expected to callsetTaskInterruptState(TaskState)
if the interruption is accepted by this task.- Parameters:
interruptState
- The state to use for the task if it is successfully interrupted.interruptReason
- A human-readable explanation for the cancellation.
-
isInterruptible
public boolean isInterruptible()Indicates whether this task is interruptible or not.- Returns:
- boolean where true indicates that this task can be interrupted.
-
toString
-