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 Details

    • Task

      public Task()
  • Method Details

    • 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.
    • getTaskName

      public final Dn getTaskName()
      Retrieves the name of the task entry.
      Returns:
      the name of the task entry.
    • 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 the initializeTask 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

      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 null if 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 to interruptTask(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 to interruptTask(TaskState, LocalizableMessage) then that method's interruptState is returned here. Otherwise this method returns TaskState.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 for System.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 for System.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(String category, 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 the ErrorLog.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

      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:
      compareTo in interface Comparable<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 the runTask 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

      public final void initializeTask() throws LdapException
      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

      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(Task.WorkCounters workCounters)
      Updates progress status.
      Parameters:
      workCounters - Counters on number of entries which 1) have yet to be processed and 2) 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 call setTaskInterruptState(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

      public String toString()
      Overrides:
      toString in class Object