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
public abstract class Task extends Object implements Comparable<Task>
This class defines a task that may be executed by the task backend within the Directory Server.
-
-
Constructor Summary
Constructors Constructor Description Task()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddLogMessage(Severity severity, LocalizableMessage message)Adds a log message to the set of messages logged by this task.voidaddLogMessage(Severity severity, LocalizableMessage message, Throwable exception)Adds a log message to the set of messages logged by this task.intcompareTo(Task task)Compares this task with the provided task for the purposes of ordering in a sorted list.TaskStateexecute()Begins execution for this task.LocalizableMessagegetAttributeDisplayName(String name)Given an attribute type name returns and locale sensitive representation.longgetCompletionTime()Retrieves the time that this task completed all of its associated processing (regardless of whether it was successful), if it has completed.Iterable<String>getDependencyIDs()Retrieves the set of task IDs for any tasks on which this task is dependent.LocalizableMessagegetDisplayName()Gets a message that identifies this type of task suitable for presentation to humans in monitoring tools.FailedDependencyActiongetFailedDependencyAction()Retrieves the action that should be taken if any of the dependencies for this task do not complete successfully.protected TaskStategetFinalTaskState()Returns a state for this task after processing has completed.List<LocalizableMessage>getLogMessages()Retrieves the set of messages that were logged by this task.OperationgetOperation()Retrieves the operation used to create this task in the server.StringgetRecurringTaskID()Retrieves the unique identifier assigned to the recurring task that is associated with this task, if there is one.longgetScheduledStartTime()Retrieves the scheduled start time for this task, if there is one.protected ServerContextgetServerContext()Returns the server context.EntrygetTaskEntry()Retrieves the unmodifiable entry containing the definition for this task.StringgetTaskID()Retrieves the unique identifier assigned to this task.TaskStategetTaskState()Retrieves the current state for this task.voidinitializeTask()Performs any task-specific initialization that may be required before processing can start.protected voidinitializeTask(Entry taskEntry)Performs any task-specific initialization that may be required before processing can start.voidinitializeTaskInternal(ServerContext serverContext, TaskScheduler taskScheduler, Entry taskEntry)Performs generic initialization for this task based on the information in the provided task entry.voidinterruptTask(TaskState interruptState, LocalizableMessage interruptReason)Performs any necessary processing to prematurely interrupt the execution of this task.booleanisInterruptible()Indicates whether this task is interruptible or not.booleanisRecurring()Indicates whether this task is an iteration of some recurring task.protected voidreplaceAttributes(Attribute... replacements)Replaces attributes in the task entry.protected abstract TaskStaterunTask()Performs the actual core processing for this task.protected voidsendNotificationEMailMessage()If appropriate, send an e-mail message with information about the completed task.protected voidsetCompletionTime(long completionTime)Sets the completion time for this task and updates the associated task entry as necessary.protected voidsetEntriesLeftAndDone(long entriesLeft, long entriesDone)Updates progress status.voidsetOperation(Operation operation)Specifies the operation used to create this task in the server.protected voidsetTaskInterruptState(TaskState state)Sets a state for this task that is the result of a call tointerruptTask(TaskState, LocalizableMessage).StringtoString()
-
-
-
Method Detail
-
getServerContext
protected ServerContext getServerContext()
Returns the server context.- Returns:
- the server context.
-
getDisplayName
public LocalizableMessage getDisplayName()
Gets a message that identifies this type of task suitable for presentation to humans in monitoring tools.- Returns:
- name of task
-
getAttributeDisplayName
public LocalizableMessage getAttributeDisplayName(String name)
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.
-
getTaskEntry
public final Entry getTaskEntry()
Retrieves the unmodifiable entry containing the definition for this task.- Returns:
- The unmodifiable entry containing the definition for this task.
-
getOperation
public final Operation 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 theinitializeTaskmethod (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
nullif it is not available.
-
setOperation
public final void setOperation(Operation operation)
Specifies the operation used to create this task in the server.- Parameters:
operation- The operation used to create this task in the server.
-
getTaskID
public final String getTaskID()
Retrieves the unique identifier assigned to this task.- Returns:
- The unique identifier assigned to this task.
-
getRecurringTaskID
public final String 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
nullif it is not associated with any recurring task.
-
getTaskState
public final TaskState 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
protected void setTaskInterruptState(TaskState state)
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
protected TaskState 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
protected void replaceAttributes(Attribute... replacements)
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
public final Iterable<String> 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
public final FailedDependencyAction 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
public final List<LocalizableMessage> 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
public void addLogMessage(Severity severity, LocalizableMessage message)
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.logErrormethods. It does not automatically persist the updated task information to disk.- Parameters:
severity- the severity of message.message- the log message.
-
addLogMessage
public void addLogMessage(Severity severity, LocalizableMessage message, Throwable exception)
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.logErrormethods. It does not automatically persist the updated task information to disk.- Parameters:
severity- the severity of message.message- the log message.exception- the exception to log. May benull.
-
compareTo
public final int compareTo(Task task)
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:
compareToin 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
public final TaskState execute()
Begins execution for this task. This is a wrapper around therunTaskmethod 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
public final void initializeTask() throws LdapExceptionPerforms 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
protected void initializeTask(Entry taskEntry) throws LdapException
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
protected abstract TaskState 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
protected final void setEntriesLeftAndDone(long entriesLeft, long entriesDone)Updates progress status.- Parameters:
entriesLeft- The number of entries which have yet to be processedentriesDone- The number of entries which have been processed
-
interruptTask
public void interruptTask(TaskState interruptState, LocalizableMessage interruptReason)
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.
-
-